Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing a problem with setting Paginator::sort() defaults directon to …

…desc
  • Loading branch information...
commit 67cea6d21ce595a53355e2260122ccc7d04cb273 1 parent 925fda7
@burzum burzum authored
View
4 cake/libs/view/helpers/paginator.php
@@ -302,9 +302,7 @@ function sort($title, $key = null, $options = array()) {
$isSorted = ($sortKey === $key || $sortKey === $this->defaultModel() . '.' . $key);
if ($isSorted) {
- if ($this->sortDir($options['model']) === 'asc') {
- $dir = 'desc';
- }
+ $dir = $this->sortDir($options['model']) === 'asc' ? 'desc' : 'asc';
$class = $dir === 'asc' ? 'desc' : 'asc';
if (!empty($options['class'])) {
$options['class'] .= $class;
View
23 cake/tests/cases/libs/view/helpers/paginator.test.php
@@ -195,6 +195,29 @@ function testSortLinks() {
$this->Paginator->params['paging']['Article']['options']['sort'] = null;
$result = $this->Paginator->sort('title');
$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc" class="asc">Title<\/a>$/', $result);
+
+ $this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
+ $this->Paginator->params['paging']['Article']['options']['sort'] = null;
+ $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->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
+ $this->Paginator->params['paging']['Article']['options']['sort'] = null;
+ $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->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
+ $this->Paginator->params['paging']['Article']['options']['sort'] = null;
+ $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->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
+ $this->Paginator->params['paging']['Article']['options']['sort'] = null;
+ $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);
}
Please sign in to comment.
Something went wrong with that request. Please try again.