|
8 | 8 |
|
9 | 9 | namespace Magento\CatalogImportExport\Model\Export;
|
10 | 10 |
|
11 |
| -use Magento\Catalog\Api\ProductRepositoryInterface; |
12 | 11 | use Magento\Catalog\Api\CategoryRepositoryInterface;
|
| 12 | +use Magento\Catalog\Api\ProductRepositoryInterface; |
13 | 13 | use Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection as ProductAttributeCollection;
|
14 | 14 | use Magento\Catalog\Observer\SwitchPriceAttributeScopeOnConfigChange;
|
15 | 15 | use Magento\Catalog\Test\Fixture\Category as CategoryFixture;
|
|
19 | 19 | use Magento\CatalogInventory\Api\StockItemRepositoryInterface;
|
20 | 20 | use Magento\CatalogInventory\Model\Stock\Item;
|
21 | 21 | use Magento\Framework\App\Config\ReinitableConfigInterface;
|
| 22 | +use Magento\Framework\Exception\NoSuchEntityException; |
| 23 | +use Magento\Store\Model\Store; |
22 | 24 | use Magento\Store\Model\StoreManagerInterface;
|
23 | 25 | use Magento\Store\Test\Fixture\Store as StoreFixture;
|
24 | 26 | use Magento\TestFramework\Fixture\AppArea;
|
@@ -139,29 +141,6 @@ public function testExport(): void
|
139 | 141 | $this->assertEquals(1, $occurrencesCount);
|
140 | 142 | }
|
141 | 143 |
|
142 |
| - /** |
143 |
| - * Verify successful export of product with HTML tag |
144 |
| - * |
145 |
| - * @magentoDataFixture Magento/CatalogImportExport/_files/product_export_data_special_chars.php |
146 |
| - * @magentoDbIsolation enabled |
147 |
| - * |
148 |
| - * @return void |
149 |
| - */ |
150 |
| - public function testExportBehaviour(): void |
151 |
| - { |
152 |
| - $product = $this->productRepository->get('simple "1"'); |
153 |
| - $product->setDescription('Description with <h2>this is test page</h2>'); |
154 |
| - $product->save(); |
155 |
| - $this->model->setWriter( |
156 |
| - $this->objectManager->create( |
157 |
| - \Magento\ImportExport\Model\Export\Adapter\Csv::class |
158 |
| - ) |
159 |
| - ); |
160 |
| - $exportData = $this->model->export(); |
161 |
| - $this->assertStringContainsString('New Product', $exportData); |
162 |
| - $this->assertStringContainsString('Description with <h2>this is test page</h2>', $exportData); |
163 |
| - } |
164 |
| - |
165 | 144 | /**
|
166 | 145 | * Verify successful export of product with stock data with 'use config max sale quantity is enabled
|
167 | 146 | *
|
@@ -259,20 +238,46 @@ public function exportWithJsonAndMarkupTextAttributeDataProvider(): array
|
259 | 238 |
|
260 | 239 | /**
|
261 | 240 | * @magentoDataFixture Magento/CatalogImportExport/_files/product_export_data_special_chars.php
|
262 |
| - * @magentoDbIsolation enabled |
| 241 | + * @magentoDbIsolation disabled |
263 | 242 | *
|
264 | 243 | * @return void
|
| 244 | + * @throws NoSuchEntityException |
265 | 245 | */
|
266 | 246 | public function testExportSpecialChars(): void
|
267 | 247 | {
|
| 248 | + $product = $this->productRepository->get('simple "1"'); |
| 249 | + $product->setStoreId(Store::DEFAULT_STORE_ID); |
| 250 | + $product->setDescription('Description with <h2>this is test page</h2>'); |
| 251 | + $product->save(); |
| 252 | + |
268 | 253 | $this->model->setWriter(
|
269 | 254 | $this->objectManager->create(
|
270 | 255 | \Magento\ImportExport\Model\Export\Adapter\Csv::class
|
271 | 256 | )
|
272 | 257 | );
|
273 | 258 | $exportData = $this->model->export();
|
| 259 | + |
274 | 260 | $this->assertStringContainsString('simple "1"', $exportData);
|
275 | 261 | $this->assertStringContainsString('Category with slash\/ symbol', $exportData);
|
| 262 | + $this->assertStringContainsString('New Product', $exportData); |
| 263 | + $this->assertStringContainsString('Description with <h2>this is test page</h2>', $exportData); |
| 264 | + $this->assertFalse($this->hasDuplicateRowsForProducts($exportData)); |
| 265 | + } |
| 266 | + |
| 267 | + /** |
| 268 | + * Verify exported data does not contain duplicate rows for product |
| 269 | + * |
| 270 | + * @param $exportData |
| 271 | + * @return bool |
| 272 | + */ |
| 273 | + private function hasDuplicateRowsForProducts($exportData): bool |
| 274 | + { |
| 275 | + $skus = []; |
| 276 | + foreach (explode("\n", $exportData, -1) as $line) { |
| 277 | + $skus[] = current(explode(',', $line)); |
| 278 | + } |
| 279 | + array_shift($skus); |
| 280 | + return count($skus) !== count(array_flip($skus)); |
276 | 281 | }
|
277 | 282 |
|
278 | 283 | /**
|
|
0 commit comments