diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetSearchResults.php b/module/VuFind/src/VuFind/AjaxHandler/GetSearchResults.php index 8ee764072f9..4bd1dafa3c8 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetSearchResults.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetSearchResults.php @@ -171,6 +171,8 @@ protected function getSearchResults(ParamsHelper $requestParams): ?Results $this->saveSearchToHistory($results); } + $requestParams->getController()->resultScroller()->init($results); + // Always save search parameters, since these are namespaced by search // class ID. $this->searchMemory->rememberParams($results->getParams()); diff --git a/module/VuFind/src/VuFind/Controller/AbstractSearch.php b/module/VuFind/src/VuFind/Controller/AbstractSearch.php index d3e6bace407..791bbac4344 100644 --- a/module/VuFind/src/VuFind/Controller/AbstractSearch.php +++ b/module/VuFind/src/VuFind/Controller/AbstractSearch.php @@ -423,9 +423,7 @@ protected function getSearchResultsView($setupCallback = null) } // Set up results scroller: - if ($this->resultScrollerActive()) { - $this->resultScroller()->init($results); - } + $this->resultScroller()->init($results); foreach ($results->getErrors() as $error) { try { diff --git a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/NextPrevNavTest.php b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/NextPrevNavTest.php index 5e3352506ae..3f4c8615d64 100644 --- a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/NextPrevNavTest.php +++ b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/NextPrevNavTest.php @@ -48,7 +48,7 @@ class NextPrevNavTest extends \VuFindTest\Integration\MinkTestCase * * @return void */ - public function testEmptySearchResultsCauseNoProblems() + public function testEmptySearchResultsCauseNoProblems(): void { $this->changeConfigs( ['config' => ['Record' => ['next_prev_navigation' => true, 'first_last_navigation' => true]]] @@ -71,4 +71,34 @@ public function testEmptySearchResultsCauseNoProblems() $this->findCssAndGetText($page, 'div.media-body > h1[property=name]') ); } + + /** + * If next_prev_navigation and first_last_navigation are set to true + * and a search results have been loaded via JS the navigation should + * be shown in the results. + * + * @return void + */ + public function testJSCauseNoProblems(): void + { + $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?type=AllField'); + $this->waitForPageLoad($page); + + $this->clickCss($page, '.search-header .pagination-simple .page-next'); + $this->waitForPageLoad($page); + + $this->clickCss($page, '#result0 a.getFull'); + $this->waitForPageLoad($page); + + $this->findCss($page, 'nav .pager'); + } }