@@ -31,7 +31,7 @@ final class LanguageTest extends CIUnitTestCase
31
31
32
32
protected function setUp (): void
33
33
{
34
- $ this ->lang = new MockLanguage ('en ' );
34
+ $ this ->lang = new Language ('en ' );
35
35
}
36
36
37
37
public function testReturnsStringWithNoFileInMessage (): void
@@ -54,6 +54,8 @@ public function testReturnParsedStringWithNoFileInMessage(): void
54
54
55
55
public function testGetLineReturnsLine (): void
56
56
{
57
+ $ this ->lang = new MockLanguage ('en ' );
58
+
57
59
$ this ->lang ->setData ('books ' , [
58
60
'bookSaved ' => 'We kept the book free from the boogeyman ' ,
59
61
'booksSaved ' => 'We saved some more ' ,
@@ -62,8 +64,67 @@ public function testGetLineReturnsLine(): void
62
64
$ this ->assertSame ('We saved some more ' , $ this ->lang ->getLine ('books.booksSaved ' ));
63
65
}
64
66
67
+ public function testGetLineReturnsLineWithKeyWithDots (): void
68
+ {
69
+ $ this ->lang = new MockLanguage ('en ' );
70
+
71
+ $ this ->lang ->setData ('books ' , [
72
+ 'bookSaved.foo ' => 'We kept the book free from the boogeyman ' ,
73
+ 'booksSaved.bar.baz ' => 'We saved some more ' ,
74
+ ]);
75
+
76
+ $ this ->assertSame (
77
+ 'We kept the book free from the boogeyman ' ,
78
+ $ this ->lang ->getLine ('books.bookSaved.foo ' )
79
+ );
80
+ $ this ->assertSame (
81
+ 'We saved some more ' ,
82
+ $ this ->lang ->getLine ('books.booksSaved.bar.baz ' )
83
+ );
84
+ }
85
+
86
+ public function testGetLineCannotUseKeysWithLeadingDot (): void
87
+ {
88
+ $ this ->lang = new MockLanguage ('en ' );
89
+
90
+ $ this ->lang ->setData ('books ' , [
91
+ '.bookSaved.foo. ' => 'We kept the book free from the boogeyman ' ,
92
+ '.booksSaved.bar.baz. ' => 'We saved some more ' ,
93
+ ]);
94
+
95
+ $ this ->assertSame (
96
+ 'books.bookSaved.foo ' , // Can't get the message.
97
+ $ this ->lang ->getLine ('books.bookSaved.foo ' )
98
+ );
99
+ $ this ->assertSame (
100
+ 'books.booksSaved.bar.baz ' , // Can't get the message.
101
+ $ this ->lang ->getLine ('books.booksSaved.bar.baz ' )
102
+ );
103
+ }
104
+
105
+ public function testGetLineCannotUseKeysWithTrailingDot (): void
106
+ {
107
+ $ this ->lang = new MockLanguage ('en ' );
108
+
109
+ $ this ->lang ->setData ('books ' , [
110
+ 'bookSaved.foo. ' => 'We kept the book free from the boogeyman ' ,
111
+ 'booksSaved.bar.baz. ' => 'We saved some more ' ,
112
+ ]);
113
+
114
+ $ this ->assertSame (
115
+ 'books.bookSaved.foo ' , // Can't get the message.
116
+ $ this ->lang ->getLine ('books.bookSaved.foo ' )
117
+ );
118
+ $ this ->assertSame (
119
+ 'books.booksSaved.bar.baz ' , // Can't get the message.
120
+ $ this ->lang ->getLine ('books.booksSaved.bar.baz ' )
121
+ );
122
+ }
123
+
65
124
public function testGetLineReturnsFallbackLine (): void
66
125
{
126
+ $ this ->lang = new MockLanguage ('en ' );
127
+
67
128
$ this ->lang
68
129
->setLocale ('en-US ' )
69
130
->setData ('equivalent ' , [
@@ -86,6 +147,8 @@ public function testGetLineReturnsFallbackLine(): void
86
147
87
148
public function testGetLineArrayReturnsLineArray (): void
88
149
{
150
+ $ this ->lang = new MockLanguage ('en ' );
151
+
89
152
$ this ->lang ->setData ('books ' , [
90
153
'booksList ' => [
91
154
'The Boogeyman ' ,
@@ -106,6 +169,8 @@ public function testGetLineFormatsMessage(): void
106
169
$ this ->markTestSkipped ('No intl support. ' );
107
170
}
108
171
172
+ $ this ->lang = new MockLanguage ('en ' );
173
+
109
174
$ this ->lang ->setData ('books ' , [
110
175
'bookCount ' => '{0, number, integer} books have been saved. ' ,
111
176
]);
@@ -120,6 +185,8 @@ public function testGetLineArrayFormatsMessages(): void
120
185
$ this ->markTestSkipped ('No intl support. ' );
121
186
}
122
187
188
+ $ this ->lang = new MockLanguage ('en ' );
189
+
123
190
$ this ->lang ->setData ('books ' , [
124
191
'bookList ' => [
125
192
'{0, number, integer} related books. ' ,
@@ -139,6 +206,8 @@ public function testGetLineInvalidFormatMessage(): void
139
206
$ this ->markTestSkipped ('No intl support. ' );
140
207
}
141
208
209
+ $ this ->lang = new MockLanguage ('en ' );
210
+
142
211
$ this ->lang ->setLocale ('ar ' );
143
212
144
213
$ line = 'تم الكشف عن كلمة المرور {0} بسبب اختراق البيانات وشوهدت {1 ، عدد} مرة في {2} في كلمات المرور المخترقة. ' ;
@@ -163,6 +232,8 @@ public function testLangAllowsOtherLocales(): void
163
232
164
233
public function testLangDoesntFormat (): void
165
234
{
235
+ $ this ->lang = new MockLanguage ('en ' );
236
+
166
237
$ this ->lang ->disableIntlSupport ();
167
238
168
239
$ this ->lang ->setData ('books ' , [
@@ -185,40 +256,42 @@ public function testLanguageDuplicateKey(): void
185
256
186
257
public function testLanguageFileLoading (): void
187
258
{
188
- $ this -> lang = new SecondMockLanguage ('en ' );
259
+ $ lang = new SecondMockLanguage ('en ' );
189
260
190
- $ this -> lang ->loadem ('More ' , 'en ' );
191
- $ this ->assertContains ('More ' , $ this -> lang ->loaded ());
261
+ $ lang ->loadem ('More ' , 'en ' );
262
+ $ this ->assertContains ('More ' , $ lang ->loaded ());
192
263
193
- $ this -> lang ->loadem ('More ' , 'en ' );
194
- $ this ->assertCount (1 , $ this -> lang ->loaded ()); // should only be there once
264
+ $ lang ->loadem ('More ' , 'en ' );
265
+ $ this ->assertCount (1 , $ lang ->loaded ()); // should only be there once
195
266
}
196
267
197
268
public function testLanguageFileLoadingReturns (): void
198
269
{
199
- $ this -> lang = new SecondMockLanguage ('en ' );
270
+ $ lang = new SecondMockLanguage ('en ' );
200
271
201
- $ result = $ this -> lang ->loadem ('More ' , 'en ' , true );
202
- $ this ->assertNotContains ('More ' , $ this -> lang ->loaded ());
272
+ $ result = $ lang ->loadem ('More ' , 'en ' , true );
273
+ $ this ->assertNotContains ('More ' , $ lang ->loaded ());
203
274
$ this ->assertCount (3 , $ result );
204
275
205
- $ this -> lang ->loadem ('More ' , 'en ' );
206
- $ this ->assertContains ('More ' , $ this -> lang ->loaded ());
207
- $ this ->assertCount (1 , $ this -> lang ->loaded ());
276
+ $ lang ->loadem ('More ' , 'en ' );
277
+ $ this ->assertContains ('More ' , $ lang ->loaded ());
278
+ $ this ->assertCount (1 , $ lang ->loaded ());
208
279
}
209
280
210
281
public function testLanguageSameKeyAndFileName (): void
211
282
{
283
+ $ lang = new MockLanguage ('en ' );
284
+
212
285
// first file data | example.message
213
- $ this -> lang ->setData ('example ' , ['message ' => 'This is an example message ' ]);
286
+ $ lang ->setData ('example ' , ['message ' => 'This is an example message ' ]);
214
287
215
288
// force loading data into file Example
216
- $ this ->assertSame ('This is an example message ' , $ this -> lang ->getLine ('example.message ' ));
289
+ $ this ->assertSame ('This is an example message ' , $ lang ->getLine ('example.message ' ));
217
290
218
291
// second file data | another.example
219
- $ this -> lang ->setData ('another ' , ['example ' => 'Another example ' ]);
292
+ $ lang ->setData ('another ' , ['example ' => 'Another example ' ]);
220
293
221
- $ this ->assertSame ('Another example ' , $ this -> lang ->getLine ('another.example ' ));
294
+ $ this ->assertSame ('Another example ' , $ lang ->getLine ('another.example ' ));
222
295
}
223
296
224
297
public function testGetLocale (): void
0 commit comments