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

This commit is contained in:
burzum 2009-11-17 02:11:23 +01:00
parent 925fda7ba6
commit 67cea6d21c
2 changed files with 24 additions and 3 deletions

View file

@ -302,9 +302,7 @@ class PaginatorHelper extends AppHelper {
$isSorted = ($sortKey === $key || $sortKey === $this->defaultModel() . '.' . $key); $isSorted = ($sortKey === $key || $sortKey === $this->defaultModel() . '.' . $key);
if ($isSorted) { if ($isSorted) {
if ($this->sortDir($options['model']) === 'asc') { $dir = $this->sortDir($options['model']) === 'asc' ? 'desc' : 'asc';
$dir = 'desc';
}
$class = $dir === 'asc' ? 'desc' : 'asc'; $class = $dir === 'asc' ? 'desc' : 'asc';
if (!empty($options['class'])) { if (!empty($options['class'])) {
$options['class'] .= $class; $options['class'] .= $class;

View file

@ -195,6 +195,29 @@ class PaginatorHelperTest extends CakeTestCase {
$this->Paginator->params['paging']['Article']['options']['sort'] = null; $this->Paginator->params['paging']['Article']['options']['sort'] = null;
$result = $this->Paginator->sort('title'); $result = $this->Paginator->sort('title');
$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc" class="asc">Title<\/a>$/', $result); $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);
} }