testing for get nav comics

This commit is contained in:
John Bintz 2009-07-19 19:08:58 -04:00
parent 452d393de2
commit 19c94e9c71
2 changed files with 92 additions and 3 deletions

View File

@ -229,9 +229,9 @@ class ComicPress {
$comic_posts[$which] = $this->{"get_${which}_comic"}(); $comic_posts[$which] = $this->{"get_${which}_comic"}();
} }
$comic_posts['show_first'] = ($comic_posts['first']->ID != $comic_posts['last']->ID); $comic_posts['show_first'] = (trim($post->ID) != trim($comic_posts['first']->ID));
$comic_posts['show_previous'] = (!empty($comic_posts['previous']) && ($comic_posts['first']->ID != $comic_posts['previous']->ID)); $comic_posts['show_previous'] = (!empty($comic_posts['previous']) && (trim($comic_posts['first']->ID) != trim($comic_posts['previous']->ID)));
$comic_posts['show_next'] = (!empty($comic_posts['next']) && ($comic_posts['last']->ID != $comic_posts['next']->ID)); $comic_posts['show_next'] = (!empty($comic_posts['next']) && (trim($comic_posts['last']->ID) != trim($comic_posts['next']->ID)));
$comic_posts['show_last'] = (trim($post->ID) != trim($comic_posts['last']->ID)); $comic_posts['show_last'] = (trim($post->ID) != trim($comic_posts['last']->ID));
return $comic_posts; return $comic_posts;

View File

@ -6,7 +6,10 @@ require_once(dirname(__FILE__) . '/../classes/ComicPress.inc');
class ComicPressTest extends PHPUnit_Framework_TestCase { class ComicPressTest extends PHPUnit_Framework_TestCase {
function setUp() { function setUp() {
global $post;
_reset_wp(); _reset_wp();
unset($post);
$this->cp = new ComicPress(); $this->cp = new ComicPress();
} }
@ -82,6 +85,92 @@ class ComicPressTest extends PHPUnit_Framework_TestCase {
$this->assertEquals($is_in_category, $this->cp->in_comic_category(1)); $this->assertEquals($is_in_category, $this->cp->in_comic_category(1));
} }
function providerTestGetNavComics() {
return array(
array(
array(
'first' => 1,
'previous' => 2,
'next' => 4,
'last' => 5
),
3,
array(
'first' => true,
'previous' => true,
'next' => true,
'last' => true
)
),
array(
array(
'first' => 1,
'previous' => false,
'next' => false,
'last' => 1
),
1,
array(
'first' => false,
'previous' => false,
'next' => false,
'last' => false
)
),
array(
array(
'first' => 1,
'previous' => false,
'next' => 3,
'last' => 3
),
1,
array(
'first' => false,
'previous' => false,
'next' => false,
'last' => true
)
),
array(
array(
'first' => 1,
'previous' => 1,
'next' => false,
'last' => 3
),
3,
array(
'first' => true,
'previous' => false,
'next' => false,
'last' => false
)
)
);
}
/**
* @dataProvider providerTestGetNavComics
*/
function testGetNavComics($nav_comics, $given_post, $expected_shows) {
global $post;
$cp = $this->getMock('ComicPress', array('get_first_comic', 'get_last_comic', 'get_previous_comic', 'get_next_comic'));
foreach ($nav_comics as $key => $result) {
$return = (is_numeric($result)) ? (object)array('ID' => $result) : false;
$cp->expects($this->once())->method("get_${key}_comic")->will($this->returnValue($return));
}
$post = (is_numeric($given_post)) ? (object)array('ID' => $given_post) : false;
$comic_posts = $cp->get_nav_comics();
foreach ($expected_shows as $show => $expected) {
$this->assertEquals($expected, $comic_posts["show_${show}"], $show);
}
}
} }
?> ?>