Browse Source

Create test for Hash::sort with locale option

Alexandros Solanos 9 years ago
parent
commit
5cb40cb8a2
1 changed files with 33 additions and 0 deletions
  1. 33 0
      tests/TestCase/Utility/HashTest.php

+ 33 - 0
tests/TestCase/Utility/HashTest.php

@@ -1678,6 +1678,39 @@ class HashTest extends TestCase
     }
 
     /**
+     * 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
      *
      * @return void