Skip to content

Commit

Permalink
Add additional tests for array args.
Browse files Browse the repository at this point in the history
Add tests for translation helpers with array arguments. These tests were
missing before and should help prevent regressions while #10087 is
solved.
  • Loading branch information
markstory committed Jan 28, 2017
1 parent 9fff233 commit 35aa70e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/TestCase/I18n/I18nTest.php
Expand Up @@ -242,6 +242,9 @@ public function testBasicTranslateFunction()
I18n::defaultFormatter('sprintf');
$this->assertEquals('%d is 1 (po translated)', __('%d = 1'));
$this->assertEquals('1 is 1 (po translated)', __('%d = 1', 1));
$this->assertEquals('1 is 1 (po translated)', __('%d = 1', [1]));
$this->assertEquals('The red dog, and blue cat', __('The %s dog, and %s cat', ['red', 'blue']));
$this->assertEquals('The red dog, and blue cat', __('The %s dog, and %s cat', 'red', 'blue'));
}

/**
Expand All @@ -268,6 +271,12 @@ public function testBasicTranslatePluralFunction()

$result = __n('singular msg', '%d = 0 or > 1', 2);
$this->assertEquals('2 is 2-4 (po translated)', $result);

$result = __n('%s %s and %s are good', '%s and %s are best', 1, ['red', 'blue']);
$this->assertEquals('1 red and blue are good', $result);

$result = __n('%s %s and %s are good', '%s and %s are best', 1, 'red', 'blue');
$this->assertEquals('1 red and blue are good', $result);
}

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

$result = __d('custom', 'The {0} is tasty', 'fruit');
$this->assertEquals('The fruit is delicious', $result);

$result = __d('custom', 'Average price {0}', ['9.99']);
$this->assertEquals('Price Average 9.99', $result);
}
Expand Down Expand Up @@ -355,6 +367,9 @@ public function testBasicContextFunction()
$this->assertEquals('The letters A and B', __x('character', 'letters', ['A', 'B']));
$this->assertEquals('The letter A', __x('character', 'letter', ['A']));

$this->assertEquals('The letters A and B', __x('character', 'letters', 'A', 'B'));
$this->assertEquals('The letter A', __x('character', 'letter', 'A'));

$this->assertEquals(
'She wrote a letter to Thomas and Sara',
__x('communication', 'letters', ['Thomas', 'Sara'])
Expand Down

0 comments on commit 35aa70e

Please sign in to comment.