Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SourcesTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
14 use PHPUnit\Framework\TestCase;
15 
16 class SourcesTest extends TestCase
17 {
21  private $exporter;
22 
26  private $exportFilePath;
27 
28  protected function setUp()
29  {
30  $sandboxDir = Bootstrap::getInstance()->getBootstrap()->getApplication()->getTempDir();
31  $this->exportFilePath = implode(DIRECTORY_SEPARATOR, [
32  $sandboxDir,
33  'var',
34  uniqid('test-export_', false) . '.csv'
35  ]);
36 
37  $this->exporter = Bootstrap::getObjectManager()->create(Sources::class);
38  $this->exporter->setWriter(Bootstrap::getObjectManager()->create(
39  Csv::class,
40  ['destination' => $this->exportFilePath]
41  ));
42  }
43 
44  protected function tearDown()
45  {
46  unlink($this->exportFilePath);
47  }
48 
57  {
58  $this->exporter->setParameters([]);
59  $this->exporter->export();
60 
61  $exportFullLines = file(
62  implode(DIRECTORY_SEPARATOR, [__DIR__, '_files', 'export_full.csv']),
63  FILE_IGNORE_NEW_LINES
64  );
65 
66  foreach ($exportFullLines as $line) {
67  $this->assertContains(
68  $line,
69  file_get_contents($this->exportFilePath)
70  );
71  }
72  }
73 
81  public function testExportWithSkuFilter()
82  {
83  $this->exporter->setParameters([
85  'sku' => 'SKU-1'
86  ]
87  ]);
88  $this->exporter->export();
89 
90  $this->assertEquals(
91  file_get_contents(implode(DIRECTORY_SEPARATOR, [__DIR__, '_files', 'export_filtered_by_sku.csv'])),
92  file_get_contents($this->exportFilePath)
93  );
94  }
95 
104  {
105  $this->exporter->setParameters([
107  'sku' => 'U-1'
108  ]
109  ]);
110  $this->exporter->export();
111 
112  $this->assertEquals(
113  file_get_contents(implode(DIRECTORY_SEPARATOR, [__DIR__, '_files', 'export_filtered_by_sku.csv'])),
114  file_get_contents($this->exportFilePath)
115  );
116  }
117 
125  public function testExportWithSourceFilter()
126  {
127  $this->exporter->setParameters([
129  'source_code' => 'eu'
130  ]
131  ]);
132  $this->exporter->export();
133 
134  $this->assertEquals(
135  file_get_contents(implode(DIRECTORY_SEPARATOR, [__DIR__, '_files', 'export_filtered_by_source.csv'])),
136  file_get_contents($this->exportFilePath)
137  );
138  }
139 
148  {
149  $this->exporter->setParameters([
151  'sku' => 'SKU-1',
152  'status' => 1
153  ],
155  'status'
156  ]
157  ]);
158  $this->exporter->export();
159 
160  $this->assertEquals(
161  file_get_contents(implode(DIRECTORY_SEPARATOR, [
162  __DIR__,
163  '_files',
164  'export_filtered_without_status_column.csv'
165  ])),
166  file_get_contents($this->exportFilePath)
167  );
168  }
169 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60