diff --git a/cake/libs/view/helpers/paginator.php b/cake/libs/view/helpers/paginator.php index 45ffb488d..c4d34acc6 100644 --- a/cake/libs/view/helpers/paginator.php +++ b/cake/libs/view/helpers/paginator.php @@ -302,9 +302,7 @@ class PaginatorHelper extends AppHelper { $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; diff --git a/cake/tests/cases/libs/view/helpers/paginator.test.php b/cake/tests/cases/libs/view/helpers/paginator.test.php index 1749f9379..e41f65530 100644 --- a/cake/tests/cases/libs/view/helpers/paginator.test.php +++ b/cake/tests/cases/libs/view/helpers/paginator.test.php @@ -195,6 +195,29 @@ class PaginatorHelperTest extends CakeTestCase { $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); }