Browse Source

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.
Mark Story 9 years ago
parent
commit
35aa70e6bb
1 changed files with 15 additions and 0 deletions
  1. 15 0
      tests/TestCase/I18n/I18nTest.php

+ 15 - 0
tests/TestCase/I18n/I18nTest.php

@@ -242,6 +242,9 @@ class I18nTest extends TestCase
         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'));
     }
 
     /**
@@ -268,6 +271,12 @@ class I18nTest extends TestCase
 
         $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);
     }
 
     /**
@@ -292,6 +301,9 @@ class I18nTest extends TestCase
         $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);
     }
@@ -355,6 +367,9 @@ class I18nTest extends TestCase
         $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'])