mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fixing a problem with setting Paginator::sort() defaults directon to desc
This commit is contained in:
parent
925fda7ba6
commit
67cea6d21c
2 changed files with 24 additions and 3 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue