diff --git a/classes/ComicPressAdmin.inc b/classes/ComicPressAdmin.inc index 5820ef7..e73b6f7 100644 --- a/classes/ComicPressAdmin.inc +++ b/classes/ComicPressAdmin.inc @@ -293,10 +293,12 @@ class ComicPressAdmin { } function handle_update_comic_ordering() { - if (is_numeric($_POST['post_ID'])) { - if ($post = get_post($_POST['post_ID'])) { - $comic_post = new ComicPressComicPost(&$post); - $comic_post->change_comic_image_ordering($this->_json_decode(stripslashes($_POST['cp']['comic_order']))); + if (isset($_POST['post_ID'])) { + if (is_numeric($_POST['post_ID'])) { + if ($post = get_post($_POST['post_ID'])) { + $comic_post = new ComicPressComicPost(&$post); + $comic_post->change_comic_image_ordering($this->_json_decode(stripslashes($_POST['cp']['comic_order']))); + } } } } @@ -332,30 +334,31 @@ class ComicPressAdmin { * Handle an update. */ function handle_update() { - if (is_array($_REQUEST['cp'])) { - if (isset($_REQUEST['cp']['_nonce'])) { - if (wp_verify_nonce($_REQUEST['cp']['_nonce'], 'comicpress')) { - if (isset($_POST['attachments'])) { - //coming from media editor - $this->handle_update_attachments(); - } else if (isset($_REQUEST['cp']['action'])) { - $method = 'handle_update_' . strtolower(str_replace('-', '_', $_REQUEST['cp']['action'])); - if (method_exists($this, $method)) { - $this->{$method}($_REQUEST['cp']); + if (isset($_REQUEST['cp'])) { + if (is_array($_REQUEST['cp'])) { + if (isset($_REQUEST['cp']['_nonce'])) { + if (wp_verify_nonce($_REQUEST['cp']['_nonce'], 'comicpress')) { + if (isset($_POST['attachments'])) { + //coming from media editor + $this->handle_update_attachments(); + } else if (isset($_REQUEST['cp']['action'])) { + $method = 'handle_update_' . strtolower(str_replace('-', '_', $_REQUEST['cp']['action'])); + if (method_exists($this, $method)) { + $this->{$method}($_REQUEST['cp']); + } + } else { + //coming from us + $this->handle_update_comicpress_options($_REQUEST['cp']); + + $this->comicpress->save(); + + $this->info(__("ComicPress configuration updated.", 'comicpress')); + + $this->comicpress->init(); } - } else { - //coming from us - // clean this up O_o - $this->handle_update_comicpress_options($_REQUEST['cp']); - $this->comicpress->save(); - - $this->info(__("ComicPress configuration updated.", 'comicpress')); - - $this->comicpress->init(); + $this->comicpress->load(); } - - $this->comicpress->load(); } } } diff --git a/classes/ComicPressStoryline.inc b/classes/ComicPressStoryline.inc index d68f5e8..bda1eee 100644 --- a/classes/ComicPressStoryline.inc +++ b/classes/ComicPressStoryline.inc @@ -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. */ diff --git a/test/ComicPressAdminTest.php b/test/ComicPressAdminTest.php index 863f15d..cd9edd9 100644 --- a/test/ComicPressAdminTest.php +++ b/test/ComicPressAdminTest.php @@ -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(); + } } ?>