Skip to content

Commit

Permalink
Adding missing test scenarios in the paginator helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Jelle Henkens authored and markstory committed Sep 10, 2011
1 parent 608e5ee commit 653163c
Showing 1 changed file with 75 additions and 11 deletions.
86 changes: 75 additions & 11 deletions lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php
Expand Up @@ -359,6 +359,9 @@ public function testSortKey() {
)));
$this->assertEqual('Article.title', $result);

$result = $this->Paginator->sortKey('Article', array('order' => 'Article.title'));
$this->assertEqual($result, 'Article.title');

$result = $this->Paginator->sortKey('Article', array('sort' => 'Article.title'));
$this->assertEqual($result, 'Article.title');

Expand Down Expand Up @@ -1273,25 +1276,25 @@ public function testNumbers() {
)
);

$result = $this->Paginator->numbers(array('first' => 1));
$result = $this->Paginator->numbers(array('first' => 1, 'class' => 'page-link'));
$expected = array(
array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
' | ',
array('span' => array('class' => 'current')), '2', '/span',
array('span' => array('class' => 'current page-link')), '2', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span',
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
);
$this->assertTags($result, $expected);

Expand Down Expand Up @@ -2260,7 +2263,6 @@ public function testOptionsConvertKeys() {
$this->assertEquals($expected, $result);
}


/**
* test the current() method
*
Expand All @@ -2274,4 +2276,66 @@ public function testCurrent() {
$this->assertEquals(1, $result);
}

/**
* test the defaultModel() method
*
* @return void
*/
public function testNoDefaultModel() {
$this->Paginator->request = new CakeRequest(null, false);
$this->assertNull($this->Paginator->defaultModel());
}

/**
* test the numbers() method when there is only one page
*
* @return void
*/
public function testWithOnePage() {
$this->Paginator->request['paging'] = array(
'Article' => array(
'page' => 1,
'current' => 2,
'count' => 2,
'prevPage' => false,
'nextPage' => true,
'pageCount' => 1,
'options' => array(
'page' => 1,
),
'paramType' => 'named',
)
);
$this->assertFalse($this->Paginator->numbers());
$this->assertFalse($this->Paginator->first());
$this->assertFalse($this->Paginator->last());
}

/**
* test the numbers() method when there is only one page
*
* @return void
*/
public function testWithZeroPages() {
$this->Paginator->request['paging'] = array(
'Article' => array(
'page' => 0,
'current' => 0,
'count' => 0,
'prevPage' => false,
'nextPage' => false,
'pageCount' => 0,
'limit' => 10,
'options' => array(
'page' => 0,
'conditions' => array()
),
'paramType' => 'named',
)
);

$result = $this->Paginator->counter(array('format' => 'pages'));
$expected = '0 of 1';
$this->assertEqual($expected, $result);
}
}

0 comments on commit 653163c

Please sign in to comment.