From 1db0f884f388d01ffefd68a63da335e64143b9bd Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 20 Oct 2009 07:22:34 -0400 Subject: [PATCH] start integration testing on nav building --- classes/ComicPressDBInterface.inc | 14 +++++--------- classes/ComicPressNavigation.inc | 17 ++++++++++++++++- test/ComicPressDBInterfaceTest.php | 11 +++-------- test/ComicPressNavigationTest.php | 19 +++++++++++++++++-- 4 files changed, 41 insertions(+), 20 deletions(-) diff --git a/classes/ComicPressDBInterface.inc b/classes/ComicPressDBInterface.inc index 1e52c64..0e42de9 100644 --- a/classes/ComicPressDBInterface.inc +++ b/classes/ComicPressDBInterface.inc @@ -18,12 +18,7 @@ class ComicPressDBInterface { * Set the comic categories for the current run of ComicPress. */ function set_comic_categories($categories) { - $this->_non_comic_categories = array(); - $this->_all_categories = array(); - foreach ($this->_get_categories() as $category_object) { - $this->_all_categories[] = $category_object->term_id; - } - + $this->_all_categories = get_all_category_ids(); $this->_non_comic_categories = array_values(array_diff($this->_all_categories, $categories)); } @@ -60,10 +55,11 @@ class ComicPressDBInterface { /** * Get the comic post adjacent to the current comic. + * Wrapper around get_adjacent_post(). Don't unit test this method. */ function get_adjacent_comic($category, $next = false, $override_post = null) { global $wp_query, $post; - $temp = $wp_query->is_single; + $temp_single = $wp_query->is_single; $wp_query->is_single = true; if (!is_null($override_post)) { @@ -71,9 +67,9 @@ class ComicPressDBInterface { $post = $override_post; } - $result = get_adjacent_post(false, implode(" and ", $categories_to_exclude), !$next); + $result = get_adjacent_post(false, implode(" and ", $this->_get_categories_to_exclude($category)), !$next); - $wp_query->is_single = $temp; + $wp_query->is_single = $temp_single; if (!is_null($override_post)) { $post = $temp_post; diff --git a/classes/ComicPressNavigation.inc b/classes/ComicPressNavigation.inc index 9f14b39..600a343 100644 --- a/classes/ComicPressNavigation.inc +++ b/classes/ComicPressNavigation.inc @@ -1,7 +1,22 @@ _storyline = $storyline; + $this->_dbi = ComicPressDBInterface::get_instance(); + } + + function get_post_nav($post) { + $nav = array(); + + // post + foreach (array('previous', 'next') as $field) { + $nav[$field] = $this->_dbi->{"get_${field}_comic"}(null, $post); + } + } } ?> \ No newline at end of file diff --git a/test/ComicPressDBInterfaceTest.php b/test/ComicPressDBInterfaceTest.php index d63f137..e6dd5b2 100644 --- a/test/ComicPressDBInterfaceTest.php +++ b/test/ComicPressDBInterfaceTest.php @@ -16,14 +16,9 @@ class ComicPressDBInterfaceTest extends PHPUnit_Framework_TestCase { } function testSetComicCategories() { - $dbi = $this->getMock('ComicPressDBInterface', array('_get_categories')); - - $dbi->expects($this->once())->method('_get_categories')->will($this->returnValue(array( - (object)array('term_id' => 1), - (object)array('term_id' => 2), - (object)array('term_id' => 3), - (object)array('term_id' => 4) - ))); + $dbi = ComicPressDBInterface::get_instance(); + + for ($i = 1; $i <= 4; ++$i) { add_category($i, (object)array()); } $dbi->set_comic_categories(array(2,3)); diff --git a/test/ComicPressNavigationTest.php b/test/ComicPressNavigationTest.php index 50e6996..4b217ca 100644 --- a/test/ComicPressNavigationTest.php +++ b/test/ComicPressNavigationTest.php @@ -4,14 +4,29 @@ require_once('MockPress/mockpress.php'); require_once('PHPUnit/Framework.php'); require_once(dirname(__FILE__) . '/../classes/ComicPressNavigation.inc'); +/** + * Integration Testing. Just make sure things are called correctly. + */ class ComicPressNavigationTest extends PHPUnit_Framework_TestCase { function setUp() { _reset_wp(); $this->nav = new ComicPressNavigation(); } - function testSomething() { - $this->markTestIncomplete(); + function testGetPostNav() { + $dbi = $this->getMock('ComicPressDBInterface', array('get_previous_comic', 'get_next_comic')); + + wp_insert_post(array('ID' => 1)); + $post = get_post(1); + + wp_set_post_categories(1, array(1)); + + $dbi->expects($this->once())->method('get_previous_comic')->with(null, $post); + $dbi->expects($this->once())->method('get_next_comic')->with(null, $post); + + $this->nav->_dbi = $dbi; + + $this->nav->get_post_nav($post); } }