ResourcesMessageTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * Lithium: the most rad php framework
  4. *
  5. * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
  6. * @license http://opensource.org/licenses/bsd-license.php The BSD License
  7. */
  8. namespace lithium\tests\integration\g11n;
  9. use lithium\g11n\Catalog;
  10. /**
  11. * Test for integration of g11n resources. Numbers of rules refer to those documented in
  12. * the document on pluralization at Mozilla.
  13. *
  14. * @link https://developer.mozilla.org/en/Localization_and_Plurals
  15. */
  16. class ResourcesMessageTest extends \lithium\test\Integration {
  17. protected $_backup = array();
  18. public function setUp() {
  19. $this->_backup['catalogConfig'] = Catalog::config();
  20. Catalog::reset();
  21. Catalog::config(array(
  22. 'lithium' => array(
  23. 'adapter' => 'Php',
  24. 'path' => LITHIUM_LIBRARY_PATH . '/lithium/g11n/resources/php'
  25. )
  26. ));
  27. }
  28. public function tearDown() {
  29. Catalog::reset();
  30. Catalog::config($this->_backup['catalogConfig']);
  31. }
  32. /**
  33. * Tests the plural rule #1 which applies to the following languages
  34. * grouped by family and sorted alphabetically.
  35. *
  36. * Germanic family:
  37. * - English (en)
  38. * - German (de)
  39. *
  40. * @return void
  41. */
  42. public function testPlurals1() {
  43. $locales = array(
  44. 'en', 'de'
  45. );
  46. foreach ($locales as $locale) {
  47. $expected = 2;
  48. $result = Catalog::read(true, 'message.pluralForms', $locale);
  49. $this->assertEqual($expected, $result, "Locale: `{$locale}`\n{:message}");
  50. $rule = Catalog::read(true, 'message.pluralRule', $locale);
  51. $expected = '10111111111111111111111111111111111111111111111111';
  52. $expected .= '11111111111111111111111111111111111111111111111111';
  53. $expected .= '11111111111111111111111111111111111111111111111111';
  54. $expected .= '11111111111111111111111111111111111111111111111111';
  55. $result = '';
  56. for ($n = 0; $n < 200; $n++) {
  57. $result .= $rule($n);
  58. }
  59. $this->assertIdentical($expected, $result, "Locale: `{$locale}`\n{:message}");
  60. }
  61. }
  62. /**
  63. * Tests the plural rule #2 which applies to the following languages
  64. * grouped by family and sorted alphabetically.
  65. *
  66. * Romanic family:
  67. * - French (fr)
  68. *
  69. * @return void
  70. */
  71. public function testPlurals2() {
  72. $locales = array(
  73. 'fr'
  74. );
  75. foreach ($locales as $locale) {
  76. $expected = 2;
  77. $result = Catalog::read(true, 'message.pluralForms', $locale);
  78. $this->assertEqual($expected, $result, "Locale: `{$locale}`\n{:message}");
  79. $rule = Catalog::read(true, 'message.pluralRule', $locale);
  80. $expected = '00111111111111111111111111111111111111111111111111';
  81. $expected .= '11111111111111111111111111111111111111111111111111';
  82. $expected .= '11111111111111111111111111111111111111111111111111';
  83. $expected .= '11111111111111111111111111111111111111111111111111';
  84. $result = '';
  85. for ($n = 0; $n < 200; $n++) {
  86. $result .= $rule($n);
  87. }
  88. $this->assertIdentical($expected, $result, "Locale: `{$locale}`\n{:message}");
  89. }
  90. }
  91. }
  92. ?>