diff --git a/tests/TestCase/View/Helper/PaginatorHelperTest.php b/tests/TestCase/View/Helper/PaginatorHelperTest.php index c0119a4cc63..c50319217b7 100644 --- a/tests/TestCase/View/Helper/PaginatorHelperTest.php +++ b/tests/TestCase/View/Helper/PaginatorHelperTest.php @@ -423,6 +423,42 @@ public function testSortLinksUsingDotNotation() $this->assertHtml($expected, $result); } + /** + * test multiple pagination sort links + * + * @return void + */ + public function testSortLinksMultiplePagination() + { + Router::setRequestInfo([ + ['plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => [], 'url' => ['url' => 'accounts/']], + ['base' => '', 'here' => '/accounts/', 'webroot' => '/'] + ]); + + $this->Paginator->options(['model' => 'Articles']); + $this->Paginator->request['paging'] = [ + 'Articles' => [ + 'current' => 9, + 'count' => 62, + 'prevPage' => false, + 'nextPage' => true, + 'pageCount' => 7, + 'sort' => 'date', + 'direction' => 'asc', + 'page' => 1, + 'prefix' => 'article', + ] + ]; + + $result = $this->Paginator->sort('title'); + $expected = [ + 'a' => ['href' => '/accounts/index?article%5Bsort%5D=title&article%5Bdirection%5D=asc'], + 'Title', + '/a' + ]; + $this->assertHtml($expected, $result); + } + /** * Test creating paging links for missing models. * @@ -677,7 +713,7 @@ public function testUrlGeneration() * * @return void */ - public function testUrlGenerationWithPrefixes() + public function testGenerateUrlWithPrefixes() { Configure::write('Routing.prefixes', ['members']); Router::reload(); @@ -736,6 +772,60 @@ public function testUrlGenerationWithPrefixes() $this->assertEquals($expected, $result); } + /** + * test generateUrl with multiple pagination + * + * @return void + */ + public function testGenerateUrlMultiplePagination() + { + Router::setRequestInfo([ + ['controller' => 'posts', 'action' => 'index', 'plugin' => null], + ['base' => '', 'here' => 'posts/index', 'webroot' => '/'] + ]); + + $this->Paginator->request->params['paging']['Article']['prefix'] = 'article'; + $this->Paginator->request->params['paging']['Article']['page'] = 3; + $this->Paginator->request->params['paging']['Article']['prevPage'] = true; + $this->Paginator->options(['model' => 'Article']); + + $result = $this->Paginator->generateUrl([]); + $expected = '/posts/index?article%5Bpage%5D=3'; + $this->assertEquals($expected, $result); + + $result = $this->Paginator->sort('name'); + $expected = [ + 'a' => ['href' => '/posts/index?article%5Bpage%5D=3&article%5Bsort%5D=name&article%5Bdirection%5D=asc'], + 'Name', + '/a' + ]; + $this->assertHtml($expected, $result); + + $result = $this->Paginator->next('next'); + $expected = [ + 'li' => ['class' => 'next'], + 'a' => ['href' => '/posts/index?article%5Bpage%5D=4', 'rel' => 'next'], + 'next', + '/a', + '/li' + ]; + $this->assertHtml($expected, $result); + + $result = $this->Paginator->prev('prev'); + $expected = [ + 'li' => ['class' => 'prev'], + 'a' => ['href' => '/posts/index?article%5Bpage%5D=2', 'rel' => 'prev'], + 'prev', + '/a', + '/li' + ]; + $this->assertHtml($expected, $result); + + $result = $this->Paginator->generateUrl(['sort' => 'name']); + $expected = '/posts/index?article%5Bpage%5D=3&article%5Bsort%5D=name'; + $this->assertEquals($expected, $result); + } + /** * testOptions method *