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,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();
}
}
}

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();
}
}
?>