Security update for Core, with self-updated composer
[yaffs-website] / web / core / tests / Drupal / Tests / Component / Gettext / PoHeaderTest.php
1 <?php
2
3 namespace Drupal\Tests\Component\Gettext;
4
5 use Drupal\Component\Gettext\PoHeader;
6 use PHPUnit\Framework\TestCase;
7
8 /**
9  * Unit tests for the Gettext PO file header handling features.
10  *
11  * @see Drupal\Component\Gettext\PoHeader.
12  *
13  * @group Gettext
14  */
15 class PoHeaderTest extends TestCase {
16
17   /**
18    * Tests that plural expressions are evaluated correctly.
19    *
20    * Validate that the given plural expressions is evaluated with the correct
21    * plural formula.
22    *
23    * @param string $plural
24    *   The plural expression.
25    * @param array $expected
26    *   Array of expected plural positions keyed by plural value.
27    *
28    * @dataProvider providerTestPluralsFormula
29    */
30   public function testPluralsFormula($plural, $expected) {
31     $p = new PoHeader();
32     $parsed = $p->parsePluralForms($plural);
33     list($nplurals, $new_plural) = $parsed;
34     foreach ($expected as $number => $plural_form) {
35       $result = isset($new_plural[$number]) ? $new_plural[$number] : $new_plural['default'];
36       $this->assertEquals($result, $plural_form, 'Difference found at ' . $number . ': ' . $plural_form . ' versus ' . $result);
37     }
38   }
39
40   /**
41    * Data provider for testPluralsFormula.
42    *
43    * Gets pairs of plural expressions and expected plural positions keyed by
44    * plural value.
45    *
46    * @return array
47    *   Pairs of plural expressions and expected plural positions keyed by plural
48    *   value.
49    */
50   public function providerTestPluralsFormula() {
51     return [
52       [
53         'nplurals=1; plural=0;',
54         ['default' => 0],
55       ],
56       [
57         'nplurals=2; plural=(n > 1);',
58         [0 => 0, 1 => 0, 'default' => 1],
59       ],
60       [
61         'nplurals=2; plural=(n!=1);',
62         [1 => 0, 'default' => 1],
63       ],
64       [
65         'nplurals=2; plural=(((n==1)||((n%10)==1))?(0):1);',
66         [
67           1 => 0,
68           11 => 0,
69           21 => 0,
70           31 => 0,
71           41 => 0,
72           51 => 0,
73           61 => 0,
74           71 => 0,
75           81 => 0,
76           91 => 0,
77           101 => 0,
78           111 => 0,
79           121 => 0,
80           131 => 0,
81           141 => 0,
82           151 => 0,
83           161 => 0,
84           171 => 0,
85           181 => 0,
86           191 => 0,
87           'default' => 1,
88         ],
89       ],
90       [
91         'nplurals=3; plural=((((n%10)==1)&&((n%100)!=11))?(0):(((((n%10)>=2)&&((n%10)<=4))&&(((n%100)<10)||((n%100)>=20)))?(1):2));',
92         [
93           1 => 0,
94           2 => 1,
95           3 => 1,
96           4 => 1,
97           21 => 0,
98           22 => 1,
99           23 => 1,
100           24 => 1,
101           31 => 0,
102           32 => 1,
103           33 => 1,
104           34 => 1,
105           41 => 0,
106           42 => 1,
107           43 => 1,
108           44 => 1,
109           51 => 0,
110           52 => 1,
111           53 => 1,
112           54 => 1,
113           61 => 0,
114           62 => 1,
115           63 => 1,
116           64 => 1,
117           71 => 0,
118           72 => 1,
119           73 => 1,
120           74 => 1,
121           81 => 0,
122           82 => 1,
123           83 => 1,
124           84 => 1,
125           91 => 0,
126           92 => 1,
127           93 => 1,
128           94 => 1,
129           101 => 0,
130           102 => 1,
131           103 => 1,
132           104 => 1,
133           121 => 0,
134           122 => 1,
135           123 => 1,
136           124 => 1,
137           131 => 0,
138           132 => 1,
139           133 => 1,
140           134 => 1,
141           141 => 0,
142           142 => 1,
143           143 => 1,
144           144 => 1,
145           151 => 0,
146           152 => 1,
147           153 => 1,
148           154 => 1,
149           161 => 0,
150           162 => 1,
151           163 => 1,
152           164 => 1,
153           171 => 0,
154           172 => 1,
155           173 => 1,
156           174 => 1,
157           181 => 0,
158           182 => 1,
159           183 => 1,
160           184 => 1,
161           191 => 0,
162           192 => 1,
163           193 => 1,
164           194 => 1,
165           'default' => 2,
166         ],
167       ],
168       [
169         'nplurals=3; plural=((n==1)?(0):(((n>=2)&&(n<=4))?(1):2));',
170         [
171           1 => 0,
172           2 => 1,
173           3 => 1,
174           4 => 1,
175           'default' => 2,
176         ],
177       ],
178       [
179         'nplurals=3; plural=((n==1)?(0):(((n==0)||(((n%100)>0)&&((n%100)<20)))?(1):2));',
180         [
181           0 => 1,
182           1 => 0,
183           2 => 1,
184           3 => 1,
185           4 => 1,
186           5 => 1,
187           6 => 1,
188           7 => 1,
189           8 => 1,
190           9 => 1,
191           10 => 1,
192           11 => 1,
193           12 => 1,
194           13 => 1,
195           14 => 1,
196           15 => 1,
197           16 => 1,
198           17 => 1,
199           18 => 1,
200           19 => 1,
201           101 => 1,
202           102 => 1,
203           103 => 1,
204           104 => 1,
205           105 => 1,
206           106 => 1,
207           107 => 1,
208           108 => 1,
209           109 => 1,
210           110 => 1,
211           111 => 1,
212           112 => 1,
213           113 => 1,
214           114 => 1,
215           115 => 1,
216           116 => 1,
217           117 => 1,
218           118 => 1,
219           119 => 1,
220           'default' => 2,
221         ],
222       ],
223       [
224         'nplurals=3; plural=((n==1)?(0):(((((n%10)>=2)&&((n%10)<=4))&&(((n%100)<10)||((n%100)>=20)))?(1):2));',
225         [
226           1 => 0,
227           2 => 1,
228           3 => 1,
229           4 => 1,
230           22 => 1,
231           23 => 1,
232           24 => 1,
233           32 => 1,
234           33 => 1,
235           34 => 1,
236           42 => 1,
237           43 => 1,
238           44 => 1,
239           52 => 1,
240           53 => 1,
241           54 => 1,
242           62 => 1,
243           63 => 1,
244           64 => 1,
245           72 => 1,
246           73 => 1,
247           74 => 1,
248           82 => 1,
249           83 => 1,
250           84 => 1,
251           92 => 1,
252           93 => 1,
253           94 => 1,
254           102 => 1,
255           103 => 1,
256           104 => 1,
257           122 => 1,
258           123 => 1,
259           124 => 1,
260           132 => 1,
261           133 => 1,
262           134 => 1,
263           142 => 1,
264           143 => 1,
265           144 => 1,
266           152 => 1,
267           153 => 1,
268           154 => 1,
269           162 => 1,
270           163 => 1,
271           164 => 1,
272           172 => 1,
273           173 => 1,
274           174 => 1,
275           182 => 1,
276           183 => 1,
277           184 => 1,
278           192 => 1,
279           193 => 1,
280           194 => 1,
281           'default' => 2,
282         ],
283       ],
284       [
285         'nplurals=4; plural=(((n==1)||(n==11))?(0):(((n==2)||(n==12))?(1):(((n>2)&&(n<20))?(2):3)));',
286         [
287           1 => 0,
288           2 => 1,
289           3 => 2,
290           4 => 2,
291           5 => 2,
292           6 => 2,
293           7 => 2,
294           8 => 2,
295           9 => 2,
296           10 => 2,
297           11 => 0,
298           12 => 1,
299           13 => 2,
300           14 => 2,
301           15 => 2,
302           16 => 2,
303           17 => 2,
304           18 => 2,
305           19 => 2,
306           'default' => 3,
307         ],
308       ],
309       [
310         'nplurals=4; plural=(((n%100)==1)?(0):(((n%100)==2)?(1):((((n%100)==3)||((n%100)==4))?(2):3)));',
311         [
312           1 => 0,
313           2 => 1,
314           3 => 2,
315           4 => 2,
316           101 => 0,
317           102 => 1,
318           103 => 2,
319           104 => 2,
320           'default' => 3,
321         ],
322       ],
323       [
324         'nplurals=5; plural=((n==1)?(0):((n==2)?(1):((n<7)?(2):((n<11)?(3):4))));',
325         [
326           0 => 2,
327           1 => 0,
328           2 => 1,
329           3 => 2,
330           4 => 2,
331           5 => 2,
332           6 => 2,
333           7 => 3,
334           8 => 3,
335           9 => 3,
336           10 => 3,
337           'default' => 4,
338         ],
339       ],
340       [
341         'nplurals=6; plural=((n==1)?(0):((n==0)?(1):((n==2)?(2):((((n%100)>=3)&&((n%100)<=10))?(3):((((n%100)>=11)&&((n%100)<=99))?(4):5)))));',
342         [
343           0 => 1,
344           1 => 0,
345           2 => 2,
346           3 => 3,
347           4 => 3,
348           5 => 3,
349           6 => 3,
350           7 => 3,
351           8 => 3,
352           9 => 3,
353           10 => 3,
354           100 => 5,
355           101 => 5,
356           102 => 5,
357           103 => 3,
358           104 => 3,
359           105 => 3,
360           106 => 3,
361           107 => 3,
362           108 => 3,
363           109 => 3,
364           110 => 3,
365           'default' => 4,
366         ],
367       ],
368     ];
369   }
370
371 }