start refactoring tests

This commit is contained in:
John Bintz 2009-07-02 07:25:49 -04:00
parent 625318abcc
commit a6b4fa30d5
2 changed files with 34 additions and 41 deletions

View File

@ -4,7 +4,7 @@
require_once('classes/ComicPressManager.php'); require_once('classes/ComicPressManager.php');
require_once('classes/ComicPressManagerAdmin.php'); require_once('classes/ComicPressManagerAdmin.php');
require_once('FirePHPCore/fb.php'); //require_once('FirePHPCore/fb.php');
include('cp_configuration_options.php'); include('cp_configuration_options.php');

View File

@ -58,52 +58,45 @@ class ComicPressManagerAdminTest extends PHPUnit_Framework_TestCase {
$this->assertEquals("", ob_get_clean()); $this->assertEquals("", ob_get_clean());
} }
function testVerifyPostBeforeHook() { function providerTestVerifyPostBeforeHook() {
return array(
array(true, null, null, null),
array(false, false, null, null),
array(false, true, false, null),
array(false, true, true, false),
array(false, true, true, true),
);
}
/**
* @dataProvider providerTestVerifyPostBeforeHook
*/
function testVerifyPostBeforeHook($is_managing, $edit_post_integration, $good_post, $is_entry_post) {
global $comicpress_manager; global $comicpress_manager;
// managing posts?
$comicpress_manager = $this->getMock("ComicPressManager", array('get_cpm_option')); $comicpress_manager = $this->getMock("ComicPressManager", array('get_cpm_option'));
$comicpress_manager->is_cpm_managing_posts = true; $comicpress_manager->is_cpm_managing_posts = $is_managing;
$comicpress_manager->expects($this->never())->method('get_cpm_option');
$this->assertFalse($this->adm->_verify_post_before_hook(1));
// not managing posts? user called, but not managing
$comicpress_manager = $this->getMock("ComicPressManager", array('get_cpm_option'));
$comicpress_manager->is_cpm_managing_posts = false;
$comicpress_manager->expects($this->once())
->method('get_cpm_option')
->will($this->returnValue("0"));
$this->assertFalse($this->adm->_verify_post_before_hook(1));
// user called, managing, but bad post $expected_result = false;
$comicpress_manager = $this->getMock("ComicPressManager", array('get_cpm_option'));
$comicpress_manager->is_cpm_managing_posts = false;
$comicpress_manager->expects($this->once())
->method('get_cpm_option')
->will($this->returnValue("1"));
$this->assertFalse($this->adm->_verify_post_before_hook(1));
// user called, managing, good post but not an Entry if ($is_managing) {
$comicpress_manager = $this->getMock("ComicPressManager", array('get_cpm_option')); $comicpress_manager->expects($this->never())->method('get_cpm_option');
$comicpress_manager->is_cpm_managing_posts = false; } else {
$comicpress_manager->expects($this->once()) $comicpress_manager->expects($this->once())
->method('get_cpm_option') ->method('get_cpm_option')
->will($this->returnValue("1")); ->will($this->returnValue($edit_post_integration ? "1" : "0"));
$id = wp_insert_post(array( if ($good_post) {
'post_type' => 'page' $id = wp_insert_post(array(
)); 'post_type' => $is_entry_post ? "entry" : "page"
$this->assertFalse($this->adm->_verify_post_before_hook($id)); ));
if ($is_entry_post) {
$expected_result = (object)array('post_type' => 'entry', 'ID' => $id);
}
}
}
// is a valid entry $this->assertEquals($expected_result, $this->adm->_verify_post_before_hook($id));
$comicpress_manager = $this->getMock("ComicPressManager", array('get_cpm_option'));
$comicpress_manager->is_cpm_managing_posts = false;
$comicpress_manager->expects($this->once())
->method('get_cpm_option')
->will($this->returnValue("1"));
$id = wp_insert_post(array(
'post_type' => 'entry'
));
$this->assertEquals((object)array('post_type' => 'entry', 'ID' => $id), $this->adm->_verify_post_before_hook($id));
} }
function testIsPostInComicCategory() { function testIsPostInComicCategory() {