I18nCommandTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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->setAppNamespace();
  37. }
  38. /**
  39. * Teardown
  40. */
  41. public function tearDown(): void
  42. {
  43. parent::tearDown();
  44. $deDir = $this->localeDir . 'de_DE' . DS;
  45. if (file_exists($this->localeDir . 'default.pot')) {
  46. unlink($this->localeDir . 'default.pot');
  47. unlink($this->localeDir . 'cake.pot');
  48. }
  49. if (file_exists($deDir . 'default.po')) {
  50. unlink($deDir . 'default.po');
  51. unlink($deDir . 'cake.po');
  52. }
  53. }
  54. /**
  55. * Tests that init() creates the PO files from POT files.
  56. */
  57. public function testInit(): void
  58. {
  59. $deDir = $this->localeDir . 'de_DE' . DS;
  60. if (!is_dir($deDir)) {
  61. mkdir($deDir, 0770, true);
  62. }
  63. file_put_contents($this->localeDir . 'default.pot', 'Testing POT file.');
  64. file_put_contents($this->localeDir . 'cake.pot', 'Testing POT file.');
  65. if (file_exists($deDir . 'default.po')) {
  66. unlink($deDir . 'default.po');
  67. }
  68. if (file_exists($deDir . 'default.po')) {
  69. unlink($deDir . 'cake.po');
  70. }
  71. $this->exec('i18n init --verbose', [
  72. 'de_DE',
  73. $this->localeDir,
  74. ]);
  75. $this->assertExitSuccess();
  76. $this->assertOutputContains('Generated 2 PO files');
  77. $this->assertFileExists($deDir . 'default.po');
  78. $this->assertFileExists($deDir . 'cake.po');
  79. }
  80. /**
  81. * Test that the option parser is shaped right.
  82. */
  83. public function testGetOptionParser(): void
  84. {
  85. $this->exec('i18n -h');
  86. $this->assertExitSuccess();
  87. $this->assertOutputContains('cake i18n');
  88. }
  89. /**
  90. * Tests main interactive mode
  91. */
  92. public function testInteractiveQuit(): void
  93. {
  94. $this->exec('i18n', ['q']);
  95. $this->assertExitSuccess();
  96. }
  97. /**
  98. * Tests main interactive mode
  99. */
  100. public function testInteractiveHelp(): void
  101. {
  102. $this->exec('i18n', ['h', 'q']);
  103. $this->assertExitSuccess();
  104. $this->assertOutputContains('cake i18n');
  105. }
  106. /**
  107. * Tests main interactive mode
  108. */
  109. public function testInteractiveInit(): void
  110. {
  111. $this->exec('i18n', [
  112. 'i',
  113. 'x',
  114. ]);
  115. $this->assertExitError();
  116. $this->assertErrorContains('Invalid language code');
  117. }
  118. }