Fixing fencepost errors.

Splitting tests up into smaller groups.
This commit is contained in:
mark_story 2010-12-20 20:27:27 -05:00
parent abc6a28eca
commit 6f62c22cbc
2 changed files with 68 additions and 55 deletions

View file

@ -754,7 +754,7 @@ class PaginatorHelper extends AppHelper {
$out = ''; $out = '';
if (is_int($first) && $params['page'] > $first) { if (is_int($first) && $params['page'] >= $first) {
if ($after === null) { if ($after === null) {
$after = $ellipsis; $after = $ellipsis;
} }
@ -811,7 +811,7 @@ class PaginatorHelper extends AppHelper {
$out = ''; $out = '';
$lower = $params['pageCount'] - $last + 1; $lower = $params['pageCount'] - $last + 1;
if (is_int($last) && $params['page'] < $lower) { if (is_int($last) && $params['page'] <= $lower) {
if ($before === null) { if ($before === null) {
$before = $ellipsis; $before = $ellipsis;
} }

View file

@ -1810,31 +1810,45 @@ class PaginatorHelperTest extends CakeTestCase {
} }
/** /**
* testFirstAndLast method * test first() on the first page.
* *
* @access public
* @return void * @return void
*/ */
function testFirstAndLast() { function testFirstEmpty() {
$this->Paginator->request->params['paging'] = array( $this->Paginator->request->params['paging']['Article']['page'] = 1;
'Client' => array(
'page' => 1,
'current' => 3,
'count' => 30,
'prevPage' => false,
'nextPage' => 2,
'pageCount' => 15,
'options' => array(),
'paramType' => 'named'
)
);
$result = $this->Paginator->first(); $result = $this->Paginator->first();
$expected = ''; $expected = '';
$this->assertEqual($result, $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(
'<span',
array('a' => array('href' => FULL_BASE_URL . '/index/page:1/sort:Article.title/direction:DESC')),
'&lt;&lt; first',
'/a',
'/span',
);
$this->assertTags($result, $expected);
}
/**
* test first() on the fence-post
*
* @return void
*/
function testFirstBoundaries() {
$result = $this->Paginator->first(); $result = $this->Paginator->first();
$expected = array( $expected = array(
'<span', '<span',
@ -1845,10 +1859,30 @@ class PaginatorHelperTest extends CakeTestCase {
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
$result = $this->Paginator->first(2);
$expected = array(
'<span',
array('a' => array('href' => '/index/page:1')), '1', '/a',
'/span',
' | ',
'<span',
array('a' => 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(); $result = $this->Paginator->last();
$expected = array( $expected = array(
'<span', '<span',
'a' => array('href' => '/index/page:15'), 'a' => array('href' => '/index/page:7'),
'last &gt;&gt;', 'last &gt;&gt;',
'/a', '/a',
'/span' '/span'
@ -1859,26 +1893,35 @@ class PaginatorHelperTest extends CakeTestCase {
$expected = array( $expected = array(
'...', '...',
'<span', '<span',
'a' => array('href' => '/index/page:15'), 'a' => array('href' => '/index/page:7'),
'15', '7',
'/a', '/a',
'/span' '/span'
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
$this->Paginator->request->params['paging']['Article']['page'] = 6;
$result = $this->Paginator->last(2); $result = $this->Paginator->last(2);
$expected = array( $expected = array(
'...', '...',
'<span', '<span',
array('a' => array('href' => '/index/page:14')), '14', '/a', array('a' => array('href' => '/index/page:6')), '6', '/a',
'/span', '/span',
' | ', ' | ',
'<span', '<span',
array('a' => array('href' => '/index/page:15')), '15', '/a', array('a' => array('href' => '/index/page:7')), '7', '/a',
'/span', '/span',
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
}
/**
* undocumented function
*
* @return void
*/
function testLastOptions() {
$this->Paginator->request->params['paging'] = array( $this->Paginator->request->params['paging'] = array(
'Client' => array( 'Client' => array(
'page' => 4, 'page' => 4,
@ -1895,14 +1938,6 @@ class PaginatorHelperTest extends CakeTestCase {
) )
); );
$result = $this->Paginator->first();
$expected = array(
'<span',
array('a' => array('href' => '/index/page:1/sort:Client.name/direction:DESC')), '&lt;&lt; first', '/a',
'/span',
);
$this->assertTags($result, $expected);
$result = $this->Paginator->last(); $result = $this->Paginator->last();
$expected = array( $expected = array(
'<span', '<span',
@ -1910,7 +1945,7 @@ class PaginatorHelperTest extends CakeTestCase {
'/span', '/span',
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
$result = $this->Paginator->last(1); $result = $this->Paginator->last(1);
$expected = array( $expected = array(
'...', '...',
@ -1933,19 +1968,6 @@ class PaginatorHelperTest extends CakeTestCase {
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
$result = $this->Paginator->last(2, array('ellipsis' => '~~~'));
$expected = array(
'~~~',
'<span',
array('a' => array('href' => '/index/page:14/sort:Client.name/direction:DESC')), '14', '/a',
'/span',
' | ',
'<span',
array('a' => array('href' => '/index/page:15/sort:Client.name/direction:DESC')), '15', '/a',
'/span',
);
$this->assertTags($result, $expected);
$result = $this->Paginator->last(2, array('ellipsis' => '<span class="ellipsis">...</span>')); $result = $this->Paginator->last(2, array('ellipsis' => '<span class="ellipsis">...</span>'));
$expected = array( $expected = array(
array('span' => array('class' => 'ellipsis')), '...', '/span', array('span' => array('class' => 'ellipsis')), '...', '/span',
@ -1958,15 +1980,6 @@ class PaginatorHelperTest extends CakeTestCase {
'/span', '/span',
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
$this->Paginator->options(array('url' => array('full_base' => true)));
$result = $this->Paginator->first();
$expected = array(
'<span',
array('a' => array('href' => FULL_BASE_URL . '/index/page:1/sort:Client.name/direction:DESC')), '&lt;&lt; first', '/a',
'/span',
);
$this->assertTags($result, $expected);
} }
/** /**