diff --git a/classes/ComicPress.inc b/classes/ComicPress.inc index 3e75c88..f126abe 100644 --- a/classes/ComicPress.inc +++ b/classes/ComicPress.inc @@ -229,9 +229,9 @@ class ComicPress { $comic_posts[$which] = $this->{"get_${which}_comic"}(); } - $comic_posts['show_first'] = ($comic_posts['first']->ID != $comic_posts['last']->ID); - $comic_posts['show_previous'] = (!empty($comic_posts['previous']) && ($comic_posts['first']->ID != $comic_posts['previous']->ID)); - $comic_posts['show_next'] = (!empty($comic_posts['next']) && ($comic_posts['last']->ID != $comic_posts['next']->ID)); + $comic_posts['show_first'] = (trim($post->ID) != trim($comic_posts['first']->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']) && (trim($comic_posts['last']->ID) != trim($comic_posts['next']->ID))); $comic_posts['show_last'] = (trim($post->ID) != trim($comic_posts['last']->ID)); return $comic_posts; diff --git a/test/ComicPressTest.php b/test/ComicPressTest.php index d37f904..b136421 100644 --- a/test/ComicPressTest.php +++ b/test/ComicPressTest.php @@ -6,7 +6,10 @@ require_once(dirname(__FILE__) . '/../classes/ComicPress.inc'); class ComicPressTest extends PHPUnit_Framework_TestCase { function setUp() { + global $post; + _reset_wp(); + unset($post); $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)); } + + 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); + } + } } ?> \ No newline at end of file