xref: /PHP-5.3/ext/intl/tests/collator_asort.phpt (revision 9762609c)
1--TEST--
2asort()
3--SKIPIF--
4<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
5--FILE--
6<?php
7
8/*
9 * Sort associative arrays using various locales.
10 */
11
12
13$test_num = 1;
14
15/*
16 * Sort various arrays in specified locale.
17 */
18function sort_arrays( $locale, $test_arrays, $sort_flag = Collator::SORT_REGULAR )
19{
20    $res_str = '';
21
22    $coll = ut_coll_create( $locale );
23
24    foreach( $test_arrays as $test_array )
25    {
26        // Try to sort test data.
27        $res_val = ut_coll_asort( $coll, $test_array, $sort_flag );
28
29        // Return output data.
30        $res_dump = "\n" . dump( $test_array ) .
31                    "\n Result: " . dump( $res_val );
32
33		// Preppend test signature to output string
34        $md5 = md5( $res_dump );
35
36        global $test_num;
37
38        $res_str .= "\n\n".
39                    "Test $test_num.$md5:" .
40                    $res_dump;
41        ++$test_num;
42    }
43
44    return $res_str;
45}
46
47/*
48 * Test main function.
49 */
50function ut_main()
51{
52    global $test_num;
53    $test_num = 1;
54    $res_str = '';
55
56    // Sort an array in SORT_REGULAR mode using en_US locale.
57    $test_params = array(
58        array( 'd' => 'y'  ,
59               'c' => 'i'  ,
60               'a' => 'k'  ),
61
62        array( 'a' => 'a'  ,
63               'b' => 'aaa',
64               'c' => 'aa' ),
65
66        array( 'a'  => 'a' ,
67               'aaa'=> 'a' ,
68               'aa' => 'a' ),
69
70        array( '1' => 'abc',
71               '5' => '!'  ,
72               '2' => null ,
73               '7' => ''   ),
74
75        array( '1' => '100',
76               '2' => '25' ,
77               '3' => '36' ),
78
79        array( '1' => 5    ,
80               '2' => '30' ,
81               '3' => 2    )
82    );
83
84    $res_str .= sort_arrays( 'en_US', $test_params );
85
86    // Sort an array in SORT_STRING mode using en_US locale.
87    $test_params = array(
88        array( '1' => '100',
89               '2' => '25' ,
90               '3' => '36' ),
91
92        array( '1' => 5    ,
93               '2' => '30' ,
94               '3' => 2    ),
95
96        array( '1' => 'd'  ,
97               '2' => ''   ,
98               '3' => ' a' ),
99
100        array( '1' => 'y'  ,
101               '2' => 'k'  ,
102               '3' => 'i'  )
103    );
104
105    $res_str .= sort_arrays( 'en_US', $test_params, Collator::SORT_STRING );
106
107    // Sort a non-ASCII array using ru_RU locale.
108    $test_params = array(
109        array( 'п' => 'у',
110               'б' => 'в',
111               'е' => 'а' ),
112
113        array( '1' => 'п',
114               '4' => '',
115               '7' => 'd',
116               '2' => 'пп' )
117    );
118
119    $res_str .= sort_arrays( 'ru_RU', $test_params );
120
121
122    // Sort an array using Lithuanian locale.
123    $test_params = array(
124        array( 'd' => 'y',
125               'c' => 'i',
126               'a' => 'k' )
127    );
128
129    $res_str .= sort_arrays( 'lt_LT', $test_params );
130
131    return $res_str . "\n";
132}
133
134include_once( 'ut_common.inc' );
135ut_run();
136?>
137--EXPECT--
138Test 1.162b81ac12878b817fc39063097e45b5:
139array (
140  'c' => 'i',
141  'a' => 'k',
142  'd' => 'y',
143)
144 Result: true
145
146Test 2.93d96e22f692d8a281b0a389f01f8d1e:
147array (
148  'a' => 'a',
149  'c' => 'aa',
150  'b' => 'aaa',
151)
152 Result: true
153
154Test 3.9f25de4482bc7b58de508e278113317c:
155array (
156  'aa' => 'a',
157  'aaa' => 'a',
158  'a' => 'a',
159)
160 Result: true
161
162Test 4.a85a41ea78e45b651080cfd98c0b431d:
163array (
164  7 => '',
165  2 => NULL,
166  5 => '!',
167  1 => 'abc',
168)
169 Result: true
170
171Test 5.99dc71f405b286e03d489061b36e6900:
172array (
173  2 => '25',
174  3 => '36',
175  1 => '100',
176)
177 Result: true
178
179Test 6.bf5bba243307c9d12934e756ad4be190:
180array (
181  3 => 2,
182  1 => 5,
183  2 => '30',
184)
185 Result: true
186
187Test 7.e4ee7024c61476e9e7a6c28b5e47df6f:
188array (
189  1 => '100',
190  2 => '25',
191  3 => '36',
192)
193 Result: true
194
195Test 8.5fa7033dd43784be0db1474eb48b83c8:
196array (
197  3 => 2,
198  2 => '30',
199  1 => 5,
200)
201 Result: true
202
203Test 9.588cdf4692bc09aa92ffe7e48f9e4579:
204array (
205  2 => '',
206  3 => ' a',
207  1 => 'd',
208)
209 Result: true
210
211Test 10.be02641a47ebcccd23e4183ca3a415f7:
212array (
213  3 => 'i',
214  2 => 'k',
215  1 => 'y',
216)
217 Result: true
218
219Test 11.153d9b11d1e5936afc917a94a4e11f34:
220array (
221  'е' => 'а',
222  'б' => 'в',
223  'п' => 'у',
224)
225 Result: true
226
227Test 12.6eaea3fa21b3b7d006ca7dfa27d4e282:
228array (
229  4 => '',
230  7 => 'd',
231  1 => 'п',
232  2 => 'пп',
233)
234 Result: true
235
236Test 13.8800d48abb960a59002eef77f1d73ae0:
237array (
238  'c' => 'i',
239  'd' => 'y',
240  'a' => 'k',
241)
242 Result: true
243