mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Refactoring paginator.test.php to use assertTags() where it makes sense.
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8240 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
56bee6e1fc
commit
f9ff43b352
1 changed files with 341 additions and 127 deletions
|
@ -116,9 +116,11 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
$this->assertEqual($result, $expected);
|
||||
|
||||
$this->Paginator->params['paging']['Article']['prevPage'] = false;
|
||||
$result = $this->Paginator->prev('prev', array('update'=> 'theList', 'indicator'=> 'loading', 'url'=> array('controller' => 'posts')), null, array('class' => 'disabled', 'tag' => 'span'));
|
||||
$expected = '<span class="disabled">prev</span>';
|
||||
$this->assertEqual($result, $expected);
|
||||
$result = $this->Paginator->prev('prev', array('update' => 'theList', 'indicator' => 'loading', 'url' => array('controller' => 'posts')), null, array('class' => 'disabled', 'tag' => 'span'));
|
||||
$expected = array(
|
||||
'span' => array('class' => 'disabled'), 'prev', '/span'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
}
|
||||
/**
|
||||
* testSortLinks method
|
||||
|
@ -135,31 +137,56 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
));
|
||||
$this->Paginator->options(array('url' => array('param')));
|
||||
$result = $this->Paginator->sort('title');
|
||||
$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:asc">Title<\/a>$/', $result);
|
||||
$expected = array(
|
||||
'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:title/direction:asc'),
|
||||
'Title',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Paginator->sort('date');
|
||||
$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:date\/direction:desc">Date<\/a>$/', $result);
|
||||
$expected = array(
|
||||
'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:date/direction:desc'),
|
||||
'Date',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Paginator->numbers(array('modulus'=> '2', 'url'=> array('controller'=>'projects', 'action'=>'sort'),'update'=>'list'));
|
||||
$this->assertPattern('/\/projects\/sort\/page:2/', $result);
|
||||
$this->assertPattern('/<script type="text\/javascript">\s*' . str_replace('/', '\\/', preg_quote('//<![CDATA[')) . '\s*Event.observe/', $result);
|
||||
|
||||
$result = $this->Paginator->sort('TestTitle', 'title');
|
||||
$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:asc">TestTitle<\/a>$/', $result);
|
||||
$expected = array(
|
||||
'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:title/direction:asc'),
|
||||
'TestTitle',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Paginator->sort(array('asc' => 'ascending', 'desc' => 'descending'), 'title');
|
||||
$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:asc">ascending<\/a>$/', $result);
|
||||
$expected = array(
|
||||
'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:title/direction:asc'),
|
||||
'ascending',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$this->Paginator->params['paging']['Article']['options']['sort'] = 'title';
|
||||
$result = $this->Paginator->sort(array('asc' => 'ascending', 'desc' => 'descending'), 'title');
|
||||
$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc">descending<\/a>$/', $result);
|
||||
|
||||
$expected = array(
|
||||
'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:title/direction:desc'),
|
||||
'descending',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
|
||||
$this->Paginator->params['paging']['Article']['options']['sort'] = null;
|
||||
$result = $this->Paginator->sort('title');
|
||||
$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:asc">Title<\/a>$/', $result);
|
||||
|
||||
|
||||
|
||||
|
||||
$this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
|
||||
$this->Paginator->params['paging']['Article']['options']['sort'] = null;
|
||||
$result = $this->Paginator->sort('title');
|
||||
|
@ -181,16 +208,30 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
|
||||
$this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
|
||||
$result = $this->Paginator->sort('Title','Article.title');
|
||||
$this->assertPattern('/\/accounts\/index\/page:1\/sort:Article.title\/direction:asc">Title<\/a>$/', $result);
|
||||
$expected = array(
|
||||
'a' => array('href' => '/officespace/accounts/index/page:1/sort:Article.title/direction:asc'),
|
||||
'Title',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
|
||||
$result = $this->Paginator->sort('Title','Article.title');
|
||||
$this->assertPattern('/\/accounts\/index\/page:1\/sort:Article.title\/direction:desc">Title<\/a>$/', $result);
|
||||
$expected = array(
|
||||
'a' => array('href' => '/officespace/accounts/index/page:1/sort:Article.title/direction:desc'),
|
||||
'Title',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$this->Paginator->params['paging']['Article']['options']['order'] = array('Account.title' => 'asc');
|
||||
$result = $this->Paginator->sort('title');
|
||||
$this->assertPattern('/\/accounts\/index\/page:1\/sort:title\/direction:asc">Title<\/a>$/', $result);
|
||||
|
||||
$expected = array(
|
||||
'a' => array('href' => '/officespace/accounts/index/page:1/sort:title/direction:asc'),
|
||||
'Title',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
}
|
||||
/**
|
||||
* testSortKey method
|
||||
|
@ -199,7 +240,6 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testSortKey() {
|
||||
|
||||
$result = $this->Paginator->sortKey(null, array(
|
||||
'order' => array('Article.title' => 'desc'
|
||||
)));
|
||||
|
@ -211,69 +251,69 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testSortDir() {
|
||||
$result = $this->Paginator->sortDir();
|
||||
$expected = 'asc';
|
||||
function testSortDir() {
|
||||
$result = $this->Paginator->sortDir();
|
||||
$expected = 'asc';
|
||||
|
||||
$this->assertEqual($result, $expected);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
|
||||
$result = $this->Paginator->sortDir();
|
||||
$expected = 'desc';
|
||||
$result = $this->Paginator->sortDir();
|
||||
$expected = 'desc';
|
||||
|
||||
$this->assertEqual($result, $expected);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
unset($this->Paginator->params['paging']['Article']['options']);
|
||||
unset($this->Paginator->params['paging']['Article']['options']);
|
||||
$this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
|
||||
$result = $this->Paginator->sortDir();
|
||||
$expected = 'asc';
|
||||
$result = $this->Paginator->sortDir();
|
||||
$expected = 'asc';
|
||||
|
||||
$this->assertEqual($result, $expected);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
unset($this->Paginator->params['paging']['Article']['options']);
|
||||
unset($this->Paginator->params['paging']['Article']['options']);
|
||||
$this->Paginator->params['paging']['Article']['options']['order'] = array('title' => 'desc');
|
||||
$result = $this->Paginator->sortDir();
|
||||
$expected = 'desc';
|
||||
$result = $this->Paginator->sortDir();
|
||||
$expected = 'desc';
|
||||
|
||||
$this->assertEqual($result, $expected);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
unset($this->Paginator->params['paging']['Article']['options']);
|
||||
unset($this->Paginator->params['paging']['Article']['options']);
|
||||
$this->Paginator->params['paging']['Article']['options']['order'] = array('title' => 'asc');
|
||||
$result = $this->Paginator->sortDir();
|
||||
$expected = 'asc';
|
||||
$result = $this->Paginator->sortDir();
|
||||
$expected = 'asc';
|
||||
|
||||
$this->assertEqual($result, $expected);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
unset($this->Paginator->params['paging']['Article']['options']);
|
||||
unset($this->Paginator->params['paging']['Article']['options']);
|
||||
$this->Paginator->params['paging']['Article']['options']['direction'] = 'asc';
|
||||
$result = $this->Paginator->sortDir();
|
||||
$expected = 'asc';
|
||||
$result = $this->Paginator->sortDir();
|
||||
$expected = 'asc';
|
||||
|
||||
$this->assertEqual($result, $expected);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
unset($this->paginator->params['paging']['article']['options']);
|
||||
unset($this->paginator->params['paging']['article']['options']);
|
||||
$this->Paginator->params['paging']['Article']['options']['direction'] = 'desc';
|
||||
$result = $this->Paginator->sortDir();
|
||||
$expected = 'desc';
|
||||
$result = $this->Paginator->sortDir();
|
||||
$expected = 'desc';
|
||||
|
||||
$this->assertEqual($result, $expected);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
unset($this->Paginator->params['paging']['Article']['options']);
|
||||
$result = $this->Paginator->sortDir('Article', array('direction' => 'asc'));
|
||||
$expected = 'asc';
|
||||
unset($this->Paginator->params['paging']['Article']['options']);
|
||||
$result = $this->Paginator->sortDir('Article', array('direction' => 'asc'));
|
||||
$expected = 'asc';
|
||||
|
||||
$this->assertEqual($result, $expected);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->Paginator->sortDir('Article', array('direction' => 'desc'));
|
||||
$expected = 'desc';
|
||||
$result = $this->Paginator->sortDir('Article', array('direction' => 'desc'));
|
||||
$expected = 'desc';
|
||||
|
||||
$this->assertEqual($result, $expected);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->Paginator->sortDir('Article', array('direction' => 'asc'));
|
||||
$expected = 'asc';
|
||||
$result = $this->Paginator->sortDir('Article', array('direction' => 'asc'));
|
||||
$expected = 'asc';
|
||||
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
/**
|
||||
* testSortAdminLinks method
|
||||
*
|
||||
|
@ -291,8 +331,12 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
Router::parse('/admin/users');
|
||||
$this->Paginator->params['paging']['Article']['page'] = 1;
|
||||
$result = $this->Paginator->next('Next');
|
||||
$this->assertPattern('/^<a[^<>]+>Next<\/a>$/', $result);
|
||||
$this->assertPattern('/href="\/admin\/users\/index\/page:2"/', $result);
|
||||
$expected = array(
|
||||
'a' => array('href' => '/admin/users/index/page:2'),
|
||||
'Next',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
Router::reload();
|
||||
Router::setRequestInfo(array(
|
||||
|
@ -302,12 +346,21 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
Router::parse('/');
|
||||
$this->Paginator->options(array('url' => array('param')));
|
||||
$result = $this->Paginator->sort('title');
|
||||
$this->assertPattern('/\/admin\/test\/index\/param\/page:1\/sort:title\/direction:asc"\s*>Title<\/a>$/', $result);
|
||||
$expected = array(
|
||||
'a' => array('href' => '/admin/test/index/param/page:1/sort:title/direction:asc'),
|
||||
'Title',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$this->Paginator->options(array('url' => array('param')));
|
||||
$result = $this->Paginator->sort('Title', 'Article.title');
|
||||
$this->assertPattern('/\/admin\/test\/index\/param\/page:1\/sort:Article.title\/direction:asc"\s*>Title<\/a>$/', $result);
|
||||
|
||||
$expected = array(
|
||||
'a' => array('href' => '/admin/test/index/param/page:1/sort:Article.title/direction:asc'),
|
||||
'Title',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
}
|
||||
/**
|
||||
* testUrlGeneration method
|
||||
|
@ -317,8 +370,12 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
*/
|
||||
function testUrlGeneration() {
|
||||
$result = $this->Paginator->sort('controller');
|
||||
$this->assertPattern('/\/page:1\//', $result);
|
||||
$this->assertPattern('/\/sort:controller\//', $result);
|
||||
$expected = array(
|
||||
'a' => array('href' => '/index/page:1/sort:controller/direction:asc'),
|
||||
'Controller',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Paginator->url();
|
||||
$this->assertEqual($result, '/index/page:1');
|
||||
|
@ -362,16 +419,28 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->Paginator->sort('name', null, array('url' => $options));
|
||||
$expected = '<a href="/members/posts/index/page:2/sort:name/direction:asc">Name</a>';
|
||||
$this->assertEqual($result, $expected);
|
||||
$expected = array(
|
||||
'a' => array('href' => '/members/posts/index/page:2/sort:name/direction:asc'),
|
||||
'Name',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($result, $expected, true);
|
||||
|
||||
$result = $this->Paginator->next('next', array('url' => $options));
|
||||
$expected = '<a href="/members/posts/index/page:3">next</a>';
|
||||
$this->assertEqual($result, $expected);
|
||||
$expected = array(
|
||||
'a' => array('href' => '/members/posts/index/page:3'),
|
||||
'next',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Paginator->prev('prev', array('url' => $options));
|
||||
$expected = '<a href="/members/posts/index/page:1">prev</a>';
|
||||
$this->assertEqual($result, $expected);
|
||||
$expected = array(
|
||||
'a' => array('href' => '/members/posts/index/page:1'),
|
||||
'prev',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$options = array('members' => true, 'controller' => 'posts', 'order' => array('name' => 'desc'));
|
||||
$result = $this->Paginator->url($options);
|
||||
|
@ -443,28 +512,54 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
'options' => array('page' => 1, 'limit' => 3, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()))
|
||||
);
|
||||
$result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled'));
|
||||
$expected = '<div class="disabled"><< Previous</div>';
|
||||
$this->assertEqual($result, $expected);
|
||||
$expected = array(
|
||||
'div' => array('class' => 'disabled'),
|
||||
'<< Previous',
|
||||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled', 'tag' => 'span'));
|
||||
$expected = '<span class="disabled"><< Previous</span>';
|
||||
$this->assertEqual($result, $expected);
|
||||
$expected = array(
|
||||
'span' => array('class' => 'disabled'),
|
||||
'<< Previous',
|
||||
'/span'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$this->Paginator->params['paging']['Client']['page'] = 2;
|
||||
$this->Paginator->params['paging']['Client']['prevPage'] = true;
|
||||
$result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled'));
|
||||
$this->assertPattern('/^<a[^<>]+><< Previous<\/a>$/', $result);
|
||||
$this->assertPattern('/href="\/index\/page:1"/', $result);
|
||||
$expected = array(
|
||||
'a' => array('href' => '/index/page:1'),
|
||||
'<< Previous',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Paginator->next('Next');
|
||||
$this->assertPattern('/^<a[^<>]+>Next<\/a>$/', $result);
|
||||
$this->assertPattern('/href="\/index\/page:3"/', $result);
|
||||
$expected = array(
|
||||
'a' => array('href' => '/index/page:3'),
|
||||
'Next',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Paginator->prev('<< Previous', array('escape' => true));
|
||||
$this->assertPattern('/^<a[^<>]+><< Previous<\/a>$/', $result);
|
||||
$expected = array(
|
||||
'a' => array('href' => '/index/page:1'),
|
||||
'<< Previous',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Paginator->prev('<< Previous', array('escape' => false));
|
||||
$this->assertPattern('/^<a[^<>]+><< Previous<\/a>$/', $result);
|
||||
$expected = array(
|
||||
'a' => array('href' => '/index/page:1'),
|
||||
'preg:/<< Previous/',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$this->Paginator->params['paging'] = array('Client' => array(
|
||||
'page' => 1, 'current' => 1, 'count' => 13, 'prevPage' => false, 'nextPage' => true, 'pageCount' => 5,
|
||||
|
@ -473,13 +568,28 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
);
|
||||
|
||||
$result = $this->Paginator->prev('<< Previous', null, '<strong>Disabled</strong>');
|
||||
$this->assertPattern('/^<div><strong>Disabled<\/strong><\/div>$/', $result);
|
||||
$expected = array(
|
||||
'<div',
|
||||
'<strong>Disabled</strong>',
|
||||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Paginator->prev('<< Previous', null, '<strong>Disabled</strong>', array('escape' => true));
|
||||
$this->assertPattern('/^<div><strong>Disabled<\/strong><\/div>$/', $result);
|
||||
$expected = array(
|
||||
'<div',
|
||||
'<strong>Disabled</strong>',
|
||||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Paginator->prev('<< Previous', null, '<strong>Disabled</strong>', array('escape' => false));
|
||||
$this->assertPattern('/^<div><strong>Disabled<\/strong><\/div>$/', $result);
|
||||
$expected = array(
|
||||
'<div',
|
||||
'<strong', 'Disabled', '/strong',
|
||||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$this->Paginator->params['paging'] = array('Client' => array(
|
||||
'page' => 1, 'current' => 3, 'count' => 13, 'prevPage' => false, 'nextPage' => true, 'pageCount' => 5,
|
||||
|
@ -490,10 +600,20 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
$this->Paginator->params['paging']['Client']['page'] = 2;
|
||||
$this->Paginator->params['paging']['Client']['prevPage'] = true;
|
||||
$result = $this->Paginator->prev('<< Previous', null, null, array('class' => 'disabled'));
|
||||
$this->assertPattern('/\/sort:Client.name\/direction:DESC"/', $result);
|
||||
$expected = array(
|
||||
'a' => array('href' => '/index/page:1/limit:3/sort:Client.name/direction:DESC'),
|
||||
'<< Previous',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($result, $expected, true);
|
||||
|
||||
$result = $this->Paginator->next('Next');
|
||||
$this->assertPattern('/\/sort:Client.name\/direction:DESC"/', $result);
|
||||
$expected = array(
|
||||
'a' => array('href' => '/index/page:3/limit:3/sort:Client.name/direction:DESC'),
|
||||
'Next',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$this->Paginator->params['paging'] = array('Client' => array(
|
||||
'page' => 2, 'current' => 1, 'count' => 13, 'prevPage' => true, 'nextPage' => false, 'pageCount' => 2,
|
||||
|
@ -531,11 +651,16 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
)
|
||||
);
|
||||
$result = $this->Paginator->next('Next', array('model' => 'Client'));
|
||||
$this->assertPattern('/^<a[^<>]+>Next<\/a>$/', $result);
|
||||
$this->assertPattern('/href="\/index\/page:2"/', $result); // These is passed.
|
||||
$expected = array(
|
||||
'a' => array('href' => '/index/page:2'), 'Next', '/a'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Paginator->next('Next', array('model' => 'Server'), 'No Next', array('model' => 'Server'));
|
||||
$this->assertPattern('/^<div>No Next<\/div>$/', $result);
|
||||
$expected = array(
|
||||
'<div', 'No Next', '/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
}
|
||||
/**
|
||||
* testGenericLinks method
|
||||
|
@ -545,24 +670,30 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
*/
|
||||
function testGenericLinks() {
|
||||
$result = $this->Paginator->link('Sort by title on page 5', array('sort' => 'title', 'page' => 5, 'direction' => 'desc'));
|
||||
$this->assertPattern('/^<a href=".+"[^<>]*>Sort by title on page 5<\/a>$/', $result);
|
||||
$this->assertPattern('/\/page:5/', $result);
|
||||
$this->assertPattern('/\/sort:title/', $result);
|
||||
$this->assertPattern('/\/direction:desc/', $result);
|
||||
$expected = array(
|
||||
'a' => array('href' => '/index/page:5/sort:title/direction:desc'),
|
||||
'Sort by title on page 5',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$this->Paginator->params['paging']['Article']['options']['page'] = 2;
|
||||
$result = $this->Paginator->link('Sort by title', array('sort' => 'title', 'direction' => 'desc'));
|
||||
$this->assertPattern('/^<a href=".+"[^<>]*>Sort by title<\/a>$/', $result);
|
||||
$this->assertPattern('/\/page:2/', $result);
|
||||
$this->assertPattern('/\/sort:title/', $result);
|
||||
$this->assertPattern('/\/direction:desc/', $result);
|
||||
$expected = array(
|
||||
'a' => array('href' => '/index/page:2/sort:title/direction:desc'),
|
||||
'Sort by title',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$this->Paginator->params['paging']['Article']['options']['page'] = 4;
|
||||
$result = $this->Paginator->link('Sort by title on page 4', array('sort' => 'Article.title', 'direction' => 'desc'));
|
||||
$this->assertPattern('/^<a href=".+"[^<>]*>Sort by title on page 4<\/a>$/', $result);
|
||||
$this->assertPattern('/\/page:4/', $result);
|
||||
$this->assertPattern('/\/sort:Article.title/', $result);
|
||||
$this->assertPattern('/\/direction:desc/', $result);
|
||||
$expected = array(
|
||||
'a' => array('href' => '/index/page:4/sort:Article.title/direction:desc'),
|
||||
'Sort by title on page 4',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
}
|
||||
/**
|
||||
* Tests generation of generic links with preset options
|
||||
|
@ -736,7 +867,7 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
$result = $this->Paginator->numbers();
|
||||
$expected = '<span><a href="/index/page:1/sort:Client.name/direction:DESC">1</a></span> | <span class="current">2</span> | <span><a href="/index/page:3/sort:Client.name/direction:DESC">3</a></span> | <span><a href="/index/page:4/sort:Client.name/direction:DESC">4</a></span>';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
|
||||
$this->Paginator->params['paging'] = array('Client' => array(
|
||||
'page' => 4895, 'current' => 10, 'count' => 48962, 'prevPage' => 1, 'nextPage' => 1, 'pageCount' => 4897,
|
||||
'defaults' => array('limit' => 10),
|
||||
|
@ -758,7 +889,7 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
|
||||
$this->Paginator->params['paging'] = array('Client' => array(
|
||||
'page' => 3, 'current' => 10, 'count' => 48962, 'prevPage' => 1, 'nextPage' => 1, 'pageCount' => 4897,
|
||||
'defaults' => array('limit' => 10),
|
||||
|
@ -780,7 +911,7 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
|
||||
$result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2, 'separator' => ' - '));
|
||||
$expected = array(
|
||||
array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
|
||||
|
@ -821,28 +952,71 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
);
|
||||
|
||||
$result = $this->Paginator->first();
|
||||
$expected = '<span><a href="/index/page:1"><< first</a></span>';
|
||||
$this->assertEqual($result, $expected);
|
||||
$expected = array(
|
||||
'<span',
|
||||
'a' => array('href' => '/index/page:1'),
|
||||
'<< first',
|
||||
'/a',
|
||||
'/span'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Paginator->first('<<', array('tag' => 'li'));
|
||||
$expected = '<li><a href="/index/page:1"><<</a></li>';
|
||||
$this->assertEqual($result, $expected);
|
||||
$expected = array(
|
||||
'<li',
|
||||
'a' => array('href' => '/index/page:1'),
|
||||
'<<',
|
||||
'/a',
|
||||
'/li'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Paginator->last();
|
||||
$expected = '<span><a href="/index/page:15">last >></a></span>';
|
||||
$this->assertEqual($result, $expected);
|
||||
$expected = array(
|
||||
'<span',
|
||||
'a' => array('href' => '/index/page:15'),
|
||||
'last >>',
|
||||
'/a',
|
||||
'/span'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Paginator->last(1);
|
||||
$expected = '...<span><a href="/index/page:15">15</a></span>';
|
||||
$this->assertEqual($result, $expected);
|
||||
$expected = array(
|
||||
'...',
|
||||
'<span',
|
||||
'a' => array('href' => '/index/page:15'),
|
||||
'15',
|
||||
'/a',
|
||||
'/span'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Paginator->last(2);
|
||||
$expected = '...<span><a href="/index/page:14">14</a></span> | <span><a href="/index/page:15">15</a></span>';
|
||||
$this->assertEqual($result, $expected);
|
||||
$expected = array(
|
||||
'...',
|
||||
'<span',
|
||||
array('a' => array('href' => '/index/page:14')), '14', '/a',
|
||||
'/span',
|
||||
' | ',
|
||||
'<span',
|
||||
array('a' => array('href' => '/index/page:15')), '15', '/a',
|
||||
'/span',
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Paginator->last(2, array('tag' => 'li'));
|
||||
$expected = '...<li><a href="/index/page:14">14</a></li> | <li><a href="/index/page:15">15</a></li>';
|
||||
$this->assertEqual($result, $expected);
|
||||
$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->params['paging'] = array('Client' => array(
|
||||
'page' => 15, 'current' => 3, 'count' => 30, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 15,
|
||||
|
@ -860,20 +1034,42 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
);
|
||||
|
||||
$result = $this->Paginator->first();
|
||||
$expected = '<span><a href="/index/page:1/sort:Client.name/direction:DESC"><< first</a></span>';
|
||||
$this->assertEqual($result, $expected);
|
||||
$expected = array(
|
||||
'<span',
|
||||
array('a' => array('href' => '/index/page:1/sort:Client.name/direction:DESC')), '<< first', '/a',
|
||||
'/span',
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Paginator->last();
|
||||
$expected = '<span><a href="/index/page:15/sort:Client.name/direction:DESC">last >></a></span>';
|
||||
$this->assertEqual($result, $expected);
|
||||
$expected = array(
|
||||
'<span',
|
||||
array('a' => array('href' => '/index/page:15/sort:Client.name/direction:DESC')), 'last >>', '/a',
|
||||
'/span',
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Paginator->last(1);
|
||||
$expected = '...<span><a href="/index/page:15/sort:Client.name/direction:DESC">15</a></span>';
|
||||
$this->assertEqual($result, $expected);
|
||||
$expected = array(
|
||||
'...',
|
||||
'<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);
|
||||
$expected = '...<span><a href="/index/page:14/sort:Client.name/direction:DESC">14</a></span> | <span><a href="/index/page:15/sort:Client.name/direction:DESC">15</a></span>';
|
||||
$this->assertEqual($result, $expected);
|
||||
$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);
|
||||
}
|
||||
/**
|
||||
* testCounter method
|
||||
|
@ -926,7 +1122,6 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
$result = $this->Paginator->counter(array('format' => 'range'));
|
||||
$expected = '1 - 3 of 13';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
}
|
||||
/**
|
||||
* testHasPage method
|
||||
|
@ -964,23 +1159,37 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
));
|
||||
|
||||
$result = $this->Paginator->link('Page 3', array('page' => 3));
|
||||
$this->assertPattern('/["\']\/my_plugin\/magazines\/index\/page:3["\']/', $result);
|
||||
$expected = array(
|
||||
'a' => array('href' => '/my_plugin/magazines/index/page:3'), 'Page 3', '/a'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$this->Paginator->options(array('url' => array('action' => 'another_index')));
|
||||
$result = $this->Paginator->link('Page 3', array('page' => 3));
|
||||
$this->assertPattern('/["\']\/my_plugin\/magazines\/another_index\/page:3["\']/', $result);
|
||||
$expected = array(
|
||||
'a' => array('href' => '/my_plugin/magazines/another_index/page:3'), 'Page 3', '/a'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$this->Paginator->options(array('url' => array('controller' => 'issues')));
|
||||
$result = $this->Paginator->link('Page 3', array('page' => 3));
|
||||
$this->assertPattern('/["\']\/my_plugin\/issues\/index\/page:3["\']/', $result);
|
||||
$expected = array(
|
||||
'a' => array('href' => '/my_plugin/issues/index/page:3'), 'Page 3', '/a'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$this->Paginator->options(array('url' => array('plugin' => null)));
|
||||
$result = $this->Paginator->link('Page 3', array('page' => 3));
|
||||
$this->assertPattern('/["\']\/magazines\/index\/page:3["\']/', $result);
|
||||
$expected = array(
|
||||
'a' => array('/magazines/index/page:3'), 'Page 3', '/a'
|
||||
);
|
||||
|
||||
$this->Paginator->options(array('url' => array('plugin' => null, 'controller' => 'issues')));
|
||||
$result = $this->Paginator->link('Page 3', array('page' => 3));
|
||||
$this->assertPattern('/["\']\/issues\/index\/page:3["\']/', $result);
|
||||
$expected = array(
|
||||
'a' => array('href' => '/issues/index/page:3'), 'Page 3', '/a'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1008,7 +1217,12 @@ class PaginatorHelperTest extends CakeTestCase {
|
|||
$this->Paginator->options($test);
|
||||
|
||||
$result = $this->Paginator->next('Next');
|
||||
$this->assertPattern('/\/accounts\/index\/page:2\/sort:Article.title\/direction:asc">Next<\/a>$/', $result);
|
||||
$expected = array(
|
||||
'a' => array('href' => '/officespace/accounts/index/page:2/sort:Article.title/direction:asc'),
|
||||
'Next',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Add table
Reference in a new issue