From 6f62c22cbc0ca1aed6ee80cee1a3ec141171f7aa Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 20 Dec 2010 20:27:27 -0500 Subject: [PATCH] Fixing fencepost errors. Splitting tests up into smaller groups. --- cake/libs/view/helpers/paginator.php | 4 +- .../libs/view/helpers/paginator.test.php | 119 ++++++++++-------- 2 files changed, 68 insertions(+), 55 deletions(-) diff --git a/cake/libs/view/helpers/paginator.php b/cake/libs/view/helpers/paginator.php index 6f7145643..f7369e408 100644 --- a/cake/libs/view/helpers/paginator.php +++ b/cake/libs/view/helpers/paginator.php @@ -754,7 +754,7 @@ class PaginatorHelper extends AppHelper { $out = ''; - if (is_int($first) && $params['page'] > $first) { + if (is_int($first) && $params['page'] >= $first) { if ($after === null) { $after = $ellipsis; } @@ -811,7 +811,7 @@ class PaginatorHelper extends AppHelper { $out = ''; $lower = $params['pageCount'] - $last + 1; - if (is_int($last) && $params['page'] < $lower) { + if (is_int($last) && $params['page'] <= $lower) { if ($before === null) { $before = $ellipsis; } diff --git a/cake/tests/cases/libs/view/helpers/paginator.test.php b/cake/tests/cases/libs/view/helpers/paginator.test.php index b0c5ae18c..b5e37983b 100644 --- a/cake/tests/cases/libs/view/helpers/paginator.test.php +++ b/cake/tests/cases/libs/view/helpers/paginator.test.php @@ -1810,31 +1810,45 @@ class PaginatorHelperTest extends CakeTestCase { } /** - * testFirstAndLast method + * test first() on the first page. * - * @access public * @return void */ - function testFirstAndLast() { - $this->Paginator->request->params['paging'] = array( - 'Client' => array( - 'page' => 1, - 'current' => 3, - 'count' => 30, - 'prevPage' => false, - 'nextPage' => 2, - 'pageCount' => 15, - 'options' => array(), - 'paramType' => 'named' - ) - ); + function testFirstEmpty() { + $this->Paginator->request->params['paging']['Article']['page'] = 1; $result = $this->Paginator->first(); $expected = ''; $this->assertEqual($result, $expected); + } - $this->Paginator->request->params['paging']['Client']['page'] = 4; +/** + * test first() and options() + * + * @return void + */ + function testFirstFullBaseUrl() { + $this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'DESC'); + $this->Paginator->options(array('url' => array('full_base' => true))); + + $result = $this->Paginator->first(); + $expected = array( + ' array('href' => FULL_BASE_URL . '/index/page:1/sort:Article.title/direction:DESC')), + '<< first', + '/a', + '/span', + ); + $this->assertTags($result, $expected); + } + +/** + * test first() on the fence-post + * + * @return void + */ + function testFirstBoundaries() { $result = $this->Paginator->first(); $expected = array( 'assertTags($result, $expected); + $result = $this->Paginator->first(2); + $expected = array( + ' array('href' => '/index/page:1')), '1', '/a', + '/span', + ' | ', + ' array('href' => '/index/page:2')), '2', '/a', + '/span' + ); + $this->assertTags($result, $expected); + } + +/** + * test Last method + * + * @access public + * @return void + */ + function testLast() { $result = $this->Paginator->last(); $expected = array( ' array('href' => '/index/page:15'), + 'a' => array('href' => '/index/page:7'), 'last >>', '/a', '/span' @@ -1859,26 +1893,35 @@ class PaginatorHelperTest extends CakeTestCase { $expected = array( '...', ' array('href' => '/index/page:15'), - '15', + 'a' => array('href' => '/index/page:7'), + '7', '/a', '/span' ); $this->assertTags($result, $expected); + $this->Paginator->request->params['paging']['Article']['page'] = 6; + $result = $this->Paginator->last(2); $expected = array( '...', ' array('href' => '/index/page:14')), '14', '/a', + array('a' => array('href' => '/index/page:6')), '6', '/a', '/span', ' | ', ' array('href' => '/index/page:15')), '15', '/a', + array('a' => array('href' => '/index/page:7')), '7', '/a', '/span', ); $this->assertTags($result, $expected); - + } + +/** + * undocumented function + * + * @return void + */ + function testLastOptions() { $this->Paginator->request->params['paging'] = array( 'Client' => array( 'page' => 4, @@ -1895,14 +1938,6 @@ class PaginatorHelperTest extends CakeTestCase { ) ); - $result = $this->Paginator->first(); - $expected = array( - ' array('href' => '/index/page:1/sort:Client.name/direction:DESC')), '<< first', '/a', - '/span', - ); - $this->assertTags($result, $expected); - $result = $this->Paginator->last(); $expected = array( 'assertTags($result, $expected); - + $result = $this->Paginator->last(1); $expected = array( '...', @@ -1933,19 +1968,6 @@ class PaginatorHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); - $result = $this->Paginator->last(2, array('ellipsis' => '~~~')); - $expected = array( - '~~~', - ' array('href' => '/index/page:14/sort:Client.name/direction:DESC')), '14', '/a', - '/span', - ' | ', - ' array('href' => '/index/page:15/sort:Client.name/direction:DESC')), '15', '/a', - '/span', - ); - $this->assertTags($result, $expected); - $result = $this->Paginator->last(2, array('ellipsis' => '...')); $expected = array( array('span' => array('class' => 'ellipsis')), '...', '/span', @@ -1958,15 +1980,6 @@ class PaginatorHelperTest extends CakeTestCase { '/span', ); $this->assertTags($result, $expected); - - $this->Paginator->options(array('url' => array('full_base' => true))); - $result = $this->Paginator->first(); - $expected = array( - ' array('href' => FULL_BASE_URL . '/index/page:1/sort:Client.name/direction:DESC')), '<< first', '/a', - '/span', - ); - $this->assertTags($result, $expected); } /**