Skip to content

Commit

Permalink
Set default sort direction to 'asc'.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed May 30, 2014
1 parent 4e8e266 commit 543066f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
29 changes: 22 additions & 7 deletions lib/Cake/Test/Case/Utility/HashTest.php
Expand Up @@ -23,6 +23,11 @@
*/
class HashTest extends CakeTestCase {

/**
* Data provider
*
* @return array
*/
public static function articleData() {
return array(
array(
Expand Down Expand Up @@ -136,6 +141,11 @@ public static function articleData() {
);
}

/**
* Data provider
*
* @return array
*/
public static function userData() {
return array(
array(
Expand Down Expand Up @@ -1021,7 +1031,7 @@ public function testExtractUnevenKeys() {
* @return void
*/
public function testSort() {
$result = Hash::sort(array(), '{n}.name', 'asc');
$result = Hash::sort(array(), '{n}.name');
$this->assertEquals(array(), $result);

$a = array(
Expand All @@ -1044,7 +1054,7 @@ public function testSort() {
'Friend' => array(array('name' => 'Nate'))
)
);
$a = Hash::sort($a, '{n}.Friend.{n}.name', 'asc');
$a = Hash::sort($a, '{n}.Friend.{n}.name');
$this->assertEquals($a, $b);

$b = array(
Expand Down Expand Up @@ -1786,6 +1796,11 @@ public function testMap() {
$this->assertEquals($expected, $result);
}

/**
* testApply
*
* @return void
*/
public function testApply() {
$data = self::articleData();

Expand All @@ -1808,8 +1823,8 @@ public function testReduce() {
/**
* testing method for map callbacks.
*
* @param mixed $value
* @return mixed.
* @param mixed $value Value
* @return mixed
*/
public function mapCallback($value) {
return $value * 2;
Expand All @@ -1818,9 +1833,9 @@ public function mapCallback($value) {
/**
* testing method for reduce callbacks.
*
* @param mixed $one
* @param mixed $two
* @return mixed.
* @param mixed $one First param
* @param mixed $two Second param
* @return mixed
*/
public function reduceCallback($one, $two) {
return $one + $two;
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Utility/Hash.php
Expand Up @@ -800,12 +800,12 @@ public static function apply(array $data, $path, $function) {
*
* @param array $data An array of data to sort
* @param string $path A Set-compatible path to the array value
* @param string $dir See directions above.
* @param string $dir See directions above. Defaults to 'asc'.
* @param string $type See direction types above. Defaults to 'regular'.
* @return array Sorted array of data
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/hash.html#Hash::sort
*/
public static function sort(array $data, $path, $dir, $type = 'regular') {
public static function sort(array $data, $path, $dir = 'asc', $type = 'regular') {
if (empty($data)) {
return array();
}
Expand Down

0 comments on commit 543066f

Please sign in to comment.