Skip to content

Commit

Permalink
Reordered PaginatorHelper::sort() key and title to be more consistent.
Browse files Browse the repository at this point in the history
Fixes #1000
  • Loading branch information
jeremyharris authored and markstory committed Jan 2, 2011
1 parent 5a75d1d commit 733f4f3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
12 changes: 6 additions & 6 deletions cake/libs/view/helpers/paginator.php 100644 → 100755
Expand Up @@ -292,20 +292,20 @@ public function next($title = 'Next >>', $options = array(), $disabledTitle = nu
* - `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';
Expand Down
27 changes: 14 additions & 13 deletions cake/tests/cases/libs/view/helpers/paginator.test.php 100644 → 100755
Expand Up @@ -168,15 +168,15 @@ function testSortLinks() {
);
$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',
'/a'
);
$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',
Expand All @@ -185,7 +185,7 @@ function testSortLinks() {
$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',
Expand All @@ -205,29 +205,29 @@ function testSortLinks() {

$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);
}

Expand Down Expand Up @@ -293,15 +293,15 @@ function testSortLinksUsingDirectionOption(){
));
$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',
'/a'
);
$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',
Expand All @@ -325,16 +325,17 @@ function testSortLinksUsingDotNotation() {
));

$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',
'/a'
);
$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',
Expand Down Expand Up @@ -483,7 +484,7 @@ function testSortAdminLinks() {
$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',
Expand Down

0 comments on commit 733f4f3

Please sign in to comment.