I18nCommandTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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\ConsoleIntegrationTestTrait;
  18. use Cake\TestSuite\TestCase;
  19. /**
  20. * I18nCommand test.
  21. */
  22. class I18nCommandTest extends TestCase
  23. {
  24. use ConsoleIntegrationTestTrait;
  25. /**
  26. * @var string
  27. */
  28. protected $localeDir;
  29. /**
  30. * setup method
  31. */
  32. public function setUp(): void
  33. {
  34. parent::setUp();
  35. $this->localeDir = TMP . 'Locale' . DS;
  36. $this->useCommandRunner();
  37. $this->setAppNamespace();
  38. }
  39. /**
  40. * Teardown
  41. */
  42. public function tearDown(): void
  43. {
  44. parent::tearDown();
  45. $deDir = $this->localeDir . 'de_DE' . DS;
  46. if (file_exists($this->localeDir . 'default.pot')) {
  47. unlink($this->localeDir . 'default.pot');
  48. unlink($this->localeDir . 'cake.pot');
  49. }
  50. if (file_exists($deDir . 'default.po')) {
  51. unlink($deDir . 'default.po');
  52. unlink($deDir . 'cake.po');
  53. }
  54. }
  55. /**
  56. * Tests that init() creates the PO files from POT files.
  57. */
  58. public function testInit(): void
  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. public function testGetOptionParser(): void
  85. {
  86. $this->exec('i18n -h');
  87. $this->assertExitSuccess();
  88. $this->assertOutputContains('cake i18n');
  89. }
  90. /**
  91. * Tests main interactive mode
  92. */
  93. public function testInteractiveQuit(): void
  94. {
  95. $this->exec('i18n', ['q']);
  96. $this->assertExitSuccess();
  97. }
  98. /**
  99. * Tests main interactive mode
  100. */
  101. public function testInteractiveHelp(): void
  102. {
  103. $this->exec('i18n', ['h', 'q']);
  104. $this->assertExitSuccess();
  105. $this->assertOutputContains('cake i18n');
  106. }
  107. /**
  108. * Tests main interactive mode
  109. */
  110. public function testInteractiveInit(): void
  111. {
  112. $this->exec('i18n', [
  113. 'i',
  114. 'x',
  115. ]);
  116. $this->assertExitError();
  117. $this->assertErrorContains('Invalid language code');
  118. }
  119. }