I18nCommandTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  5. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  6. *
  7. * Licensed under The MIT License
  8. * For full copyright and license information, please see the LICENSE.txt
  9. * Redistributions of files must retain the above copyright notice.
  10. *
  11. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  12. * @link https://cakephp.org CakePHP(tm) Project
  13. * @since 3.0.8
  14. * @license https://opensource.org/licenses/mit-license.php MIT License
  15. */
  16. namespace Cake\Test\TestCase\Command;
  17. use Cake\TestSuite\ConsoleIntegrationTestCase;
  18. /**
  19. * I18nCommand test.
  20. */
  21. class I18nCommandTest extends ConsoleIntegrationTestCase
  22. {
  23. /**
  24. * setup method
  25. *
  26. * @return void
  27. */
  28. public function setUp(): void
  29. {
  30. parent::setUp();
  31. $this->localeDir = TMP . 'Locale' . DS;
  32. $this->useCommandRunner();
  33. $this->setAppNamespace();
  34. }
  35. /**
  36. * Teardown
  37. *
  38. * @return void
  39. */
  40. public function tearDown(): void
  41. {
  42. parent::tearDown();
  43. $deDir = $this->localeDir . 'de_DE' . DS;
  44. if (file_exists($this->localeDir . 'default.pot')) {
  45. unlink($this->localeDir . 'default.pot');
  46. unlink($this->localeDir . 'cake.pot');
  47. }
  48. if (file_exists($deDir . 'default.po')) {
  49. unlink($deDir . 'default.po');
  50. unlink($deDir . 'cake.po');
  51. }
  52. }
  53. /**
  54. * Tests that init() creates the PO files from POT files.
  55. *
  56. * @return void
  57. */
  58. public function testInit()
  59. {
  60. $deDir = $this->localeDir . 'de_DE' . DS;
  61. if (!is_dir($deDir)) {
  62. mkdir($deDir, 0770, true);
  63. }
  64. file_put_contents($this->localeDir . 'default.pot', 'Testing POT file.');
  65. file_put_contents($this->localeDir . 'cake.pot', 'Testing POT file.');
  66. if (file_exists($deDir . 'default.po')) {
  67. unlink($deDir . 'default.po');
  68. }
  69. if (file_exists($deDir . 'default.po')) {
  70. unlink($deDir . 'cake.po');
  71. }
  72. $this->exec('i18n init --verbose', [
  73. 'de_DE',
  74. $this->localeDir,
  75. ]);
  76. $this->assertExitSuccess();
  77. $this->assertOutputContains('Generated 2 PO files');
  78. $this->assertFileExists($deDir . 'default.po');
  79. $this->assertFileExists($deDir . 'cake.po');
  80. }
  81. /**
  82. * Test that the option parser is shaped right.
  83. *
  84. * @return void
  85. */
  86. public function testGetOptionParser()
  87. {
  88. $this->exec('i18n -h');
  89. $this->assertExitSuccess();
  90. $this->assertOutputContains('cake i18n');
  91. }
  92. /**
  93. * Tests main interactive mode
  94. *
  95. * @return void
  96. */
  97. public function testInteractiveQuit()
  98. {
  99. $this->exec('i18n', ['q']);
  100. $this->assertExitSuccess();
  101. }
  102. /**
  103. * Tests main interactive mode
  104. *
  105. * @return void
  106. */
  107. public function testInteractiveHelp()
  108. {
  109. $this->exec('i18n', ['h', 'q']);
  110. $this->assertExitSuccess();
  111. $this->assertOutputContains('cake i18n');
  112. }
  113. /**
  114. * Tests main interactive mode
  115. *
  116. * @return void
  117. */
  118. public function testInteractiveInit()
  119. {
  120. $this->exec('i18n', [
  121. 'i',
  122. 'x',
  123. ]);
  124. $this->assertExitError();
  125. $this->assertErrorContains('Invalid language code');
  126. }
  127. }