I18nShellTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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' . DS;
  46. unlink($this->localeDir . 'default.pot');
  47. unlink($this->localeDir . 'cake.pot');
  48. unlink($deDir . 'default.po');
  49. unlink($deDir . 'cake.po');
  50. }
  51. /**
  52. * Tests that init() creates the PO files from POT files.
  53. *
  54. * @return void
  55. */
  56. public function testInit()
  57. {
  58. $deDir = $this->localeDir . 'de' . DS;
  59. if (!is_dir($deDir)) {
  60. mkdir($deDir, 0770, true);
  61. }
  62. file_put_contents($this->localeDir . 'default.pot', 'Testing POT file.');
  63. file_put_contents($this->localeDir . 'cake.pot', 'Testing POT file.');
  64. if (file_exists($deDir . 'default.po')) {
  65. unlink($deDir . 'default.po');
  66. }
  67. if (file_exists($deDir . 'default.po')) {
  68. unlink($deDir . 'cake.po');
  69. }
  70. $this->shell->io()->expects($this->at(0))
  71. ->method('ask')
  72. ->will($this->returnValue('de'));
  73. $this->shell->io()->expects($this->at(1))
  74. ->method('ask')
  75. ->will($this->returnValue($this->localeDir));
  76. $this->shell->params['verbose'] = true;
  77. $this->shell->init();
  78. $this->assertFileExists($deDir . 'default.po');
  79. $this->assertFileExists($deDir . 'cake.po');
  80. }
  81. }