diff --git a/tests/TestCase/Utility/HashTest.php b/tests/TestCase/Utility/HashTest.php index 6ebf5756e3f..955737b1139 100644 --- a/tests/TestCase/Utility/HashTest.php +++ b/tests/TestCase/Utility/HashTest.php @@ -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 *