Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/View/Helper/SearchHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Search\View\Helper;

use Cake\Datasource\Paging\PaginatedInterface;
use Cake\View\Helper;
use Cake\View\View;
use function Cake\I18n\__d;
Expand Down Expand Up @@ -34,15 +35,18 @@ class SearchHelper extends Helper
];

/**
* Checks for pagination and if so, blacklist limit and page params.
* Checks for paginated resultset and if so, blacklist the `page` param.
*
* @param \Cake\View\View $View View
* @param array $config Config
*/
public function __construct(View $View, array $config)
{
if ($View->getRequest()->getParam('paging')) {
$this->_defaultConfig['additionalBlacklist'][] = 'page';
foreach ($View->getVars() as $name) {
if ($View->get($name) instanceof PaginatedInterface) {
$this->_defaultConfig['additionalBlacklist'][] = 'page';
break;
}
}

parent::__construct($View, $config);
Expand Down
11 changes: 9 additions & 2 deletions tests/TestCase/View/Helper/SearchHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Search\Test\View\Helper;

use Cake\Datasource\Paging\PaginatedInterface;
use Cake\Http\ServerRequest;
use Cake\Routing\RouteBuilder;
use Cake\Routing\Router;
Expand Down Expand Up @@ -128,9 +129,12 @@ public function testResetUrlWithPaginator()
$request = new ServerRequest([
'url' => '/controller/action?page=2&limit=5&sort=x&direction=asc&foo=bar',
]);
$request = $request->withParam('paging', ['Something']);

$this->view = new View($request);

$paginatedResult = $this->createMock(PaginatedInterface::class);
$this->view->set('results', $paginatedResult);

$this->searchHelper = new SearchHelper($this->view, []);

$params = [
Expand All @@ -157,9 +161,12 @@ public function testResetUrlWithPaginatorAndAdditionalBlacklist()
$request = new ServerRequest([
'url' => '/controller/action?page=2&limit=5&sort=x&direction=asc&foo=bar',
]);
$request = $request->withParam('paging', ['Something']);

$this->view = new View($request);

$paginatedResult = $this->createMock(PaginatedInterface::class);
$this->view->set('results', $paginatedResult);

$config = [
'additionalBlacklist' => [
'sort',
Expand Down