Skip to content

Commit a13c588

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into 4.6
2 parents 510bf8b + f2e560f commit a13c588

File tree

8 files changed

+173
-72
lines changed

8 files changed

+173
-72
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"phpunit/phpcov": "^9.0.2 || ^10.0",
2929
"phpunit/phpunit": "^10.5.16 || ^11.2",
3030
"predis/predis": "^1.1 || ^2.0",
31-
"rector/rector": "1.2.2"
31+
"rector/rector": "1.2.3"
3232
},
3333
"replace": {
3434
"codeigniter4/framework": "self.version"

phpstan-baseline.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15625,30 +15625,6 @@
1562515625
'count' => 2,
1562615626
'path' => __DIR__ . '/tests/system/Images/ImageMagickHandlerTest.php',
1562715627
];
15628-
$ignoreErrors[] = [
15629-
// identifier: method.notFound
15630-
'message' => '#^Call to an undefined method CodeIgniter\\\\Language\\\\Language\\:\\:disableIntlSupport\\(\\)\\.$#',
15631-
'count' => 1,
15632-
'path' => __DIR__ . '/tests/system/Language/LanguageTest.php',
15633-
];
15634-
$ignoreErrors[] = [
15635-
// identifier: method.notFound
15636-
'message' => '#^Call to an undefined method CodeIgniter\\\\Language\\\\Language\\:\\:loaded\\(\\)\\.$#',
15637-
'count' => 3,
15638-
'path' => __DIR__ . '/tests/system/Language/LanguageTest.php',
15639-
];
15640-
$ignoreErrors[] = [
15641-
// identifier: method.notFound
15642-
'message' => '#^Call to an undefined method CodeIgniter\\\\Language\\\\Language\\:\\:loadem\\(\\)\\.$#',
15643-
'count' => 2,
15644-
'path' => __DIR__ . '/tests/system/Language/LanguageTest.php',
15645-
];
15646-
$ignoreErrors[] = [
15647-
// identifier: method.notFound
15648-
'message' => '#^Call to an undefined method CodeIgniter\\\\Language\\\\Language\\:\\:setData\\(\\)\\.$#',
15649-
'count' => 9,
15650-
'path' => __DIR__ . '/tests/system/Language/LanguageTest.php',
15651-
];
1565215628
$ignoreErrors[] = [
1565315629
// identifier: missingType.iterableValue
1565415630
'message' => '#^Method CodeIgniter\\\\Language\\\\LanguageTest\\:\\:provideBundleUniqueKeys\\(\\) return type has no value type specified in iterable type iterable\\.$#',

preload.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,25 @@ class preload
3838
[
3939
'include' => __DIR__ . '/vendor/codeigniter4/framework/system', // Change this path if using manual installation
4040
'exclude' => [
41-
'/system/bootstrap.php',
4241
// Not needed if you don't use them.
4342
'/system/Database/OCI8/',
4443
'/system/Database/Postgre/',
4544
'/system/Database/SQLite3/',
4645
'/system/Database/SQLSRV/',
47-
// Not needed.
46+
// Not needed for web apps.
4847
'/system/Database/Seeder.php',
4948
'/system/Test/',
50-
'/system/Language/',
5149
'/system/CLI/',
5250
'/system/Commands/',
5351
'/system/Publisher/',
5452
'/system/ComposerScripts.php',
53+
// Not Class/Function files.
54+
'/system/Config/Routes.php',
55+
'/system/Language/',
56+
'/system/bootstrap.php',
57+
'/system/rewrite.php',
5558
'/Views/',
5659
// Errors occur.
57-
'/system/Config/Routes.php',
5860
'/system/ThirdParty/',
5961
],
6062
],

system/Common.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use CodeIgniter\HTTP\RedirectResponse;
3131
use CodeIgniter\HTTP\RequestInterface;
3232
use CodeIgniter\HTTP\ResponseInterface;
33+
use CodeIgniter\Language\Language;
3334
use CodeIgniter\Model;
3435
use CodeIgniter\Session\Session;
3536
use CodeIgniter\Test\TestLogger;
@@ -734,6 +735,7 @@ function is_windows(?bool $mock = null): bool
734735
*/
735736
function lang(string $line, array $args = [], ?string $locale = null)
736737
{
738+
/** @var Language $language */
737739
$language = service('language');
738740

739741
// Get active locale

tests/system/Language/LanguageTest.php

Lines changed: 89 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ final class LanguageTest extends CIUnitTestCase
3131

3232
protected function setUp(): void
3333
{
34-
$this->lang = new MockLanguage('en');
34+
$this->lang = new Language('en');
3535
}
3636

3737
public function testReturnsStringWithNoFileInMessage(): void
@@ -54,6 +54,8 @@ public function testReturnParsedStringWithNoFileInMessage(): void
5454

5555
public function testGetLineReturnsLine(): void
5656
{
57+
$this->lang = new MockLanguage('en');
58+
5759
$this->lang->setData('books', [
5860
'bookSaved' => 'We kept the book free from the boogeyman',
5961
'booksSaved' => 'We saved some more',
@@ -62,8 +64,67 @@ public function testGetLineReturnsLine(): void
6264
$this->assertSame('We saved some more', $this->lang->getLine('books.booksSaved'));
6365
}
6466

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+
65124
public function testGetLineReturnsFallbackLine(): void
66125
{
126+
$this->lang = new MockLanguage('en');
127+
67128
$this->lang
68129
->setLocale('en-US')
69130
->setData('equivalent', [
@@ -86,6 +147,8 @@ public function testGetLineReturnsFallbackLine(): void
86147

87148
public function testGetLineArrayReturnsLineArray(): void
88149
{
150+
$this->lang = new MockLanguage('en');
151+
89152
$this->lang->setData('books', [
90153
'booksList' => [
91154
'The Boogeyman',
@@ -106,6 +169,8 @@ public function testGetLineFormatsMessage(): void
106169
$this->markTestSkipped('No intl support.');
107170
}
108171

172+
$this->lang = new MockLanguage('en');
173+
109174
$this->lang->setData('books', [
110175
'bookCount' => '{0, number, integer} books have been saved.',
111176
]);
@@ -120,6 +185,8 @@ public function testGetLineArrayFormatsMessages(): void
120185
$this->markTestSkipped('No intl support.');
121186
}
122187

188+
$this->lang = new MockLanguage('en');
189+
123190
$this->lang->setData('books', [
124191
'bookList' => [
125192
'{0, number, integer} related books.',
@@ -139,6 +206,8 @@ public function testGetLineInvalidFormatMessage(): void
139206
$this->markTestSkipped('No intl support.');
140207
}
141208

209+
$this->lang = new MockLanguage('en');
210+
142211
$this->lang->setLocale('ar');
143212

144213
$line = 'تم الكشف عن كلمة المرور {0} بسبب اختراق البيانات وشوهدت {1 ، عدد} مرة في {2} في كلمات المرور المخترقة.';
@@ -163,6 +232,8 @@ public function testLangAllowsOtherLocales(): void
163232

164233
public function testLangDoesntFormat(): void
165234
{
235+
$this->lang = new MockLanguage('en');
236+
166237
$this->lang->disableIntlSupport();
167238

168239
$this->lang->setData('books', [
@@ -185,40 +256,42 @@ public function testLanguageDuplicateKey(): void
185256

186257
public function testLanguageFileLoading(): void
187258
{
188-
$this->lang = new SecondMockLanguage('en');
259+
$lang = new SecondMockLanguage('en');
189260

190-
$this->lang->loadem('More', 'en');
191-
$this->assertContains('More', $this->lang->loaded());
261+
$lang->loadem('More', 'en');
262+
$this->assertContains('More', $lang->loaded());
192263

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
195266
}
196267

197268
public function testLanguageFileLoadingReturns(): void
198269
{
199-
$this->lang = new SecondMockLanguage('en');
270+
$lang = new SecondMockLanguage('en');
200271

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());
203274
$this->assertCount(3, $result);
204275

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());
208279
}
209280

210281
public function testLanguageSameKeyAndFileName(): void
211282
{
283+
$lang = new MockLanguage('en');
284+
212285
// 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']);
214287

215288
// 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'));
217290

218291
// second file data | another.example
219-
$this->lang->setData('another', ['example' => 'Another example']);
292+
$lang->setData('another', ['example' => 'Another example']);
220293

221-
$this->assertSame('Another example', $this->lang->getLine('another.example'));
294+
$this->assertSame('Another example', $lang->getLine('another.example'));
222295
}
223296

224297
public function testGetLocale(): void

0 commit comments

Comments
 (0)