Skip to content

Commit

Permalink
Split mega test up.
Browse files Browse the repository at this point in the history
The previous testNumbers() method was a behemoth. Split out the
scenarios for first/last a bit.

Refs #7902
  • Loading branch information
markstory committed Dec 27, 2015
1 parent 7d052bd commit 430612f
Showing 1 changed file with 141 additions and 133 deletions.
274 changes: 141 additions & 133 deletions lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php
Expand Up @@ -1729,6 +1729,147 @@ public function testNumbers() {
);
$this->assertTags($result, $expected);

$this->Paginator->request->params['paging'] = array(
'Client' => array(
'page' => 1,
'current' => 10,
'count' => 30,
'prevPage' => false,
'nextPage' => 2,
'pageCount' => 3,
'options' => array(
'page' => 1,
),
'paramType' => 'named'
)
);
$options = array('modulus' => 10);
$result = $this->Paginator->numbers($options);
$expected = array(
array('span' => array('class' => 'current')), '1', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
);
$this->assertTags($result, $expected);

$result = $this->Paginator->numbers(array('modulus' => 3, 'currentTag' => 'span', 'tag' => 'li'));
$expected = array(
array('li' => array('class' => 'current')), array('span' => array()), '1', '/span', '/li',
' | ',
array('li' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/li',
' | ',
array('li' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/li',
);
$this->assertTags($result, $expected);

$this->Paginator->request->params['paging'] = array(
'Client' => array(
'page' => 2,
'current' => 10,
'count' => 31,
'prevPage' => true,
'nextPage' => true,
'pageCount' => 4,
'options' => array(
'page' => 1,
'order' => array('Client.name' => 'DESC'),
),
'paramType' => 'named'
)
);
$result = $this->Paginator->numbers(array('class' => 'page-link'));
$expected = array(
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/sort:Client.name/direction:DESC')), '1', '/a', '/span',
' | ',
array('span' => array('class' => 'current page-link')), '2', '/span',
' | ',
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:3/sort:Client.name/direction:DESC')), '3', '/a', '/span',
' | ',
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:4/sort:Client.name/direction:DESC')), '4', '/a', '/span',
);
$this->assertTags($result, $expected);

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

$request = new CakeRequest();
$request->addParams(array(
'controller' => 'clients', 'action' => 'index', 'plugin' => null, 'page' => 2
));
$request->base = '';
$request->here = '/clients/index/page:2';
$request->webroot = '/';

Router::setRequestInfo($request);

$result = $this->Paginator->numbers();
$expected = array(
array('span' => array()), array('a' => array('href' => '/clients')), '1', '/a', '/span',
' | ',
array('span' => array('class' => 'current')), '2', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/clients/index/page:3')), '3', '/a', '/span',

);
$this->assertTags($result, $expected);

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

$request = new CakeRequest();
$request->addParams(array(
'controller' => 'clients', 'action' => 'index', 'plugin' => null
));
$request->base = '';
$request->here = '/clients?page=2';
$request->webroot = '/';

Router::setRequestInfo($request);

$result = $this->Paginator->numbers();
$expected = array(
array('span' => array()), array('a' => array('href' => '/clients')), '1', '/a', '/span',
' | ',
array('span' => array('class' => 'current')), '2', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/clients?page=3')), '3', '/a', '/span',

);
$this->assertTags($result, $expected);
}

/**
* Test that numbers() works with first and last options.
*
* @return void
*/
public function testNumbersFirstAndLast() {
$this->Paginator->request->params['paging'] = array(
'Client' => array(
'page' => 10,
Expand Down Expand Up @@ -1852,68 +1993,6 @@ public function testNumbers() {
);
$this->assertTags($result, $expected);

$this->Paginator->request->params['paging'] = array(
'Client' => array(
'page' => 1,
'current' => 10,
'count' => 30,
'prevPage' => false,
'nextPage' => 2,
'pageCount' => 3,
'options' => array(
'page' => 1,
),
'paramType' => 'named'
)
);
$options = array('modulus' => 10);
$result = $this->Paginator->numbers($options);
$expected = array(
array('span' => array('class' => 'current')), '1', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
);
$this->assertTags($result, $expected);

$result = $this->Paginator->numbers(array('modulus' => 3, 'currentTag' => 'span', 'tag' => 'li'));
$expected = array(
array('li' => array('class' => 'current')), array('span' => array()), '1', '/span', '/li',
' | ',
array('li' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/li',
' | ',
array('li' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/li',
);
$this->assertTags($result, $expected);

$this->Paginator->request->params['paging'] = array(
'Client' => array(
'page' => 2,
'current' => 10,
'count' => 31,
'prevPage' => true,
'nextPage' => true,
'pageCount' => 4,
'options' => array(
'page' => 1,
'order' => array('Client.name' => 'DESC'),
),
'paramType' => 'named'
)
);
$result = $this->Paginator->numbers(array('class' => 'page-link'));
$expected = array(
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/sort:Client.name/direction:DESC')), '1', '/a', '/span',
' | ',
array('span' => array('class' => 'current page-link')), '2', '/span',
' | ',
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:3/sort:Client.name/direction:DESC')), '3', '/a', '/span',
' | ',
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:4/sort:Client.name/direction:DESC')), '4', '/a', '/span',
);
$this->assertTags($result, $expected);

$this->Paginator->request->params['paging'] = array(
'Client' => array(
'page' => 4895,
Expand Down Expand Up @@ -2132,77 +2211,6 @@ public function testNumbers() {
);
$this->assertTags($result, $expected);

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

$request = new CakeRequest();
$request->addParams(array(
'controller' => 'clients', 'action' => 'index', 'plugin' => null, 'page' => 2
));
$request->base = '';
$request->here = '/clients/index/page:2';
$request->webroot = '/';

Router::setRequestInfo($request);

$result = $this->Paginator->numbers();
$expected = array(
array('span' => array()), array('a' => array('href' => '/clients')), '1', '/a', '/span',
' | ',
array('span' => array('class' => 'current')), '2', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/clients/index/page:3')), '3', '/a', '/span',

);
$this->assertTags($result, $expected);

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

$request = new CakeRequest();
$request->addParams(array(
'controller' => 'clients', 'action' => 'index', 'plugin' => null
));
$request->base = '';
$request->here = '/clients?page=2';
$request->webroot = '/';

Router::setRequestInfo($request);

$result = $this->Paginator->numbers();
$expected = array(
array('span' => array()), array('a' => array('href' => '/clients')), '1', '/a', '/span',
' | ',
array('span' => array('class' => 'current')), '2', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/clients?page=3')), '3', '/a', '/span',

);
$this->assertTags($result, $expected);
}

/**
Expand Down

0 comments on commit 430612f

Please sign in to comment.