Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
I18nPackCommandTest.php
Go to the documentation of this file.
1 <?php
7 
8 use Symfony\Component\Console\Tester\CommandTester;
9 
13 class I18nPackCommandTest extends \PHPUnit\Framework\TestCase
14 {
18  private $command;
19 
23  private $tester;
24 
25  public function setUp()
26  {
27  $this->command = new I18nPackCommand();
28  $this->tester = new CommandTester($this->command);
29  }
30 
31  public function tearDown()
32  {
33  $this->removeCsv('A');
34  $this->removeCsv('B');
35  $this->removeCsv('C');
36  $this->removeCsv('D');
37  }
38 
39  private function removeCsv($module)
40  {
41  if (file_exists(__DIR__ . "/_files/root/app/code/Magento/{$module}/i18n")) {
42  $helper = new \Magento\Framework\Backup\Filesystem\Helper();
43  $helper->rm(__DIR__ . "/_files/root/app/code/Magento/{$module}/i18n", [], true);
44  }
45  }
46 
47  public function testExecute()
48  {
49  $this->tester->execute(
50  [
51  'source' => BP . '/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/i18n.csv',
52  'locale' => 'de_DE',
53  '--allow-duplicates' => true,
54  ]
55  );
56 
57  $this->assertEquals('Successfully saved de_DE language package.' . PHP_EOL, $this->tester->getDisplay());
58  $basePath = BP . '/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/root/app/code';
59  $this->assertFileExists($basePath . '/Magento/A/i18n/de_DE.csv');
60  $this->assertFileExists($basePath . '/Magento/B/i18n/de_DE.csv');
61  $this->assertFileExists($basePath . '/Magento/C/i18n/de_DE.csv');
62  $this->assertFileExists($basePath . '/Magento/D/i18n/de_DE.csv');
63  }
64 
69  public function testExecuteNonExistingPath()
70  {
71  $nonExistPath = BP . '/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/non_exist.csv';
72  $this->tester->execute(
73  [
74  'source' => $nonExistPath,
75  'locale' => 'de_DE',
76  '--allow-duplicates' => true,
77  ]
78  );
79  }
80 
85  public function testExecuteInvalidMode()
86  {
87  $this->tester->execute(
88  [
89  'source' => BP . '/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/i18n.csv',
90  'locale' => 'de_DE',
91  '--allow-duplicates' => true,
92  '--mode' => 'invalid'
93  ]
94  );
95  }
96 }
$helper
Definition: iframe.phtml:13
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
const BP
Definition: autoload.php:14