Skip to content
This repository
Browse code

fixes #6507 paginator sort directions

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8239 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information...
commit 56bee6e1fc511f813c181082ffb38018db180906 1 parent 4cfdd31
authored July 21, 2009
3  cake/libs/view/helpers/paginator.php
@@ -226,11 +226,12 @@ function sort($title, $key = null, $options = array()) {
226 226
 		}
227 227
 		$dir = 'asc';
228 228
 		$sortKey = $this->sortKey($options['model']);
229  
-		$isSorted = ($sortKey === $key);
  229
+		$isSorted = ($sortKey === $key || $sortKey === $this->defaultModel() . '.' . $key);
230 230
 
231 231
 		if ($isSorted && $this->sortDir($options['model']) === 'asc') {
232 232
 			$dir = 'desc';
233 233
 		}
  234
+
234 235
 		if (is_array($title) && array_key_exists($dir, $title)) {
235 236
 			$title = $title[$dir];
236 237
 		}
11  cake/tests/cases/libs/view/helpers/paginator.test.php
@@ -153,6 +153,17 @@ function testSortLinks() {
153 153
 		$this->Paginator->params['paging']['Article']['options']['sort'] = 'title';
154 154
 		$result = $this->Paginator->sort(array('asc' => 'ascending', 'desc' => 'descending'), 'title');
155 155
 		$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc">descending<\/a>$/', $result);
  156
+		
  157
+		$this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
  158
+		$this->Paginator->params['paging']['Article']['options']['sort'] = null;
  159
+		$result = $this->Paginator->sort('title');
  160
+		$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:asc">Title<\/a>$/', $result);
  161
+		
  162
+		
  163
+		$this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
  164
+		$this->Paginator->params['paging']['Article']['options']['sort'] = null;
  165
+		$result = $this->Paginator->sort('title');
  166
+		$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc">Title<\/a>$/', $result);
156 167
 	}
157 168
 /**
158 169
  * testSortLinksUsingDotNotation method

0 notes on commit 56bee6e

Please sign in to comment.
Something went wrong with that request. Please try again.