PoFileParserTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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\Parser;
  16. use Cake\I18n\Parser\PoFileParser;
  17. use Cake\TestSuite\TestCase;
  18. /**
  19. * Tests the PoFileLoader
  20. *
  21. */
  22. class PoFileParserTest extends TestCase {
  23. /**
  24. * Tests parsing a file with plurals and message context
  25. *
  26. * @return void
  27. */
  28. public function testParse() {
  29. $parser = new PoFileParser;
  30. $file = APP . 'Locale' . DS . 'rule_1_po' . DS . 'default.po';
  31. $messages = $parser->parse($file);
  32. $this->assertCount(5, $messages);
  33. $expected = [
  34. 'Plural Rule 1' => 'Plural Rule 1 (translated)',
  35. '%d = 1' => [
  36. '_context' => [
  37. 'This is the context' => 'First Context trasnlation',
  38. 'Another Context' => '%d = 1 (translated)'
  39. ]
  40. ],
  41. '%d = 0 or > 1' => [
  42. '_context' => [
  43. 'Another Context' => [
  44. 0 => '%d = 1 (translated)',
  45. 1 => '%d = 0 or > 1 (translated)'
  46. ]
  47. ]
  48. ],
  49. '%-5d = 1' => '%-5d = 1 (translated)',
  50. '%-5d = 0 or > 1' => [
  51. 0 => '%-5d = 1 (translated)',
  52. 1 => '',
  53. 2 => '',
  54. 3 => '',
  55. 4 => '%-5d = 0 or > 1 (translated)'
  56. ]
  57. ];
  58. $this->assertEquals($expected, $messages);
  59. }
  60. /**
  61. * Tests parsing a file with multiline keys and values
  62. *
  63. * @return void
  64. */
  65. public function testParseMultiLine() {
  66. $parser = new PoFileParser;
  67. $file = APP . 'Locale' . DS . 'en' . DS . 'default.po';
  68. $messages = $parser->parse($file);
  69. $this->assertCount(12, $messages);
  70. $this->assertTextEquals("v\nsecond line", $messages["valid\nsecond line"]);
  71. }
  72. /**
  73. * Test parsing a file with quoted strings
  74. *
  75. * @return void
  76. */
  77. public function testQuotedString() {
  78. $parser = new PoFileParser;
  79. $file = APP . 'Locale' . DS . 'en' . DS . 'default.po';
  80. $messages = $parser->parse($file);
  81. $this->assertTextEquals('this is a "quoted string" (translated)', $messages['this is a "quoted string"']);
  82. }
  83. }