2009-10-20 01:41:55 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once('MockPress/mockpress.php');
|
|
|
|
require_once('PHPUnit/Framework.php');
|
2009-11-07 17:18:53 +00:00
|
|
|
require_once('ComicPressDBInterface.inc');
|
2009-10-20 01:41:55 +00:00
|
|
|
|
|
|
|
class ComicPressDBInterfaceTest extends PHPUnit_Framework_TestCase {
|
2009-11-15 15:46:47 +00:00
|
|
|
function setUp() {
|
|
|
|
global $wp_query;
|
|
|
|
|
|
|
|
_reset_wp();
|
|
|
|
|
|
|
|
unset($wp_query);
|
|
|
|
}
|
|
|
|
|
2009-10-20 01:41:55 +00:00
|
|
|
function testSingleton() {
|
|
|
|
$a = ComicPressDBInterface::get_instance();
|
|
|
|
$this->assertTrue(!isset($a->test));
|
|
|
|
$a->test = "test";
|
|
|
|
$this->assertEquals("test", $a->test);
|
|
|
|
|
|
|
|
$b = ComicPressDBInterface::get_instance();
|
|
|
|
$this->assertEquals("test", $b->test);
|
|
|
|
}
|
2009-11-15 15:46:47 +00:00
|
|
|
|
|
|
|
function providerTestGetCategoriesToExclude() {
|
|
|
|
return array(
|
|
|
|
array(null, array()),
|
|
|
|
array(array(), array(1,2,3)),
|
|
|
|
array(array(1), array(2,3)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerTestGetCategoriesToExclude
|
|
|
|
*/
|
|
|
|
function testGetCategoriesToExclude($input, $expected_output) {
|
|
|
|
add_category(1, (object)array('slug' => 'one'));
|
|
|
|
add_category(2, (object)array('slug' => 'one'));
|
|
|
|
add_category(3, (object)array('slug' => 'one'));
|
|
|
|
|
|
|
|
$dbi = new ComicPressDBInterface();
|
|
|
|
|
|
|
|
$this->assertEquals($expected_output, $dbi->_get_categories_to_exclude($input));
|
|
|
|
}
|
|
|
|
|
|
|
|
function testPrepareWPQuery() {
|
|
|
|
global $wp_query;
|
|
|
|
|
|
|
|
$dbi = new ComicPressDBInterface();
|
|
|
|
|
|
|
|
$wp_query = (object)array(
|
|
|
|
'is_single' => false,
|
|
|
|
'in_the_loop' => false
|
|
|
|
);
|
|
|
|
|
|
|
|
$dbi->_prepare_wp_query();
|
|
|
|
|
|
|
|
$this->assertTrue($wp_query->is_single);
|
|
|
|
$this->assertTrue($wp_query->in_the_loop);
|
|
|
|
$this->assertTrue(false === $dbi->is_single);
|
|
|
|
$this->assertTrue(false === $dbi->in_the_loop);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testResetWPQuery() {
|
|
|
|
global $wp_query;
|
|
|
|
|
|
|
|
$dbi = new ComicPressDBInterface();
|
|
|
|
|
|
|
|
$wp_query = (object)array(
|
|
|
|
'is_single' => true,
|
|
|
|
'in_the_loop' => true
|
|
|
|
);
|
|
|
|
|
|
|
|
$dbi->is_single = false;
|
|
|
|
$dbi->in_the_loop = false;
|
|
|
|
|
|
|
|
$dbi->_Reset_wp_query();
|
|
|
|
|
|
|
|
$this->assertTrue(false === $wp_query->is_single);
|
|
|
|
$this->assertTrue(false === $wp_query->in_the_loop);
|
|
|
|
}
|
2009-10-20 01:41:55 +00:00
|
|
|
}
|
|
|
|
|
2009-11-15 15:37:43 +00:00
|
|
|
?>
|