diff --git a/module/VuFind/src/VuFind/Controller/Plugin/ResultScroller.php b/module/VuFind/src/VuFind/Controller/Plugin/ResultScroller.php index 4f39ae5658791b02aeac260f44c7981c37da4f17..c34b6ed0c9804412be228608a288d88100d8e1e7 100644 --- a/module/VuFind/src/VuFind/Controller/Plugin/ResultScroller.php +++ b/module/VuFind/src/VuFind/Controller/Plugin/ResultScroller.php @@ -100,6 +100,7 @@ class ResultScroller extends AbstractPlugin $this->data->searchId = $searchObject->getSearchId(); $this->data->page = $searchObject->getParams()->getPage(); $this->data->limit = $searchObject->getParams()->getLimit(); + $this->data->sort = $searchObject->getParams()->getSort(); $this->data->total = $searchObject->getResultTotal(); $this->data->firstlast = $searchObject->getOptions() ->supportsFirstLastNavigation(); @@ -536,7 +537,7 @@ class ResultScroller extends AbstractPlugin */ protected function fetchPage($searchObject, $page = null) { - if (!is_null($page)) { + if (null !== $page) { $searchObject->getParams()->setPage($page); $searchObject->performAndProcessSearch(); } @@ -568,6 +569,7 @@ class ResultScroller extends AbstractPlugin // The saved search does not remember its original limit; // we should reapply it from the session data: $search->getParams()->setLimit($this->data->limit); + $search->getParams()->setSort($this->data->sort); return $search; } } diff --git a/module/VuFind/src/VuFindTest/Search/TestHarness/Results.php b/module/VuFind/src/VuFindTest/Search/TestHarness/Results.php index a915805b9818fec824dd22f73ba0e722f2abba4e..99f4224e5b8bf9cc697f5febee247517f32db19c 100644 --- a/module/VuFind/src/VuFindTest/Search/TestHarness/Results.php +++ b/module/VuFind/src/VuFindTest/Search/TestHarness/Results.php @@ -115,7 +115,10 @@ class Results extends \VuFind\Search\Base\Results if ($i > $this->resultTotal) { break; } - $this->results[] = $this->getMockRecordDriver($i); + // Append sort type to ID to simulate sort order; default sort is + // null, so most tests will just get numbers. + $sort = $this->getParams()->getSort(); + $this->results[] = $this->getMockRecordDriver($sort . $i); } } 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 ae7fb28404accce58ac48ebb0eee9c4cad7dc169..6d51a0ab5ef603465ed69070f89ad88685efec8a 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 @@ -292,18 +292,39 @@ class ResultScrollerTest extends TestCase $this->assertEquals($expected, $plugin->getScrollData($results->getMockRecordDriver(20))); } + /** + * Test scrolling at end of middle page with sorting. + * + * @return void + */ + public function testScrollingAtEndOfMiddlePageWithSorting() + { + $results = $this->getMockResults(2, 10, 30, true, 'sorted'); + $plugin = $this->getMockResultScroller($results); + $this->assertTrue($plugin->init($results)); + $expected = [ + 'firstRecord' => 'Solr|sorted1', 'lastRecord' => 'Solr|sorted30', + 'previousRecord' => 'Solr|sorted19', 'nextRecord' => 'Solr|sorted21', + 'currentPosition' => 20, 'resultTotal' => 30 + ]; + $this->assertEquals($expected, $plugin->getScrollData( + $results->getMockRecordDriver('sorted20')) + ); + } + /** * Get mock search results * - * @param int $page Current page number - * @param int $limit Page size - * @param int $total Total size of fake result set - * @param bool $firstLast Turn on first/last config? + * @param int $page Current page number + * @param int $limit Page size + * @param int $total Total size of fake result set + * @param bool $firstLast Turn on first/last config? + * @param string $sort Sort type (null for default) * * @return \VuFind\Search\Base\Results */ protected function getMockResults($page = 1, $limit = 20, $total = 0, - $firstLast = true + $firstLast = true, $sort = null ) { $pm = $this->getMockBuilder('VuFind\Config\PluginManager')->disableOriginalConstructor()->getMock(); $config = new \Zend\Config\Config( @@ -314,6 +335,9 @@ class ResultScrollerTest extends TestCase $params = new \VuFindTest\Search\TestHarness\Params($options, $pm); $params->setPage($page); $params->setLimit($limit); + if (null !== $sort) { + $params->setSort($sort, true); + } $ss = $this->getMockBuilder('VuFindSearch\Service') ->disableOriginalConstructor()->getMock(); $rl = $this->getMockBuilder('VuFind\Record\Loader')