Skip to content
This repository
Browse code

Fix sortDir() to read default params.

sortDir() also did not reflect the default paging parameters.
This would result in initial links not matching the query used.

Fixes #2640
  • Loading branch information...
commit dde19f97c784952ba716b841eddd482a2c70184b 1 parent 8f72b69
Mark Story authored March 03, 2012
35  lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php
@@ -384,6 +384,15 @@ public function testSortKeyFallbackToParams() {
384 384
 
385 385
 		$result = $this->Paginator->sortKey('Article');
386 386
 		$this->assertEquals('Article.body', $result);
  387
+
  388
+		$this->Paginator->request->params['paging']['Article']['order'] = array(
  389
+			'Article.body' => 'DESC'
  390
+		);
  391
+		$result = $this->Paginator->sortKey();
  392
+		$this->assertEquals('Article.body', $result);
  393
+
  394
+		$result = $this->Paginator->sortKey('Article');
  395
+		$this->assertEquals('Article.body', $result);
387 396
 	}
388 397
 
389 398
 /**
@@ -456,6 +465,32 @@ public function testSortDir() {
456 465
 	}
457 466
 
458 467
 /**
  468
+ * Test that sortDir falls back to the default sorting options set
  469
+ * in the $params which are the default pagination options.
  470
+ *
  471
+ * @return void
  472
+ */
  473
+	public function testSortDirFallbackToParams() {
  474
+		$this->Paginator->request->params['paging']['Article']['order'] = array(
  475
+			'Article.body' => 'ASC'
  476
+		);
  477
+		$result = $this->Paginator->sortDir();
  478
+		$this->assertEquals('asc', $result);
  479
+
  480
+		$result = $this->Paginator->sortDir('Article');
  481
+		$this->assertEquals('asc', $result);
  482
+
  483
+		$this->Paginator->request->params['paging']['Article']['order'] = array(
  484
+			'Article.body' => 'DESC'
  485
+		);
  486
+		$result = $this->Paginator->sortDir();
  487
+		$this->assertEquals('desc', $result);
  488
+
  489
+		$result = $this->Paginator->sortDir('Article');
  490
+		$this->assertEquals('desc', $result);
  491
+	}
  492
+
  493
+/**
459 494
  * testSortAdminLinks method
460 495
  *
461 496
  * @return void
2  lib/Cake/View/Helper/PaginatorHelper.php
@@ -232,6 +232,8 @@ public function sortDir($model = null, $options = array()) {
232 232
 			$dir = strtolower($options['direction']);
233 233
 		} elseif (isset($options['order']) && is_array($options['order'])) {
234 234
 			$dir = strtolower(current($options['order']));
  235
+		} elseif (isset($params['order']) && is_array($params['order'])) {
  236
+			$dir = strtolower(current($params['order']));
235 237
 		}
236 238
 
237 239
 		if ($dir == 'desc') {

0 notes on commit dde19f9

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