I18nShellTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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\Shell;
  17. use Cake\Shell\I18nShell;
  18. use Cake\TestSuite\TestCase;
  19. /**
  20. * I18nShell test.
  21. */
  22. class I18nShellTest extends TestCase
  23. {
  24. /**
  25. * setup method
  26. *
  27. * @return void
  28. */
  29. public function setUp()
  30. {
  31. parent::setUp();
  32. $this->io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
  33. $this->shell = new I18nShell($this->io);
  34. $this->localeDir = TMP . 'Locale' . DS;
  35. }
  36. /**
  37. * Teardown
  38. *
  39. * @return void
  40. */
  41. public function tearDown()
  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. * @return void
  58. */
  59. public function testInit()
  60. {
  61. $deDir = $this->localeDir . 'de_DE' . DS;
  62. if (!is_dir($deDir)) {
  63. mkdir($deDir, 0770, true);
  64. }
  65. file_put_contents($this->localeDir . 'default.pot', 'Testing POT file.');
  66. file_put_contents($this->localeDir . 'cake.pot', 'Testing POT file.');
  67. if (file_exists($deDir . 'default.po')) {
  68. unlink($deDir . 'default.po');
  69. }
  70. if (file_exists($deDir . 'default.po')) {
  71. unlink($deDir . 'cake.po');
  72. }
  73. $this->shell->getIo()->expects($this->at(0))
  74. ->method('ask')
  75. ->will($this->returnValue('de_DE'));
  76. $this->shell->getIo()->expects($this->at(1))
  77. ->method('ask')
  78. ->will($this->returnValue($this->localeDir));
  79. $this->shell->params['verbose'] = true;
  80. $this->shell->init();
  81. $this->assertFileExists($deDir . 'default.po');
  82. $this->assertFileExists($deDir . 'cake.po');
  83. }
  84. /**
  85. * Test that the option parser is shaped right.
  86. *
  87. * @return void
  88. */
  89. public function testGetOptionParser()
  90. {
  91. $this->shell->loadTasks();
  92. $parser = $this->shell->getOptionParser();
  93. $this->assertArrayHasKey('init', $parser->subcommands());
  94. $this->assertArrayHasKey('extract', $parser->subcommands());
  95. }
  96. }