From b0b9c1e4bd19e05345748474d76dfc6aa158ccd6 Mon Sep 17 00:00:00 2001 From: nate Date: Thu, 24 Jul 2008 04:04:21 +0000 Subject: [PATCH] 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 --- cake/libs/view/helpers/paginator.php | 4 +-- .../libs/view/helpers/paginator.test.php | 32 +++++++++++++++---- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/cake/libs/view/helpers/paginator.php b/cake/libs/view/helpers/paginator.php index efcc66ccd..dd573c8f6 100644 --- a/cake/libs/view/helpers/paginator.php +++ b/cake/libs/view/helpers/paginator.php @@ -311,7 +311,7 @@ class PaginatorHelper extends AppHelper { $title = $disabledTitle; } $options = array_merge($_defaults, (array)$disabledOptions); - } elseif (!$this->{$check}()) { + } elseif (!$this->{$check}($options['model'])) { return null; } @@ -321,7 +321,7 @@ class PaginatorHelper extends AppHelper { } $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))); } else { return $this->Html->tag($tag, $title, $options, $escape); diff --git a/cake/tests/cases/libs/view/helpers/paginator.test.php b/cake/tests/cases/libs/view/helpers/paginator.test.php index f7ddabc43..9528ea897 100644 --- a/cake/tests/cases/libs/view/helpers/paginator.test.php +++ b/cake/tests/cases/libs/view/helpers/paginator.test.php @@ -239,28 +239,46 @@ class PaginatorTest extends CakeTestCase { * @return void */ function testUrlGenerationWithPrefixes() { - $memberPrefixes = array('prefix' => 'members', 'members' => true); + $memberPrefixes = array('prefix' => 'members', 'members' => true); Router::connect('/members/:controller/:action/*', $memberPrefixes); - Router::parse('/'); - + Router::parse('/'); + Router::setRequestInfo( array( array('controller' => 'posts', 'action' => 'index', 'form' => array(), 'url' => array(), 'plugin' => null), array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => 'posts/index', 'webroot' => '/') - )); - + )); + $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); - + $result = $this->Paginator->url($options); $expected = '/members/posts/index/page:2'; $this->assertEqual($result, $expected); + $result = $this->Paginator->sort('name', null, array('url' => $options)); + $expected = 'Name'; + $this->assertEqual($result, $expected); + + $result = $this->Paginator->next('next', array('url' => $options)); + $expected = 'next'; + $this->assertEqual($result, $expected); + + $result = $this->Paginator->prev('prev', array('url' => $options)); + $expected = 'prev'; + $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')); $result = $this->Paginator->url($options); $expected = '/posts/index/page:2/sort:Article.name/direction:desc'; $this->assertEqual($result, $expected); } - /** * testOptions method *