I18nShellTest.php 3.0 KB

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