Skip to content

Commit

Permalink
Merge pull request #294 from FriendsOfCake/dereuromark-patch-2
Browse files Browse the repository at this point in the history
Dont drop passed params for reset
  • Loading branch information
ADmad authored Nov 3, 2020
2 parents 9d55dbf + 0a20a78 commit 2cc18da
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/View/Helper/SearchHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,11 @@ public function resetUrl(): array
unset($query[$param]);
}

return [
$url = (array)$this->getView()->getRequest()->getParam('pass');
$url += [
'?' => $query,
];

return $url;
}
}
31 changes: 31 additions & 0 deletions tests/TestCase/View/Helper/SearchHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,37 @@ public function testResetUrl()
$this->assertSame($expected, $result);
}

/**
* @return void
*/
public function testResetUrlWithPassedParams()
{
$request = new ServerRequest([
'url' => '/controller/action/my-passed?limit=5&sort=x&direction=asc&foo=baz&bar=1',
]);
$request = $request->withParam('pass', ['my-passed']);

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

$params = [
'foo' => 'baz',
'bar' => '1',
];
$this->view->set('_searchParams', $params);

$result = $this->searchHelper->resetUrl();
$expected = [
'my-passed',
'?' => [
'limit' => '5',
'sort' => 'x',
'direction' => 'asc',
],
];
$this->assertSame($expected, $result);
}

/**
* @return void
*/
Expand Down

0 comments on commit 2cc18da

Please sign in to comment.