From 231d58522136ee46e8dd97c0c418d6a67695d98e Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 8 May 2008 03:26:47 +0000 Subject: [PATCH] Updated paginator.test.php to increase code coverage git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6767 3807eeeb-6ff5-0310-8944-8be069107fe0 --- .../libs/view/helpers/paginator.test.php | 119 +++++++++++++++++- 1 file changed, 118 insertions(+), 1 deletion(-) diff --git a/cake/tests/cases/libs/view/helpers/paginator.test.php b/cake/tests/cases/libs/view/helpers/paginator.test.php index 697b2d6a5..18572a812 100644 --- a/cake/tests/cases/libs/view/helpers/paginator.test.php +++ b/cake/tests/cases/libs/view/helpers/paginator.test.php @@ -159,8 +159,37 @@ class PaginatorTest extends UnitTestCase { $this->Paginator->params['paging']['Article']['options']['page'] = 2; $result = $this->Paginator->url(); $this->assertEqual($result, '/index/page:2'); + + $options = array('order' => array('Article' => 'desc')); + $result = $this->Paginator->url($options); + $this->assertEqual($result, '/index/page:2/sort:Article/direction:desc'); } - + + function testOptions() { + $this->Paginator->options('myDiv'); + $this->assertEqual('myDiv', $this->Paginator->options['update']); + + $this->Paginator->options = array(); + $this->Paginator->params = array(); + + $options = array('paging' => array( + 'Article' => array( + 'order' => 'desc', + 'sort' => 'title' + ) + ) + ); + $this->Paginator->options($options); + + $expected = array('Article' => array( + 'order' => 'desc', + 'sort' => 'title' + ) + ); + $this->assertEqual($expected, $this->Paginator->params['paging']); + + } + function testPagingLinks() { $this->Paginator->params['paging'] = array('Client' => array( 'page' => 1, 'current' => 3, 'count' => 13, 'prevPage' => false, 'nextPage' => true, 'pageCount' => 5, @@ -287,6 +316,32 @@ class PaginatorTest extends UnitTestCase { $expected = '1...33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42'; $this->assertEqual($result, $expected); + + $this->Paginator->params['paging'] = array( + 'Client' => array( + 'page' => 1, + 'current' => 10, + 'count' => 30, + 'prevPage' => false, + 'nextPage' => 2, + 'pageCount' => 3, + 'defaults' => array( + 'limit' => 3, + 'step' => 1, + 'order' => array('Client.name' => 'DESC'), + 'conditions' => array()), + 'options' => array( + 'page' => 1, + 'limit' => 3, + 'order' => array('Client.name' => 'DESC'), + 'conditions' => array() + ) + ) + ); + $options = array('modulus' => 10); + $result = $this->Paginator->numbers($options); + $expected = '1 | 2 | 3'; + $this->assertEqual($result, $expected); } @@ -334,6 +389,68 @@ class PaginatorTest extends UnitTestCase { } + function testCounter() { + $this->Paginator->params['paging'] = array( + 'Client' => array( + 'page' => 1, + 'current' => 3, + 'count' => 13, + 'prevPage' => false, + 'nextPage' => true, + 'pageCount' => 5, + 'defaults' => array( + 'limit' => 3, + 'step' => 1, + 'order' => array('Client.name' => 'DESC'), + 'conditions' => array() + ), + 'options' => array( + 'page' => 1, + 'limit' => 3, + 'order' => array('Client.name' => 'DESC'), + 'conditions' => array(), + 'separator' => 'of' + ), + ) + ); + $input = 'Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%'; + $result = $this->Paginator->counter($input); + $expected = 'Page 1 of 5, showing 3 records out of 13 total, starting on record 1, ending on 3'; + $this->assertEqual($result, $expected); + + $input = 'Page %page% of %pages%'; + $result = $this->Paginator->counter($input); + $expected = 'Page 1 of 5'; + $this->assertEqual($result, $expected); + + $result = $this->Paginator->counter(array('format' => $input)); + $expected = 'Page 1 of 5'; + $this->assertEqual($result, $expected); + + $result = $this->Paginator->counter(array('format' => 'pages')); + $expected = '1 of 5'; + $this->assertEqual($result, $expected); + + $result = $this->Paginator->counter(array('format' => 'range')); + $expected = '1 - 3 of 13'; + $this->assertEqual($result, $expected); + + } + + function testHasPage() { + $result = $this->Paginator->hasPage('Article', 15); + $this->assertFalse($result); + + $result = $this->Paginator->hasPage('UndefinedModel', 2); + $this->assertFalse($result); + + $result = $this->Paginator->hasPage('Article', 2); + $this->assertTrue($result); + + $result = $this->Paginator->hasPage(2); + $this->assertTrue($result); + } + function tearDown() { unset($this->Paginator); }