From d578797b7b4cfacfee6d015bdbe82ac6aa5c192e Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sat, 28 Nov 2009 16:57:43 -0500 Subject: [PATCH] make first link work with multipage --- .../widgets/GraphicalNavigationWidgetTest.php | 19 ++++++++++--------- widgets/GraphicalNavigationWidget.inc | 12 +++++++----- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/test/widgets/GraphicalNavigationWidgetTest.php b/test/widgets/GraphicalNavigationWidgetTest.php index faa84f7..aa29f0f 100644 --- a/test/widgets/GraphicalNavigationWidgetTest.php +++ b/test/widgets/GraphicalNavigationWidgetTest.php @@ -28,20 +28,21 @@ class GraphicalNavigationWidgetTest extends PHPUnit_Framework_TestCase { function providerTestIsNavLinkVisible() { return array( - array('first', 1, 2, 1, 1, true), - array('first', 1, 1, 1, 1, false), - array('last', 1, 2, 1, 1, true), - array('last', 1, 1, 1, 1, false), - array('prev', 1, 2, 1, 1, true), - array('first', 1, 1, 2, 2, true), - array('first', 1, 1, 1, 2, false), + array('first', 1, 2, 1, 1, 'on', true), + array('first', 1, 1, 1, 1, 'on', false), + array('last', 1, 2, 1, 1, 'on', true), + array('last', 1, 1, 1, 1, 'on', false), + array('prev', 1, 2, 1, 1, 'on', true), + array('first', 1, 1, 2, 2, 'on', true), + array('first', 1, 1, 1, 2, 'on', false), + array('first', 1, 1, 2, 2, 'off', false), ); } /** * @dataProvider providerTestIsNavLinkVisible */ - function testIsNavLinkVisible($which, $current_id, $target_id, $_page, $_numpages, $expected_result) { + function testIsNavLinkVisible($which, $current_id, $target_id, $_page, $_numpages, $multi_page_support, $expected_result) { global $page, $numpages; $page = $_page; $numpages = $_numpages; @@ -49,7 +50,7 @@ class GraphicalNavigationWidgetTest extends PHPUnit_Framework_TestCase { $current = (object)array('ID' => $current_id); $target = (object)array('ID' => $target_id); - $this->assertEquals($expected_result, $this->w->_will_display_nav_link($which, $current, $target)); + $this->assertEquals($expected_result, $this->w->_will_display_nav_link($which, $current, $target, array('enable_multipage_support' => $multi_page_support))); } function providerTestGroupNavigationButtons() { diff --git a/widgets/GraphicalNavigationWidget.inc b/widgets/GraphicalNavigationWidget.inc index c6112eb..1c20d62 100644 --- a/widgets/GraphicalNavigationWidget.inc +++ b/widgets/GraphicalNavigationWidget.inc @@ -63,7 +63,7 @@ class GraphicalNavigationWidget extends WP_Widget { switch ($which) { case 'first': case 'last': - $ok = $this->_will_display_nav_link($which, $current, $target); + $ok = $this->_will_display_nav_link($which, $current, $target, $instance); break; case 'previous': case 'next': @@ -169,16 +169,18 @@ class GraphicalNavigationWidget extends WP_Widget { * @param object $target The target post to comare to. * @return boolean True if this link should be visible. */ - function _will_display_nav_link($which, $current, $target) { + function _will_display_nav_link($which, $current, $target, $instance) { global $page, $numpages; $return = true; switch ($which) { case 'first': - if ($page != 1 && $numpages > 1) { - $return = true; - break; + if ($instance['enable_multipage_support'] == 'on') { + if ($page != 1 && $numpages > 1) { + $return = true; + break; + } } case 'last': $return = ($target->ID != $current->ID);