I18nPackCommandTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Setup\Console\Command;
  7. use Symfony\Component\Console\Tester\CommandTester;
  8. /**
  9. * @magentoComponentsDir Magento/Setup/Console/Command/_files/root/app/code
  10. */
  11. class I18nPackCommandTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var I18nCollectPhrasesCommand
  15. */
  16. private $command;
  17. /**
  18. * @var CommandTester
  19. */
  20. private $tester;
  21. public function setUp()
  22. {
  23. $this->command = new I18nPackCommand();
  24. $this->tester = new CommandTester($this->command);
  25. }
  26. public function tearDown()
  27. {
  28. $this->removeCsv('A');
  29. $this->removeCsv('B');
  30. $this->removeCsv('C');
  31. $this->removeCsv('D');
  32. }
  33. private function removeCsv($module)
  34. {
  35. if (file_exists(__DIR__ . "/_files/root/app/code/Magento/{$module}/i18n")) {
  36. $helper = new \Magento\Framework\Backup\Filesystem\Helper();
  37. $helper->rm(__DIR__ . "/_files/root/app/code/Magento/{$module}/i18n", [], true);
  38. }
  39. }
  40. public function testExecute()
  41. {
  42. $this->tester->execute(
  43. [
  44. 'source' => BP . '/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/i18n.csv',
  45. 'locale' => 'de_DE',
  46. '--allow-duplicates' => true,
  47. ]
  48. );
  49. $this->assertEquals('Successfully saved de_DE language package.' . PHP_EOL, $this->tester->getDisplay());
  50. $basePath = BP . '/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/root/app/code';
  51. $this->assertFileExists($basePath . '/Magento/A/i18n/de_DE.csv');
  52. $this->assertFileExists($basePath . '/Magento/B/i18n/de_DE.csv');
  53. $this->assertFileExists($basePath . '/Magento/C/i18n/de_DE.csv');
  54. $this->assertFileExists($basePath . '/Magento/D/i18n/de_DE.csv');
  55. }
  56. /**
  57. * @expectedException \InvalidArgumentException
  58. * @expectedExceptionMessage Cannot open dictionary file:
  59. */
  60. public function testExecuteNonExistingPath()
  61. {
  62. $nonExistPath = BP . '/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/non_exist.csv';
  63. $this->tester->execute(
  64. [
  65. 'source' => $nonExistPath,
  66. 'locale' => 'de_DE',
  67. '--allow-duplicates' => true,
  68. ]
  69. );
  70. }
  71. /**
  72. * @expectedException \InvalidArgumentException
  73. * @expectedExceptionMessage Possible values for 'mode' option are 'replace' and 'merge'
  74. */
  75. public function testExecuteInvalidMode()
  76. {
  77. $this->tester->execute(
  78. [
  79. 'source' => BP . '/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/i18n.csv',
  80. 'locale' => 'de_DE',
  81. '--allow-duplicates' => true,
  82. '--mode' => 'invalid'
  83. ]
  84. );
  85. }
  86. }