tests for save post

This commit is contained in:
John Bintz 2010-01-31 18:19:35 -05:00
parent e3e5284d9c
commit 739753ee8e
2 changed files with 101 additions and 5 deletions

View File

@ -451,10 +451,15 @@ class ComicPressAdmin {
} }
} }
function _new_comicpresscomicpost($post) {
return new ComicPressComicPost($post);
}
// @codeCoverageIgnoreEnd
function save_post($post_id) { function save_post($post_id) {
if (ComicPressAdmin::verify_nonces() === 'handle_update_edit_form_advanced') { if ($this->verify_nonces() === 'handle_update_edit_form_advanced') {
if ($post = get_post($psot_id)) { if ($post = get_post($post_id)) {
$comic_post = new ComicPressComicPost($post); $comic_post = $this->_new_comicpresscomicpost($post);
$data = $this->_json_decode(stripslashes($_POST['cp']['comic_order'])); $data = $this->_json_decode(stripslashes($_POST['cp']['comic_order']));
if (!empty($data)) { if (!empty($data)) {
if (is_array($data)) { if (is_array($data)) {
@ -465,6 +470,7 @@ class ComicPressAdmin {
} }
} }
// @codeCoverageIgnoreStart
function handle_update_get_new_image_type_editor($info) { function handle_update_get_new_image_type_editor($info) {
$type = substr(md5(rand()), 0, 6); $type = substr(md5(rand()), 0, 6);
$info = array( $info = array(

View File

@ -391,6 +391,96 @@ class ComicPressAdminTest extends PHPUnit_Framework_TestCase {
$this->assertTrue(_xpath_test($xml, $xpath, $value), $xpath); $this->assertTrue(_xpath_test($xml, $xpath, $value), $xpath);
} }
} }
function providerTestSavePost() {
return array(
array(
array(
'verify_nonces' => false,
'post_id' => 1
),
false
),
array(
array(
'verify_nonces' => 'handle_update_edit_form_advanced',
'post_id' => 2
),
false
),
array(
array(
'verify_nonces' => 'handle_update_edit_form_advanced',
'post_id' => 1,
'comic_order' => 'order',
'json_decode_return' => ''
),
false
),
array(
array(
'verify_nonces' => 'handle_update_edit_form_advanced',
'post_id' => 1,
'comic_order' => 'order',
'json_decode_return' => array()
),
false
),
array(
array(
'verify_nonces' => 'handle_update_edit_form_advanced',
'post_id' => 1,
'comic_order' => 'order',
'json_decode_return' => array('test')
),
true
),
);
} }
?> /**
* @dataProvider providerTestSavePost
*/
function testSavePost($info, $expects_update_media_data) {
extract($info);
$post = (object)array(
'ID' => 1
);
wp_insert_post($post);
$admin = $this->getMock('ComicPressAdmin', array(
'verify_nonces',
'_json_decode',
'_new_comicpresscomicpost'
));
$admin->expects($this->once())->method('verify_nonces')->will($this->returnValue($verify_nonces));
if (isset($info['comic_order'])) {
$comic_post = $this->getMock('ComicPressComicPost', array('update_post_media_data'));
$expectation = $comic_post->expects($this->{$expects_update_media_data ? 'once' : 'never'}())
->method('update_post_media_data');
if ($expects_update_media_data) {
$expectation->with($json_decode_return);
}
$admin->expects($this->once())
->method('_new_comicpresscomicpost')
->with($post)
->will($this->returnValue($comic_post));
$admin->expects($this->once())
->method('_json_decode')
->with($comic_order)
->will($this->returnValue($json_decode_return));
$_POST = array('cp' => array('comic_order' => $comic_order));
}
$admin->save_post($post_id);
}
}