From 364c1479a2651367d9e64d72c39a0477524d8a15 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sat, 21 Nov 2009 09:56:31 -0500 Subject: [PATCH] fix the fact that you con't pass restrictions to navigation --- classes/ComicPressNavigation.inc | 10 ++++++---- classes/ComicPressStoryline.inc | 5 ++++- test/ComicPressNavigationTest.php | 26 ++++++++++++++------------ test/ComicPressStorylineTest.php | 2 +- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/classes/ComicPressNavigation.inc b/classes/ComicPressNavigation.inc index bcc4a46..938583e 100644 --- a/classes/ComicPressNavigation.inc +++ b/classes/ComicPressNavigation.inc @@ -11,7 +11,7 @@ class ComicPressNavigation { } // @codeCoverageIgnoreEnd - function get_post_nav($post) { + function get_post_nav($post, $restrictions = null) { $nav = array(); if (is_object($post)) { if (isset($post->ID)) { @@ -24,14 +24,16 @@ class ComicPressNavigation { return $nav; } + $categories = $this->_storyline->build_from_restrictions($restrictions); + // global previous/next foreach (array('previous', 'next') as $field) { - $nav[$field] = $this->_dbi->{"get_${field}_comic"}(null, $post); + $nav[$field] = $this->_dbi->{"get_${field}_comic"}($categories, $post); } // global first/last foreach (array('first', 'last') as $field) { - $nav[$field] = $this->_dbi->{"get_${field}_comic"}(null); + $nav[$field] = $this->_dbi->{"get_${field}_comic"}($categories); } if ($category = $this->_storyline->get_valid_post_category($post->ID)) { @@ -68,4 +70,4 @@ class ComicPressNavigation { } } -?> \ No newline at end of file +?> diff --git a/classes/ComicPressStoryline.inc b/classes/ComicPressStoryline.inc index b92337a..b9566e0 100644 --- a/classes/ComicPressStoryline.inc +++ b/classes/ComicPressStoryline.inc @@ -16,7 +16,10 @@ class ComicPressStoryline { */ function get_flattened_storyline() { $comicpress = &ComicPress::get_instance(); - return $comicpress->comicpress_options['storyline_order']; + if (isset($comicpress->comicpress_options['storyline_order'])) { + return $comicpress->comicpress_options['storyline_order']; + } + return false; } /** diff --git a/test/ComicPressNavigationTest.php b/test/ComicPressNavigationTest.php index d55b111..49eb163 100644 --- a/test/ComicPressNavigationTest.php +++ b/test/ComicPressNavigationTest.php @@ -35,25 +35,27 @@ class ComicPressNavigationTest extends PHPUnit_Framework_TestCase { $dbi = $this->getMock('ComicPressDBInterface', array('get_previous_comic', 'get_next_comic', 'get_first_comic', 'get_last_comic')); $storyline = new ComicPressStoryline(); - $storyline->_structure = array( - '1' => array('next' => 2), - '2' => array('previous' => 1, 'next' => 3), - '3' => array('previous' => 2) - ); + $storyline->set_flattened_storyline('0/1,0/1/2,0/3'); wp_insert_post(array('ID' => 1)); $post = get_post(1); wp_set_post_categories(1, array(2)); - $dbi->expects($this->at(0))->method('get_previous_comic')->with(null, $post); - $dbi->expects($this->at(1))->method('get_next_comic')->with(null, $post); - $dbi->expects($this->at(2))->method('get_first_comic')->with(null); - $dbi->expects($this->at(3))->method('get_last_comic')->with(null); + $dbi->expects($this->at(0))->method('get_previous_comic')->with(array(1,2,3), $post); + $dbi->expects($this->at(1))->method('get_next_comic')->with(array(1,2,3), $post); + $dbi->expects($this->at(2))->method('get_first_comic')->with(array(1,2,3)); + $dbi->expects($this->at(3))->method('get_last_comic')->with(array(1,2,3)); $dbi->expects($this->at(4))->method('get_previous_comic')->with(2, $post); $dbi->expects($this->at(5))->method('get_next_comic')->with(2, $post); - $dbi->expects($this->at(6))->method('get_first_comic')->with(1)->will($this->returnValue((object)array('ID' => 1))); - $dbi->expects($this->at(7))->method('get_first_comic')->with(3)->will($this->returnValue((object)array('ID' => 1))); + // level + $dbi->expects($this->at(6))->method('get_first_comic')->with(2)->will($this->returnValue((object)array('ID' => 1))); + // parent + $dbi->expects($this->at(7))->method('get_first_comic')->with(1)->will($this->returnValue((object)array('ID' => 1))); + // previous + $dbi->expects($this->at(8))->method('get_first_comic')->with(1)->will($this->returnValue((object)array('ID' => 1))); + // next + $dbi->expects($this->at(9))->method('get_first_comic')->with(3)->will($this->returnValue((object)array('ID' => 1))); $this->nav->_dbi = $dbi; $this->nav->_storyline = $storyline; @@ -102,4 +104,4 @@ class ComicPressNavigationTest extends PHPUnit_Framework_TestCase { } } -?> \ No newline at end of file +?> diff --git a/test/ComicPressStorylineTest.php b/test/ComicPressStorylineTest.php index 555d2ff..01b85da 100644 --- a/test/ComicPressStorylineTest.php +++ b/test/ComicPressStorylineTest.php @@ -691,4 +691,4 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase { } } -?> \ No newline at end of file +?>