Adding PaginatorHelper tests for additional custom URL settings

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7358 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2008-07-24 04:04:21 +00:00
parent cc098629a6
commit b0b9c1e4bd
2 changed files with 27 additions and 9 deletions

View file

@ -311,7 +311,7 @@ class PaginatorHelper extends AppHelper {
$title = $disabledTitle; $title = $disabledTitle;
} }
$options = array_merge($_defaults, (array)$disabledOptions); $options = array_merge($_defaults, (array)$disabledOptions);
} elseif (!$this->{$check}()) { } elseif (!$this->{$check}($options['model'])) {
return null; return null;
} }
@ -321,7 +321,7 @@ class PaginatorHelper extends AppHelper {
} }
$url = array_merge(array('page' => $paging['page'] + ($which == 'Prev' ? $step * -1 : $step)), $url); $url = array_merge(array('page' => $paging['page'] + ($which == 'Prev' ? $step * -1 : $step)), $url);
if ($this->{$check}()) { if ($this->{$check}($model)) {
return $this->link($title, $url, array_merge($options, array('escape' => $escape))); return $this->link($title, $url, array_merge($options, array('escape' => $escape)));
} else { } else {
return $this->Html->tag($tag, $title, $options, $escape); return $this->Html->tag($tag, $title, $options, $escape);

View file

@ -249,18 +249,36 @@ class PaginatorTest extends CakeTestCase {
)); ));
$this->Paginator->params['paging']['Article']['options']['page'] = 2; $this->Paginator->params['paging']['Article']['options']['page'] = 2;
$this->Paginator->params['paging']['Article']['page'] = 2;
$this->Paginator->params['paging']['Article']['prevPage'] = true;
$options = array('members' => true); $options = array('members' => true);
$result = $this->Paginator->url($options); $result = $this->Paginator->url($options);
$expected = '/members/posts/index/page:2'; $expected = '/members/posts/index/page:2';
$this->assertEqual($result, $expected); $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);
$result = $this->Paginator->next('next', array('url' => $options));
$expected = '<a href="/members/posts/index/page:3">next</a>';
$this->assertEqual($result, $expected);
$result = $this->Paginator->prev('prev', array('url' => $options));
$expected = '<a href="/members/posts/index/page:1">prev</a>';
$this->assertEqual($result, $expected);
$options = array('members' => true, 'controller' => 'posts', 'order' => array('name' => 'desc'));
$result = $this->Paginator->url($options);
$expected = '/members/posts/index/page:2/sort:name/direction:desc';
$this->assertEqual($result, $expected);
$options = array('controller' => 'posts', 'order' => array('Article.name' => 'desc')); $options = array('controller' => 'posts', 'order' => array('Article.name' => 'desc'));
$result = $this->Paginator->url($options); $result = $this->Paginator->url($options);
$expected = '/posts/index/page:2/sort:Article.name/direction:desc'; $expected = '/posts/index/page:2/sort:Article.name/direction:desc';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
} }
/** /**
* testOptions method * testOptions method
* *