diff --git a/module/VuFind/src/VuFind/Controller/Plugin/ResultScroller.php b/module/VuFind/src/VuFind/Controller/Plugin/ResultScroller.php index 6383f83cc9c735a03e523b873a5ede9ba11439ed..6f5fed38eb6b230bb061ebfb3d3838a0e1d5a0af 100644 --- a/module/VuFind/src/VuFind/Controller/Plugin/ResultScroller.php +++ b/module/VuFind/src/VuFind/Controller/Plugin/ResultScroller.php @@ -91,8 +91,8 @@ class ResultScroller extends AbstractPlugin */ public function init($searchObject) { - // Do nothing if disabled: - if (!$this->enabled) { + // Do nothing if disabled or search is empty: + if (!$this->enabled || $searchObject->getResultTotal() === 0) { return false; } diff --git a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/NextPrevNavTest.php b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/NextPrevNavTest.php new file mode 100644 index 0000000000000000000000000000000000000000..a630e2c33e7e8ee5e0c8b3bc3181422f287ef884 --- /dev/null +++ b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/NextPrevNavTest.php @@ -0,0 +1,67 @@ +<?php +/** + * Next/previous navigation test class. + * + * PHP version 5 + * + * Copyright (C) Villanova University 2018. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category VuFind + * @package Tests + * @author Conor Sheehan <csheehan@nli.ie> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org Main Page + */ +namespace VuFindTest\Mink; + +/** + * Next/previous navigation test class. + * + * @category VuFind + * @package Tests + * @author Conor Sheehan <csheehan@nli.ie> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org Main Page + */ +class NextPrevNavTest extends \VuFindTest\Unit\MinkTestCase +{ + /** + * if next_prev_navigation and first_last_navigation are set to true + * and a search which returns no results is run + * when a record page is visited no next prev navigation should be shown + * and no exception should be thrown + * + * @return void + */ + public function testEmptySearchResultsCauseNoProblems() + { + $this->changeConfigs(["config" => ["Record" => ["next_prev_navigation" => true, "first_last_navigation" => true]]]); + + // when a search returns no results + // make sure no errors occur when visiting a collection record after + $session = $this->getMinkSession(); + $page = $session->getPage(); + + $session->visit($this->getVuFindUrl() . "/Search/Results?lookfor=__ReturnNoResults__&type=AllField"); + $this->assertEquals($this->findCss($page, ".search-stats > h2")->getText(), "No Results!"); + + // collection should render as normal + $session->visit($this->getVuFindUrl() . "/Record/geo20001"); + + // should fail if exception is thrown + $this->assertContains("Test Publication 20001", $this->findCss($page, "div.media-body > h3[property=name]")->getText()); + } +} diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Controller/Plugin/ResultScrollerTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Controller/Plugin/ResultScrollerTest.php index 5b509546d30d6dfa5c84ef646993fb43b0a2dbdf..123c589a64ade4499282835fa5940a4a02968452 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/Controller/Plugin/ResultScrollerTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Controller/Plugin/ResultScrollerTest.php @@ -43,6 +43,29 @@ use Zend\Session\Container; */ class ResultScrollerTest extends TestCase { + /** + * Test next_prev_nav bug + * Expect next_prev to behave like it's disabled if the last search didn't return any results + * + * @return void + */ + public function testNextPrevNavBug() + { + $results = $this->getMockResults(0, 0, 0, true, 'sorted'); + $plugin = $this->getMockResultScroller($results); + $this->assertFalse($plugin->init($results)); + + $expected = [ + 'firstRecord' => null, 'lastRecord' => null, + 'previousRecord' => null, 'nextRecord' => null, + 'currentPosition' => null, 'resultTotal' => null + ]; + + $this->assertEquals($expected, $plugin->getScrollData( + $results->getMockRecordDriver('sorted20')) + ); + } + /** * Test disabled behavior *