Skip to content
This repository
Browse code

Fix sortKey() not looking at default params.

sortKey() only looked at the options values, which do not include
default sorting options declared as settings in the helper.

Fixes #2640
  • Loading branch information...
commit 8f72b696a0956fd6e594132c1fd9dfac75b032a7 1 parent 3f4be3b
Mark Story authored March 03, 2012
17  lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php
@@ -53,6 +53,8 @@ public function setUp() {
53 53
 					'prevPage' => false,
54 54
 					'nextPage' => true,
55 55
 					'pageCount' => 7,
  56
+					'order' => null,
  57
+					'limit' => 20,
56 58
 					'options' => array(
57 59
 						'page' => 1,
58 60
 						'conditions' => array()
@@ -370,6 +372,21 @@ public function testSortKey() {
370 372
 	}
371 373
 
372 374
 /**
  375
+ * Test that sortKey falls back to the default sorting options set
  376
+ * in the $params which are the default pagination options.
  377
+ *
  378
+ * @return void
  379
+ */
  380
+	public function testSortKeyFallbackToParams() {
  381
+		$this->Paginator->request->params['paging']['Article']['order'] = 'Article.body';
  382
+		$result = $this->Paginator->sortKey();
  383
+		$this->assertEquals('Article.body', $result);
  384
+
  385
+		$result = $this->Paginator->sortKey('Article');
  386
+		$this->assertEquals('Article.body', $result);
  387
+	}
  388
+
  389
+/**
373 390
  * testSortDir method
374 391
  *
375 392
  * @return void
11  lib/Cake/View/Helper/PaginatorHelper.php
@@ -199,13 +199,14 @@ public function sortKey($model = null, $options = array()) {
199 199
 			$params = $this->params($model);
200 200
 			$options = $params['options'];
201 201
 		}
202  
-
203 202
 		if (isset($options['sort']) && !empty($options['sort'])) {
204 203
 			return $options['sort'];
205  
-		} elseif (isset($options['order']) && is_array($options['order'])) {
206  
-			return key($options['order']);
207  
-		} elseif (isset($options['order']) && is_string($options['order'])) {
208  
-			return $options['order'];
  204
+		}
  205
+		if (isset($options['order'])) {
  206
+			return is_array($options['order']) ? key($options['order']) : $options['order'];
  207
+		}
  208
+		if (isset($params['order'])) {
  209
+			return is_array($params['order']) ? key($params['order']) : $params['order'];
209 210
 		}
210 211
 		return null;
211 212
 	}

0 notes on commit 8f72b69

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