Skip to content

Commit 35aa70e

Browse files
committed
Add additional tests for array args.
Add tests for translation helpers with array arguments. These tests were missing before and should help prevent regressions while #10087 is solved.
1 parent 9fff233 commit 35aa70e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/TestCase/I18n/I18nTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ public function testBasicTranslateFunction()
242242
I18n::defaultFormatter('sprintf');
243243
$this->assertEquals('%d is 1 (po translated)', __('%d = 1'));
244244
$this->assertEquals('1 is 1 (po translated)', __('%d = 1', 1));
245+
$this->assertEquals('1 is 1 (po translated)', __('%d = 1', [1]));
246+
$this->assertEquals('The red dog, and blue cat', __('The %s dog, and %s cat', ['red', 'blue']));
247+
$this->assertEquals('The red dog, and blue cat', __('The %s dog, and %s cat', 'red', 'blue'));
245248
}
246249

247250
/**
@@ -268,6 +271,12 @@ public function testBasicTranslatePluralFunction()
268271

269272
$result = __n('singular msg', '%d = 0 or > 1', 2);
270273
$this->assertEquals('2 is 2-4 (po translated)', $result);
274+
275+
$result = __n('%s %s and %s are good', '%s and %s are best', 1, ['red', 'blue']);
276+
$this->assertEquals('1 red and blue are good', $result);
277+
278+
$result = __n('%s %s and %s are good', '%s and %s are best', 1, 'red', 'blue');
279+
$this->assertEquals('1 red and blue are good', $result);
271280
}
272281

273282
/**
@@ -292,6 +301,9 @@ public function testBasicDomainFunction()
292301
$result = __d('custom', 'The {0} is tasty', ['fruit']);
293302
$this->assertEquals('The fruit is delicious', $result);
294303

304+
$result = __d('custom', 'The {0} is tasty', 'fruit');
305+
$this->assertEquals('The fruit is delicious', $result);
306+
295307
$result = __d('custom', 'Average price {0}', ['9.99']);
296308
$this->assertEquals('Price Average 9.99', $result);
297309
}
@@ -355,6 +367,9 @@ public function testBasicContextFunction()
355367
$this->assertEquals('The letters A and B', __x('character', 'letters', ['A', 'B']));
356368
$this->assertEquals('The letter A', __x('character', 'letter', ['A']));
357369

370+
$this->assertEquals('The letters A and B', __x('character', 'letters', 'A', 'B'));
371+
$this->assertEquals('The letter A', __x('character', 'letter', 'A'));
372+
358373
$this->assertEquals(
359374
'She wrote a letter to Thomas and Sara',
360375
__x('communication', 'letters', ['Thomas', 'Sara'])

0 commit comments

Comments
 (0)