SprintfFormatterTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since 3.0.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\I18n;
  16. use Cake\I18n\Formatter\SprintfFormatter;
  17. use Cake\TestSuite\TestCase;
  18. /**
  19. * SprintfFormatter tests
  20. *
  21. */
  22. class SprintfFormatterTest extends TestCase {
  23. /**
  24. * Tests that variables are interpolated correctly
  25. *
  26. * @return void
  27. */
  28. public function testFormatSimple() {
  29. $formatter = new SprintfFormatter();
  30. $this->assertEquals('Hello José', $formatter->format('en_US', 'Hello %s', ['José']));
  31. $this->assertEquals('1 Orange', $formatter->format('en_US', '%d %s', [1, 'Orange']));
  32. }
  33. /**
  34. * Tests that plural forms are selected for the passed locale
  35. *
  36. * @return void
  37. */
  38. public function testFormatPlural() {
  39. $formatter = new SprintfFormatter();
  40. $messages = ['%d is 0', '%d is 1', '%d is 2', '%d is 3', '%d > 11'];
  41. $this->assertEquals('1 is 1', $formatter->format('ar', $messages, ['_count' => 1]));
  42. $this->assertEquals('2 is 2', $formatter->format('ar', $messages, ['_count' => 2]));
  43. $this->assertEquals('20 > 11', $formatter->format('ar', $messages, ['_count' => 20]));
  44. }
  45. }