Skip to content

Commit

Permalink
Create test for Hash::sort with locale option
Browse files Browse the repository at this point in the history
  • Loading branch information
hytromo committed Aug 23, 2016
1 parent 0c84232 commit 5cb40cb
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/TestCase/Utility/HashTest.php
Expand Up @@ -1677,6 +1677,39 @@ public function testSortNatural()
$this->assertEquals($expected, $result);
}

/**
* Test sort() with locale option.
*
* @return void
*/
public function testSortLocale()
{
// get the current locale
$oldLocale = setlocale(LC_COLLATE, '0');

// the de_DE.utf8 locale must be installed on the system where the test is performed
setlocale(LC_COLLATE, 'de_DE.utf8');

$items = [
['Item' => ['entry' => 'Übergabe']],
['Item' => ['entry' => 'Ostfriesland']],
['Item' => ['entry' => 'Äpfel']],
['Item' => ['entry' => 'Apfel']],
];

$result = Hash::sort($items, '{n}.Item.entry', 'asc', 'locale');
$expected = [
['Item' => ['entry' => 'Apfel']],
['Item' => ['entry' => 'Äpfel']],
['Item' => ['entry' => 'Ostfriesland']],
['Item' => ['entry' => 'Übergabe']],
];
$this->assertEquals($expected, $result);

// change to the original locale
setlocale(LC_COLLATE, $oldLocale);
}

/**
* Test that sort() with 'natural' type will fallback to 'regular' as SORT_NATURAL is introduced in PHP 5.4
*
Expand Down

0 comments on commit 5cb40cb

Please sign in to comment.