Skip to content

Commit

Permalink
Moving some tests around so its easier to figure out what's being tes…
Browse files Browse the repository at this point in the history
…ted.

Adding a querystring test.
  • Loading branch information
markstory committed Dec 20, 2010
1 parent e5588f7 commit d7e4116
Showing 1 changed file with 53 additions and 57 deletions.
110 changes: 53 additions & 57 deletions cake/tests/cases/libs/view/helpers/paginator.test.php
Expand Up @@ -47,6 +47,7 @@ function setUp() {
$this->Paginator->request->addParams(array(
'paging' => array(
'Article' => array(
'page' => 2,
'current' => 9,
'count' => 62,
'prevPage' => false,
Expand Down Expand Up @@ -1763,6 +1764,51 @@ function testNumbers() {
$this->assertTags($result, $expected);
}

/**
* test first() and last() with tag options
*
* @return void
*/
function testFirstAndLastTag() {
$result = $this->Paginator->first('<<', array('tag' => 'li'));
$expected = array(
'<li',
'a' => array('href' => '/index/page:1'),
'&lt;&lt;',
'/a',
'/li'
);
$this->assertTags($result, $expected);

$result = $this->Paginator->last(2, array('tag' => 'li'));

$expected = array(
'...',
'<li',
array('a' => array('href' => '/index/page:6')), '6', '/a',
'/li',
' | ',
'<li',
array('a' => array('href' => '/index/page:7')), '7', '/a',
'/li',
);
$this->assertTags($result, $expected);
}

/**
* test that on the last page you don't get a link ot the last page.
*
* @return void
*/
function testLastNoOutput() {
$this->Paginator->request->params['paging']['Article']['page'] = 15;
$this->Paginator->request->params['paging']['Article']['pageCount'] = 15;

$result = $this->Paginator->last();
$expected = '';
$this->assertEqual($result, $expected);
}

/**
* testFirstAndLast method
*
Expand All @@ -1787,20 +1833,7 @@ function testFirstAndLast() {
$expected = '';
$this->assertEqual($result, $expected);

$this->Paginator->request->params['paging'] = array(
'Client' => array(
'page' => 4,
'current' => 3,
'count' => 30,
'prevPage' => false,
'nextPage' => 2,
'pageCount' => 15,
'options' => array(
'page' => 1,
),
'paramType' => 'named'
)
);
$this->Paginator->request->params['paging']['Client']['page'] = 4;

$result = $this->Paginator->first();
$expected = array(
Expand All @@ -1812,16 +1845,6 @@ function testFirstAndLast() {
);
$this->assertTags($result, $expected);

$result = $this->Paginator->first('<<', array('tag' => 'li'));
$expected = array(
'<li',
'a' => array('href' => '/index/page:1'),
'&lt;&lt;',
'/a',
'/li'
);
$this->assertTags($result, $expected);

$result = $this->Paginator->last();
$expected = array(
'<span',
Expand Down Expand Up @@ -1856,37 +1879,6 @@ function testFirstAndLast() {
);
$this->assertTags($result, $expected);

$result = $this->Paginator->last(2, array('tag' => 'li'));
$expected = array(
'...',
'<li',
array('a' => array('href' => '/index/page:14')), '14', '/a',
'/li',
' | ',
'<li',
array('a' => array('href' => '/index/page:15')), '15', '/a',
'/li',
);
$this->assertTags($result, $expected);

$this->Paginator->request->params['paging'] = array(
'Client' => array(
'page' => 15,
'current' => 3,
'count' => 30,
'prevPage' => false,
'nextPage' => 2,
'pageCount' => 15,
'options' => array(
'page' => 1,
),
'paramType' => 'named'
)
);
$result = $this->Paginator->last();
$expected = '';
$this->assertEqual($result, $expected);

$this->Paginator->request->params['paging'] = array(
'Client' => array(
'page' => 4,
Expand Down Expand Up @@ -2192,15 +2184,19 @@ function testMockAjaxProviderClassInjection() {
}

/**
* test that querystring links can be generated.
* test that querystring urls can be generated.
*
* @return void
*/
function testQuerystringLinkGeneration() {
function testQuerystringUrlGeneration() {
$this->Paginator->request->params['paging']['Article']['paramType'] = 'querystring';
$result = $this->Paginator->url(array('page' => '4'));
$expected = '/?page=4';
$this->assertEquals($expected, $result);

$result = $this->Paginator->url(array('page' => '4', 'limit' => 10, 'something' => 'else'));
$expected = '/index/something:else?page=4&amp;limit=10';
$this->assertEquals($expected, $result);
}

}

0 comments on commit d7e4116

Please sign in to comment.