fix the fact that you con't pass restrictions to navigation

This commit is contained in:
John Bintz 2009-11-21 09:56:31 -05:00
parent b25f03389b
commit 364c1479a2
4 changed files with 25 additions and 18 deletions

View File

@ -11,7 +11,7 @@ class ComicPressNavigation {
} }
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
function get_post_nav($post) { function get_post_nav($post, $restrictions = null) {
$nav = array(); $nav = array();
if (is_object($post)) { if (is_object($post)) {
if (isset($post->ID)) { if (isset($post->ID)) {
@ -24,14 +24,16 @@ class ComicPressNavigation {
return $nav; return $nav;
} }
$categories = $this->_storyline->build_from_restrictions($restrictions);
// global previous/next // global previous/next
foreach (array('previous', 'next') as $field) { 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 // global first/last
foreach (array('first', 'last') as $field) { 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)) { if ($category = $this->_storyline->get_valid_post_category($post->ID)) {
@ -68,4 +70,4 @@ class ComicPressNavigation {
} }
} }
?> ?>

View File

@ -16,7 +16,10 @@ class ComicPressStoryline {
*/ */
function get_flattened_storyline() { function get_flattened_storyline() {
$comicpress = &ComicPress::get_instance(); $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;
} }
/** /**

View File

@ -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')); $dbi = $this->getMock('ComicPressDBInterface', array('get_previous_comic', 'get_next_comic', 'get_first_comic', 'get_last_comic'));
$storyline = new ComicPressStoryline(); $storyline = new ComicPressStoryline();
$storyline->_structure = array( $storyline->set_flattened_storyline('0/1,0/1/2,0/3');
'1' => array('next' => 2),
'2' => array('previous' => 1, 'next' => 3),
'3' => array('previous' => 2)
);
wp_insert_post(array('ID' => 1)); wp_insert_post(array('ID' => 1));
$post = get_post(1); $post = get_post(1);
wp_set_post_categories(1, array(2)); wp_set_post_categories(1, array(2));
$dbi->expects($this->at(0))->method('get_previous_comic')->with(null, $post); $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(null, $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(null); $dbi->expects($this->at(2))->method('get_first_comic')->with(array(1,2,3));
$dbi->expects($this->at(3))->method('get_last_comic')->with(null); $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(4))->method('get_previous_comic')->with(2, $post);
$dbi->expects($this->at(5))->method('get_next_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))); // level
$dbi->expects($this->at(7))->method('get_first_comic')->with(3)->will($this->returnValue((object)array('ID' => 1))); $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->_dbi = $dbi;
$this->nav->_storyline = $storyline; $this->nav->_storyline = $storyline;
@ -102,4 +104,4 @@ class ComicPressNavigationTest extends PHPUnit_Framework_TestCase {
} }
} }
?> ?>

View File

@ -691,4 +691,4 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
} }
} }
?> ?>