Permalink
Browse files

Fixing regression in PaginatorHelper. Adding tests for PaginatorHelpe…

…r::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
  • Loading branch information...
1 parent 364fe18 commit 4439bc4f70d3fbdcfa679a12e2a0cffd2223f1e2 @jperras jperras committed Mar 22, 2009
Showing with 79 additions and 4 deletions.
  1. +9 −1 cake/libs/view/helpers/paginator.php
  2. +70 −3 cake/tests/cases/libs/view/helpers/paginator.test.php
@@ -222,8 +222,16 @@ function sort($title, $key = null, $options = array()) {
$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)) {
@@ -176,7 +176,7 @@ function testSortLinksUsingDotNotation() {
$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 @@ function testSortKey() {
'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 @@ function testWithPlugin() {
$this->assertPattern('/["\']\/issues\/index\/page:3["\']/', $result);
}
}
-?>
+?>

0 comments on commit 4439bc4

Please sign in to comment.