L10nLegacyTest.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Thomas Müller <thomas.mueller@tmit.eu>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace Test\L10N;
  9. use OC_L10N;
  10. use DateTime;
  11. /**
  12. * Class Test_L10n
  13. */
  14. class L10nLegacyTest extends \Test\TestCase {
  15. public function testGermanPluralTranslations() {
  16. $l = new OC_L10N('test');
  17. $transFile = \OC::$SERVERROOT.'/tests/data/l10n/de.json';
  18. $l->load($transFile);
  19. $this->assertEquals('1 Datei', (string)$l->n('%n file', '%n files', 1));
  20. $this->assertEquals('2 Dateien', (string)$l->n('%n file', '%n files', 2));
  21. }
  22. public function testRussianPluralTranslations() {
  23. $l = new OC_L10N('test');
  24. $transFile = \OC::$SERVERROOT.'/tests/data/l10n/ru.json';
  25. $l->load($transFile);
  26. $this->assertEquals('1 файл', (string)$l->n('%n file', '%n files', 1));
  27. $this->assertEquals('2 файла', (string)$l->n('%n file', '%n files', 2));
  28. $this->assertEquals('6 файлов', (string)$l->n('%n file', '%n files', 6));
  29. $this->assertEquals('21 файл', (string)$l->n('%n file', '%n files', 21));
  30. $this->assertEquals('22 файла', (string)$l->n('%n file', '%n files', 22));
  31. $this->assertEquals('26 файлов', (string)$l->n('%n file', '%n files', 26));
  32. /*
  33. 1 file 1 файл 1 папка
  34. 2-4 files 2-4 файла 2-4 папки
  35. 5-20 files 5-20 файлов 5-20 папок
  36. 21 files 21 файл 21 папка
  37. 22-24 files 22-24 файла 22-24 папки
  38. 25-30 files 25-30 файлов 25-30 папок
  39. etc
  40. 100 files 100 файлов, 100 папок
  41. 1000 files 1000 файлов 1000 папок
  42. */
  43. }
  44. public function testCzechPluralTranslations() {
  45. $l = new OC_L10N('test');
  46. $transFile = \OC::$SERVERROOT.'/tests/data/l10n/cs.json';
  47. $l->load($transFile);
  48. $this->assertEquals('1 okno', (string)$l->n('%n window', '%n windows', 1));
  49. $this->assertEquals('2 okna', (string)$l->n('%n window', '%n windows', 2));
  50. $this->assertEquals('5 oken', (string)$l->n('%n window', '%n windows', 5));
  51. }
  52. public function localizationDataProvider() {
  53. return array(
  54. // timestamp as string
  55. array('February 13, 2009 at 11:31:30 PM GMT+0', 'en', 'datetime', '1234567890'),
  56. array('13. Februar 2009 um 23:31:30 GMT+0', 'de', 'datetime', '1234567890'),
  57. array('February 13, 2009', 'en', 'date', '1234567890'),
  58. array('13. Februar 2009', 'de', 'date', '1234567890'),
  59. array('11:31:30 PM GMT+0', 'en', 'time', '1234567890'),
  60. array('23:31:30 GMT+0', 'de', 'time', '1234567890'),
  61. // timestamp as int
  62. array('February 13, 2009 at 11:31:30 PM GMT+0', 'en', 'datetime', 1234567890),
  63. array('13. Februar 2009 um 23:31:30 GMT+0', 'de', 'datetime', 1234567890),
  64. array('February 13, 2009', 'en', 'date', 1234567890),
  65. array('13. Februar 2009', 'de', 'date', 1234567890),
  66. array('11:31:30 PM GMT+0', 'en', 'time', 1234567890),
  67. array('23:31:30 GMT+0', 'de', 'time', 1234567890),
  68. // DateTime object
  69. array('February 13, 2009 at 11:31:30 PM GMT+0', 'en', 'datetime', new DateTime('@1234567890')),
  70. array('13. Februar 2009 um 23:31:30 GMT+0', 'de', 'datetime', new DateTime('@1234567890')),
  71. array('February 13, 2009', 'en', 'date', new DateTime('@1234567890')),
  72. array('13. Februar 2009', 'de', 'date', new DateTime('@1234567890')),
  73. array('11:31:30 PM GMT+0', 'en', 'time', new DateTime('@1234567890')),
  74. array('23:31:30 GMT+0', 'de', 'time', new DateTime('@1234567890')),
  75. // en_GB
  76. array('13 February 2009 at 23:31:30 GMT+0', 'en_GB', 'datetime', new DateTime('@1234567890')),
  77. array('13 February 2009', 'en_GB', 'date', new DateTime('@1234567890')),
  78. array('23:31:30 GMT+0', 'en_GB', 'time', new DateTime('@1234567890')),
  79. array('13 February 2009 at 23:31:30 GMT+0', 'en-GB', 'datetime', new DateTime('@1234567890')),
  80. array('13 February 2009', 'en-GB', 'date', new DateTime('@1234567890')),
  81. array('23:31:30 GMT+0', 'en-GB', 'time', new DateTime('@1234567890')),
  82. );
  83. }
  84. /**
  85. * @dataProvider localizationDataProvider
  86. */
  87. public function testNumericStringLocalization($expectedDate, $lang, $type, $value) {
  88. $l = new OC_L10N('test', $lang);
  89. $this->assertSame($expectedDate, $l->l($type, $value));
  90. }
  91. public function firstDayDataProvider() {
  92. return array(
  93. array(1, 'de'),
  94. array(0, 'en'),
  95. );
  96. }
  97. /**
  98. * @dataProvider firstDayDataProvider
  99. * @param $expected
  100. * @param $lang
  101. */
  102. public function testFirstWeekDay($expected, $lang) {
  103. $l = new OC_L10N('test', $lang);
  104. $this->assertSame($expected, $l->l('firstday', 'firstday'));
  105. }
  106. public function testFactoryGetLanguageCode() {
  107. $factory = new \OC\L10N\Factory(
  108. $this->getMockBuilder('OCP\IConfig')->getMock(),
  109. $this->getMockBuilder('OCP\IRequest')->getMock(),
  110. $this->getMockBuilder('OCP\IUserSession')->getMock(),
  111. \OC::$SERVERROOT);
  112. $l = $factory->get('lib', 'de');
  113. $this->assertEquals('de', $l->getLanguageCode());
  114. }
  115. public function testServiceGetLanguageCode() {
  116. $l = \OC::$server->getL10N('lib', 'de');
  117. $this->assertEquals('de', $l->getLanguageCode());
  118. }
  119. }