I18nShellTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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.8
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\Shell;
  16. use Cake\Shell\I18nShell;
  17. use Cake\TestSuite\TestCase;
  18. /**
  19. * I18nShell test.
  20. */
  21. class I18nShellTest extends TestCase
  22. {
  23. /**
  24. * setup method
  25. *
  26. * @return void
  27. */
  28. public function setUp()
  29. {
  30. parent::setUp();
  31. $this->io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
  32. $this->shell = new I18nShell($this->io);
  33. $this->localeDir = TMP . 'Locale' . DS;
  34. }
  35. /**
  36. * Teardown
  37. *
  38. * @return void
  39. */
  40. public function tearDown()
  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->shell->io()->expects($this->at(0))
  73. ->method('ask')
  74. ->will($this->returnValue('de_DE'));
  75. $this->shell->io()->expects($this->at(1))
  76. ->method('ask')
  77. ->will($this->returnValue($this->localeDir));
  78. $this->shell->params['verbose'] = true;
  79. $this->shell->init();
  80. $this->assertFileExists($deDir . 'default.po');
  81. $this->assertFileExists($deDir . 'cake.po');
  82. }
  83. /**
  84. * Test that the option parser is shaped right.
  85. *
  86. * @return void
  87. */
  88. public function testGetOptionParser()
  89. {
  90. $this->shell->loadTasks();
  91. $parser = $this->shell->getOptionParser();
  92. $this->assertArrayHasKey('init', $parser->subcommands());
  93. $this->assertArrayHasKey('extract', $parser->subcommands());
  94. }
  95. }