add handle update tests

This commit is contained in:
John Bintz 2009-11-11 07:42:52 -05:00
parent c0767b0c6e
commit 95aeb3f45c
3 changed files with 71 additions and 37 deletions

View File

@ -293,6 +293,7 @@ class ComicPressAdmin {
}
function handle_update_comic_ordering() {
if (isset($_POST['post_ID'])) {
if (is_numeric($_POST['post_ID'])) {
if ($post = get_post($_POST['post_ID'])) {
$comic_post = new ComicPressComicPost(&$post);
@ -300,6 +301,7 @@ class ComicPressAdmin {
}
}
}
}
/**
* Update the zoom slider info.
@ -332,6 +334,7 @@ class ComicPressAdmin {
* Handle an update.
*/
function handle_update() {
if (isset($_REQUEST['cp'])) {
if (is_array($_REQUEST['cp'])) {
if (isset($_REQUEST['cp']['_nonce'])) {
if (wp_verify_nonce($_REQUEST['cp']['_nonce'], 'comicpress')) {
@ -345,7 +348,6 @@ class ComicPressAdmin {
}
} else {
//coming from us
// clean this up O_o
$this->handle_update_comicpress_options($_REQUEST['cp']);
$this->comicpress->save();
@ -360,6 +362,7 @@ class ComicPressAdmin {
}
}
}
}
// @codeCoverageIgnoreStart
var $messages = array(

View File

@ -200,14 +200,6 @@ class ComicPressStoryline {
return $result;
}
/**
* Get all comic categories.
* @deprecated
*/
function get_comic_categories() {
return array_keys($this->_structure);
}
/**
* Get a simple storyline.
*/

View File

@ -7,7 +7,7 @@ require_once('ComicPressAdmin.inc');
class ComicPressAdminTest extends PHPUnit_Framework_TestCase {
function setUp() {
_reset_wp();
$_POST = array();
$_POST = $_REQUEST = array();
$this->admin = new ComicPressAdmin();
}
@ -24,7 +24,7 @@ class ComicPressAdminTest extends PHPUnit_Framework_TestCase {
}
}
function providerTestHandleUpdate() {
function providerTestHandleUpdateComicPressOptions() {
return array(
array(
array('comic_dimensions' => '150x150'),
@ -57,9 +57,9 @@ class ComicPressAdminTest extends PHPUnit_Framework_TestCase {
}
/**
* @dataProvider providerTestHandleUpdate
* @dataProvider providerTestHandleUpdateComicPressOptions
*/
function testHandleUpdate($original, $change, $new) {
function testHandleUpdateComicPressOptions($original, $change, $new) {
$this->admin->comicpress = $this->getMock('ComicPress', array('save', 'init'));
$this->admin->comicpress->comicpress_options = array(
'comic_dimensions' => '760x',
@ -198,6 +198,45 @@ class ComicPressAdminTest extends PHPUnit_Framework_TestCase {
'zoom_level' => 100
), get_usermeta(1, 'comicpress-settings'));
}
function providerTestHandleUpdate() {
return array(
array(array()),
array(array('cp' => true), false),
array(array('cp' => array()), false),
array(array('cp' => array()), true, true, true),
array(array('cp' => array(), 'attachments' => array()), true, true, false),
array(array('cp' => array('action' => 'test')), true, true, false),
array(array('cp' => array('action' => 'comic_ordering')), true, true, false),
);
}
/**
* @dataProvider providerTestHandleUpdate
* @covers ComicPressAdmin::handle_update
*/
function testHandleUpdate($input, $add_nonce = false, $comicpress_load = false, $comicpress_save = false) {
$this->admin->comicpress = $this->getMock('ComicPress', array('save', 'init', 'load'));
if ($comicpress_load) {
$this->admin->comicpress->expects($this->once())->method('load');
}
if ($comicpress_save) {
$this->admin->comicpress->expects($this->once())->method('save');
$this->admin->comicpress->expects($this->once())->method('init');
}
if ($add_nonce) {
if (isset($input['cp'])) {
if (is_array($input['cp'])) {
$input['cp']['_nonce'] = wp_create_nonce('comicpress');
}
}
}
$_POST = $_REQUEST = $input;
$this->admin->handle_update();
}
}
?>