Fixing regression in PaginatorHelper. Adding tests for PaginatorHelper::sortDir, as well as fixing incorrect test for sorting with Model.field dot notation. Fixes #6218.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8125 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
jperras 2009-03-22 18:59:53 +00:00
parent 364fe18208
commit 4439bc4f70
2 changed files with 80 additions and 5 deletions

View file

@ -222,8 +222,16 @@ class PaginatorHelper extends AppHelper {
$title = __(Inflector::humanize(preg_replace('/_id$/', '', $title)), true);
}
$dir = 'asc';
$sortKey = $this->sortKey($options['model']);
$defaultModel = $this->defaultModel();
if ($this->sortKey($options['model']) == $key && $this->sortDir($options['model']) == 'asc') {
if (strpos($sortKey, $defaultModel) !== false && strpos($key, $defaultModel) === false) {
$isSorted = ($sortKey === $defaultModel . '.' . $key);
} else {
$isSorted = ($sortKey === $key);
}
if ($isSorted && $this->sortDir($options['model']) === 'asc') {
$dir = 'desc';
}
if (is_array($title) && array_key_exists($dir, $title)) {

View file

@ -176,7 +176,7 @@ class PaginatorHelperTest extends CakeTestCase {
$result = $this->Paginator->sort('Title','Article.title');
$this->assertPattern('/\/accounts\/index\/page:1\/sort:Article.title\/direction:desc">Title<\/a>$/', $result);
$this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
$this->Paginator->params['paging']['Article']['options']['order'] = array('Account.title' => 'asc');
$result = $this->Paginator->sort('title');
$this->assertPattern('/\/accounts\/index\/page:1\/sort:title\/direction:asc">Title<\/a>$/', $result);
@ -193,9 +193,76 @@ class PaginatorHelperTest extends CakeTestCase {
'order' => array('Article.title' => 'desc'
)));
$this->assertEqual('Article.title', $result);
}
/**
* testSortDir method
*
* @access public
* @return void
*/
function testSortDir() {
$result = $this->Paginator->sortDir();
$expected = 'asc';
$this->assertEqual($result, $expected);
$this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
$result = $this->Paginator->sortDir();
$expected = 'desc';
$this->assertEqual($result, $expected);
unset($this->Paginator->params['paging']['Article']['options']);
$this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
$result = $this->Paginator->sortDir();
$expected = 'asc';
$this->assertEqual($result, $expected);
unset($this->Paginator->params['paging']['Article']['options']);
$this->Paginator->params['paging']['Article']['options']['order'] = array('title' => 'desc');
$result = $this->Paginator->sortDir();
$expected = 'desc';
$this->assertEqual($result, $expected);
unset($this->Paginator->params['paging']['Article']['options']);
$this->Paginator->params['paging']['Article']['options']['order'] = array('title' => 'asc');
$result = $this->Paginator->sortDir();
$expected = 'asc';
$this->assertEqual($result, $expected);
unset($this->Paginator->params['paging']['Article']['options']);
$this->Paginator->params['paging']['Article']['options']['direction'] = 'asc';
$result = $this->Paginator->sortDir();
$expected = 'asc';
$this->assertEqual($result, $expected);
unset($this->paginator->params['paging']['article']['options']);
$this->Paginator->params['paging']['Article']['options']['direction'] = 'desc';
$result = $this->Paginator->sortDir();
$expected = 'desc';
$this->assertEqual($result, $expected);
unset($this->Paginator->params['paging']['Article']['options']);
$result = $this->Paginator->sortDir('Article', array('direction' => 'asc'));
$expected = 'asc';
$this->assertEqual($result, $expected);
$result = $this->Paginator->sortDir('Article', array('direction' => 'desc'));
$expected = 'desc';
$this->assertEqual($result, $expected);
$result = $this->Paginator->sortDir('Article', array('direction' => 'asc'));
$expected = 'asc';
$this->assertEqual($result, $expected);
}
/**
* testSortAdminLinks method
*
@ -845,4 +912,4 @@ class PaginatorHelperTest extends CakeTestCase {
$this->assertPattern('/["\']\/issues\/index\/page:3["\']/', $result);
}
}
?>
?>