Skip to content

Commit

Permalink
remove current page param from first page link
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-gribanov committed Apr 12, 2017
1 parent aec72d7 commit c12e523
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/Service/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ private function configureFromRequest(
) {
$route = $request->get('_route');
$route_params = array_merge($request->query->all(), $request->get('_route_params'));
unset($route_params[$parameter_name]);

return $configuration
->setPageLink(function ($number) use ($route, $route_params, $parameter_name, $reference_type) {
Expand Down
21 changes: 11 additions & 10 deletions tests/Service/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class BuilderTest extends TestCase
*/
private $query_params = [
'foo' => 'bar',
'p' => 2,
];

protected function setUp()
Expand Down Expand Up @@ -190,7 +191,8 @@ public function testPaginateRequest()
$total_pages = 10;
$parameter_name = 'p';
$route = '_route';
$route_params = array_merge($this->query_params, ['foo' => 'baz', '_route_params']);
$route_params = ['foo' => 'baz', '_route_params' => 123];
$all_params = array_merge($this->query_params, $route_params);
$reference_type = UrlGeneratorInterface::ABSOLUTE_URL;

$this->currentPage(null, 'p');
Expand All @@ -214,12 +216,10 @@ public function testPaginateRequest()
->will($this->returnCallback(function ($_route, $_route_params, $_reference_type) use (
$that,
$route,
$route_params,
$reference_type
) {
$that->assertEquals($reference_type, $_reference_type);
$that->assertEquals($route, $_route);
$that->assertEquals($route_params, array_intersect($_route_params, $route_params));

return $_route.http_build_query($_route_params);
}))
Expand All @@ -231,11 +231,12 @@ public function testPaginateRequest()
$this->assertEquals($max_navigate, $config->getMaxNavigate());
$this->assertEquals($total_pages, $config->getTotalPages());
$this->assertEquals(1, $config->getCurrentPage());
$this->assertEquals($route.http_build_query($route_params), $config->getFirstPageLink());
unset($all_params['p']);
$this->assertEquals($route.http_build_query($all_params), $config->getFirstPageLink());
$this->assertInstanceOf('Closure', $config->getPageLink());
$page_number = 3;
$this->assertEquals(
$route.http_build_query($route_params + [$parameter_name => $page_number]),
$route.http_build_query($all_params + [$parameter_name => $page_number]),
call_user_func($config->getPageLink(), $page_number)
);
}
Expand Down Expand Up @@ -284,7 +285,8 @@ public function testPaginateRequestQuery()
$total = 150;
$parameter_name = 'p';
$route = '_route';
$route_params = array_merge($this->query_params, ['foo' => 'baz', '_route_params']);
$route_params = ['foo' => 'baz', '_route_params'];
$all_params = array_merge($this->query_params, $route_params);
$reference_type = UrlGeneratorInterface::ABSOLUTE_URL;

$this->currentPage($current_page, 'p');
Expand Down Expand Up @@ -322,12 +324,10 @@ public function testPaginateRequestQuery()
->will($this->returnCallback(function ($_route, $_route_params, $_reference_type) use (
$that,
$route,
$route_params,
$reference_type
) {
$that->assertEquals($reference_type, $_reference_type);
$that->assertEquals($route, $_route);
$that->assertEquals($route_params, array_intersect($_route_params, $route_params));

return $_route.http_build_query($_route_params);
}))
Expand All @@ -345,11 +345,12 @@ public function testPaginateRequestQuery()
$this->assertEquals($max_navigate, $config->getMaxNavigate());
$this->assertEquals(ceil($total / $per_page), $config->getTotalPages());
$this->assertEquals($current_page, $config->getCurrentPage());
$this->assertEquals($route.http_build_query($route_params), $config->getFirstPageLink());
unset($all_params['p']);
$this->assertEquals($route.http_build_query($all_params), $config->getFirstPageLink());
$this->assertInstanceOf('Closure', $config->getPageLink());
$page_number = 3;
$this->assertEquals(
$route.http_build_query($route_params + [$parameter_name => $page_number]),
$route.http_build_query($all_params + [$parameter_name => $page_number]),
call_user_func($config->getPageLink(), $page_number)
);
}
Expand Down

0 comments on commit c12e523

Please sign in to comment.