From 430612f1df7ac8284fead650020c33e3349eb704 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 26 Dec 2015 22:37:25 -0500 Subject: [PATCH] Split mega test up. The previous testNumbers() method was a behemoth. Split out the scenarios for first/last a bit. Refs #7902 --- .../Case/View/Helper/PaginatorHelperTest.php | 274 +++++++++--------- 1 file changed, 141 insertions(+), 133 deletions(-) diff --git a/lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php b/lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php index f536ed5969b..8c27cfbef3a 100644 --- a/lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php @@ -1729,6 +1729,147 @@ public function testNumbers() { ); $this->assertTags($result, $expected); + $this->Paginator->request->params['paging'] = array( + 'Client' => array( + 'page' => 1, + 'current' => 10, + 'count' => 30, + 'prevPage' => false, + 'nextPage' => 2, + 'pageCount' => 3, + 'options' => array( + 'page' => 1, + ), + 'paramType' => 'named' + ) + ); + $options = array('modulus' => 10); + $result = $this->Paginator->numbers($options); + $expected = array( + array('span' => array('class' => 'current')), '1', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span', + ); + $this->assertTags($result, $expected); + + $result = $this->Paginator->numbers(array('modulus' => 3, 'currentTag' => 'span', 'tag' => 'li')); + $expected = array( + array('li' => array('class' => 'current')), array('span' => array()), '1', '/span', '/li', + ' | ', + array('li' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/li', + ' | ', + array('li' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/li', + ); + $this->assertTags($result, $expected); + + $this->Paginator->request->params['paging'] = array( + 'Client' => array( + 'page' => 2, + 'current' => 10, + 'count' => 31, + 'prevPage' => true, + 'nextPage' => true, + 'pageCount' => 4, + 'options' => array( + 'page' => 1, + 'order' => array('Client.name' => 'DESC'), + ), + 'paramType' => 'named' + ) + ); + $result = $this->Paginator->numbers(array('class' => 'page-link')); + $expected = array( + array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/sort:Client.name/direction:DESC')), '1', '/a', '/span', + ' | ', + array('span' => array('class' => 'current page-link')), '2', '/span', + ' | ', + array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:3/sort:Client.name/direction:DESC')), '3', '/a', '/span', + ' | ', + array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:4/sort:Client.name/direction:DESC')), '4', '/a', '/span', + ); + $this->assertTags($result, $expected); + + $this->Paginator->request->params['paging'] = array( + 'Client' => array( + 'page' => 2, + 'current' => 2, + 'count' => 30, + 'prevPage' => false, + 'nextPage' => 3, + 'pageCount' => 3, + 'options' => array( + 'page' => 1, + ), + 'paramType' => 'named' + ) + ); + + $request = new CakeRequest(); + $request->addParams(array( + 'controller' => 'clients', 'action' => 'index', 'plugin' => null, 'page' => 2 + )); + $request->base = ''; + $request->here = '/clients/index/page:2'; + $request->webroot = '/'; + + Router::setRequestInfo($request); + + $result = $this->Paginator->numbers(); + $expected = array( + array('span' => array()), array('a' => array('href' => '/clients')), '1', '/a', '/span', + ' | ', + array('span' => array('class' => 'current')), '2', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/clients/index/page:3')), '3', '/a', '/span', + + ); + $this->assertTags($result, $expected); + + $this->Paginator->request->params['paging'] = array( + 'Client' => array( + 'page' => 2, + 'current' => 2, + 'count' => 30, + 'prevPage' => false, + 'nextPage' => 3, + 'pageCount' => 3, + 'options' => array( + 'page' => 1, + ), + 'paramType' => 'querystring' + ) + ); + + $request = new CakeRequest(); + $request->addParams(array( + 'controller' => 'clients', 'action' => 'index', 'plugin' => null + )); + $request->base = ''; + $request->here = '/clients?page=2'; + $request->webroot = '/'; + + Router::setRequestInfo($request); + + $result = $this->Paginator->numbers(); + $expected = array( + array('span' => array()), array('a' => array('href' => '/clients')), '1', '/a', '/span', + ' | ', + array('span' => array('class' => 'current')), '2', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/clients?page=3')), '3', '/a', '/span', + + ); + $this->assertTags($result, $expected); + } + +/** + * Test that numbers() works with first and last options. + * + * @return void + */ + public function testNumbersFirstAndLast() { $this->Paginator->request->params['paging'] = array( 'Client' => array( 'page' => 10, @@ -1852,68 +1993,6 @@ public function testNumbers() { ); $this->assertTags($result, $expected); - $this->Paginator->request->params['paging'] = array( - 'Client' => array( - 'page' => 1, - 'current' => 10, - 'count' => 30, - 'prevPage' => false, - 'nextPage' => 2, - 'pageCount' => 3, - 'options' => array( - 'page' => 1, - ), - 'paramType' => 'named' - ) - ); - $options = array('modulus' => 10); - $result = $this->Paginator->numbers($options); - $expected = array( - array('span' => array('class' => 'current')), '1', '/span', - ' | ', - array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span', - ' | ', - array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span', - ); - $this->assertTags($result, $expected); - - $result = $this->Paginator->numbers(array('modulus' => 3, 'currentTag' => 'span', 'tag' => 'li')); - $expected = array( - array('li' => array('class' => 'current')), array('span' => array()), '1', '/span', '/li', - ' | ', - array('li' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/li', - ' | ', - array('li' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/li', - ); - $this->assertTags($result, $expected); - - $this->Paginator->request->params['paging'] = array( - 'Client' => array( - 'page' => 2, - 'current' => 10, - 'count' => 31, - 'prevPage' => true, - 'nextPage' => true, - 'pageCount' => 4, - 'options' => array( - 'page' => 1, - 'order' => array('Client.name' => 'DESC'), - ), - 'paramType' => 'named' - ) - ); - $result = $this->Paginator->numbers(array('class' => 'page-link')); - $expected = array( - array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/sort:Client.name/direction:DESC')), '1', '/a', '/span', - ' | ', - array('span' => array('class' => 'current page-link')), '2', '/span', - ' | ', - array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:3/sort:Client.name/direction:DESC')), '3', '/a', '/span', - ' | ', - array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:4/sort:Client.name/direction:DESC')), '4', '/a', '/span', - ); - $this->assertTags($result, $expected); - $this->Paginator->request->params['paging'] = array( 'Client' => array( 'page' => 4895, @@ -2132,77 +2211,6 @@ public function testNumbers() { ); $this->assertTags($result, $expected); - $this->Paginator->request->params['paging'] = array( - 'Client' => array( - 'page' => 2, - 'current' => 2, - 'count' => 30, - 'prevPage' => false, - 'nextPage' => 3, - 'pageCount' => 3, - 'options' => array( - 'page' => 1, - ), - 'paramType' => 'named' - ) - ); - - $request = new CakeRequest(); - $request->addParams(array( - 'controller' => 'clients', 'action' => 'index', 'plugin' => null, 'page' => 2 - )); - $request->base = ''; - $request->here = '/clients/index/page:2'; - $request->webroot = '/'; - - Router::setRequestInfo($request); - - $result = $this->Paginator->numbers(); - $expected = array( - array('span' => array()), array('a' => array('href' => '/clients')), '1', '/a', '/span', - ' | ', - array('span' => array('class' => 'current')), '2', '/span', - ' | ', - array('span' => array()), array('a' => array('href' => '/clients/index/page:3')), '3', '/a', '/span', - - ); - $this->assertTags($result, $expected); - - $this->Paginator->request->params['paging'] = array( - 'Client' => array( - 'page' => 2, - 'current' => 2, - 'count' => 30, - 'prevPage' => false, - 'nextPage' => 3, - 'pageCount' => 3, - 'options' => array( - 'page' => 1, - ), - 'paramType' => 'querystring' - ) - ); - - $request = new CakeRequest(); - $request->addParams(array( - 'controller' => 'clients', 'action' => 'index', 'plugin' => null - )); - $request->base = ''; - $request->here = '/clients?page=2'; - $request->webroot = '/'; - - Router::setRequestInfo($request); - - $result = $this->Paginator->numbers(); - $expected = array( - array('span' => array()), array('a' => array('href' => '/clients')), '1', '/a', '/span', - ' | ', - array('span' => array('class' => 'current')), '2', '/span', - ' | ', - array('span' => array()), array('a' => array('href' => '/clients?page=3')), '3', '/a', '/span', - - ); - $this->assertTags($result, $expected); } /**