Split mega test up.

The previous testNumbers() method was a behemoth. Split out the
scenarios for first/last a bit.

Refs #7902
This commit is contained in:
mark_story 2015-12-26 22:37:25 -05:00
parent 7d052bdbc1
commit 430612f1df

View file

@ -1729,6 +1729,147 @@ class PaginatorHelperTest extends CakeTestCase {
);
$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,
@ -1852,68 +1993,6 @@ class PaginatorHelperTest extends CakeTestCase {
);
$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,
@ -2132,77 +2211,6 @@ class PaginatorHelperTest extends CakeTestCase {
);
$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);
}
/**