From 733f4f395e4c31684ce9550f72fc8456e9a1186d Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Fri, 3 Sep 2010 16:41:26 -0500 Subject: [PATCH] Reordered PaginatorHelper::sort() key and title to be more consistent. Fixes #1000 --- cake/libs/view/helpers/paginator.php | 12 ++++----- .../libs/view/helpers/paginator.test.php | 27 ++++++++++--------- 2 files changed, 20 insertions(+), 19 deletions(-) mode change 100644 => 100755 cake/libs/view/helpers/paginator.php mode change 100644 => 100755 cake/tests/cases/libs/view/helpers/paginator.test.php diff --git a/cake/libs/view/helpers/paginator.php b/cake/libs/view/helpers/paginator.php old mode 100644 new mode 100755 index 8fe9e40ec..e9d4c5565 --- a/cake/libs/view/helpers/paginator.php +++ b/cake/libs/view/helpers/paginator.php @@ -292,20 +292,20 @@ class PaginatorHelper extends AppHelper { * - `escape` Whether you want the contents html entity encoded, defaults to true * - `model` The model to use, defaults to PaginatorHelper::defaultModel() * - * @param string $title Title for the link. - * @param string $key The name of the key that the recordset should be sorted. If $key is null - * $title will be used for the key, and a title will be generated by inflection. + * @param string $key The name of the key that the recordset should be sorted. + * @param string $title Title for the link. If $title is null $key will be used + * for the title and will be generated by inflection. * @param array $options Options for sorting link. See above for list of keys. * @return string A link sorting default by 'asc'. If the resultset is sorted 'asc' by the specified * key the returned link will sort by 'desc'. */ - public function sort($title, $key = null, $options = array()) { + public function sort($key, $title = null, $options = array()) { $options = array_merge(array('url' => array(), 'model' => null), $options); $url = $options['url']; unset($options['url']); - if (empty($key)) { - $key = $title; + if (empty($title)) { + $title = $key; $title = __(Inflector::humanize(preg_replace('/_id$/', '', $title))); } $dir = isset($options['direction']) ? $options['direction'] : 'asc'; diff --git a/cake/tests/cases/libs/view/helpers/paginator.test.php b/cake/tests/cases/libs/view/helpers/paginator.test.php old mode 100644 new mode 100755 index ce4497536..d3115cc98 --- a/cake/tests/cases/libs/view/helpers/paginator.test.php +++ b/cake/tests/cases/libs/view/helpers/paginator.test.php @@ -168,7 +168,7 @@ class PaginatorHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); - $result = $this->Paginator->sort('TestTitle', 'title'); + $result = $this->Paginator->sort('title', 'TestTitle'); $expected = array( 'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:title/direction:asc'), 'TestTitle', @@ -176,7 +176,7 @@ class PaginatorHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); - $result = $this->Paginator->sort(array('asc' => 'ascending', 'desc' => 'descending'), 'title'); + $result = $this->Paginator->sort('title', array('asc' => 'ascending', 'desc' => 'descending')); $expected = array( 'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:title/direction:asc'), 'ascending', @@ -185,7 +185,7 @@ class PaginatorHelperTest extends CakeTestCase { $this->assertTags($result, $expected); $this->Paginator->request->params['paging']['Article']['options']['sort'] = 'title'; - $result = $this->Paginator->sort(array('asc' => 'ascending', 'desc' => 'descending'), 'title'); + $result = $this->Paginator->sort('title', array('asc' => 'ascending', 'desc' => 'descending')); $expected = array( 'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:title/direction:desc', 'class' => 'asc'), 'descending', @@ -205,29 +205,29 @@ class PaginatorHelperTest extends CakeTestCase { $this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc'); $this->Paginator->request->params['paging']['Article']['options']['sort'] = null; - $result = $this->Paginator->sort('Title', 'title', array('direction' => 'desc')); + $result = $this->Paginator->sort('title', 'Title', array('direction' => 'desc')); $this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:asc" class="desc">Title<\/a>$/', $result); $this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc'); $this->Paginator->request->params['paging']['Article']['options']['sort'] = null; - $result = $this->Paginator->sort('Title', 'title', array('direction' => 'asc')); + $result = $this->Paginator->sort('title', 'Title', array('direction' => 'asc')); $this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:asc" class="desc">Title<\/a>$/', $result); $this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc'); $this->Paginator->request->params['paging']['Article']['options']['sort'] = null; - $result = $this->Paginator->sort('Title', 'title', array('direction' => 'asc')); + $result = $this->Paginator->sort('title', 'Title', array('direction' => 'asc')); $this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc" class="asc">Title<\/a>$/', $result); $this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc'); $this->Paginator->request->params['paging']['Article']['options']['sort'] = null; - $result = $this->Paginator->sort('Title', 'title', array('direction' => 'desc')); + $result = $this->Paginator->sort('title', 'Title', array('direction' => 'desc')); $this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc" class="asc">Title<\/a>$/', $result); $this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc'); $this->Paginator->request->params['paging']['Article']['options']['sort'] = null; - $result = $this->Paginator->sort('Title', 'title', array('direction' => 'desc', 'class' => 'foo')); + $result = $this->Paginator->sort('title', 'Title', array('direction' => 'desc', 'class' => 'foo')); $this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc" class="foo asc">Title<\/a>$/', $result); } @@ -293,7 +293,7 @@ class PaginatorHelperTest extends CakeTestCase { )); $this->Paginator->options(array('url' => array('param'))); - $result = $this->Paginator->sort('TestTitle', 'title', array('direction' => 'desc')); + $result = $this->Paginator->sort('title', 'TestTitle', array('direction' => 'desc')); $expected = array( 'a' => array('href' => '/accounts/index/param/page:1/sort:title/direction:desc'), 'TestTitle', @@ -301,7 +301,7 @@ class PaginatorHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); - $result = $this->Paginator->sort(array('asc' => 'ascending', 'desc' => 'descending'), 'title', array('direction' => 'desc')); + $result = $this->Paginator->sort('title', array('asc' => 'ascending', 'desc' => 'descending'), array('direction' => 'desc')); $expected = array( 'a' => array('href' => '/accounts/index/param/page:1/sort:title/direction:desc'), 'descending', @@ -325,7 +325,7 @@ class PaginatorHelperTest extends CakeTestCase { )); $this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc'); - $result = $this->Paginator->sort('Title','Article.title'); + $result = $this->Paginator->sort('Article.title', 'Title'); $expected = array( 'a' => array('href' => '/officespace/accounts/index/page:1/sort:Article.title/direction:asc', 'class' => 'desc'), 'Title', @@ -333,8 +333,9 @@ class PaginatorHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); + $this->Paginator->request->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc'); - $result = $this->Paginator->sort('Title','Article.title'); + $result = $this->Paginator->sort('Article.title', 'Title'); $expected = array( 'a' => array('href' => '/officespace/accounts/index/page:1/sort:Article.title/direction:desc', 'class' => 'asc'), 'Title', @@ -483,7 +484,7 @@ class PaginatorHelperTest extends CakeTestCase { $this->assertTags($result, $expected); $this->Paginator->options(array('url' => array('param'))); - $result = $this->Paginator->sort('Title', 'Article.title'); + $result = $this->Paginator->sort('Article.title', 'Title'); $expected = array( 'a' => array('href' => '/admin/test/index/param/page:1/sort:Article.title/direction:asc'), 'Title',