@@ -238,48 +238,69 @@ public function exportWithJsonAndMarkupTextAttributeDataProvider(): array
238
238
239
239
/**
240
240
* @magentoDataFixture Magento/CatalogImportExport/_files/product_export_data_special_chars.php
241
- * @magentoDbIsolation disabled
241
+ * @magentoDbIsolation enabled
242
242
*
243
243
* @return void
244
244
* @throws NoSuchEntityException
245
245
*/
246
246
public function testExportSpecialChars (): void
247
247
{
248
+ /** @var \Magento\Catalog\Model\Product $product */
248
249
$ product = $ this ->productRepository ->get ('simple "1" ' );
249
250
$ product ->setStoreId (Store::DEFAULT_STORE_ID );
250
251
$ product ->setDescription ('Description with <h2>this is test page</h2> ' );
251
- $ product -> save ();
252
+ $ this -> productRepository -> save ($ product );
252
253
253
254
$ this ->model ->setWriter (
254
255
$ this ->objectManager ->create (
255
256
\Magento \ImportExport \Model \Export \Adapter \Csv::class
256
257
)
257
258
);
258
259
$ exportData = $ this ->model ->export ();
260
+ $ rows = $ this ->csvToArray ($ exportData );
259
261
260
- $ this ->assertStringContainsString ('simple "1" ' , $ exportData );
262
+ $ this ->assertCount (4 , $ rows );
263
+ $ this ->assertEquals ('simple "1" ' , $ rows [0 ]['sku ' ]);
264
+ $ this ->assertEquals ('Description with <h2>this is test page</h2> ' , $ rows [0 ]['description ' ]);
261
265
$ 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 ));
266
+ $ this ->assertFalse ($ this ->hasDuplicateRowsForProducts ($ rows ));
265
267
}
266
268
267
269
/**
268
270
* Verify exported data does not contain duplicate rows for product
269
271
*
270
- * @param $exportData
272
+ * @param $rows
271
273
* @return bool
272
274
*/
273
- private function hasDuplicateRowsForProducts ($ exportData ): bool
275
+ private function hasDuplicateRowsForProducts ($ rows ): bool
274
276
{
275
277
$ skus = [];
276
- foreach (explode ( "\n" , $ exportData , - 1 ) as $ line ) {
277
- $ skus [] = current ( explode ( ' , ' , $ line )) ;
278
+ foreach ($ rows as $ product ) {
279
+ $ skus [] = $ product [ ' sku ' ] ;
278
280
}
279
- array_shift ($ skus );
280
281
return count ($ skus ) !== count (array_flip ($ skus ));
281
282
}
282
283
284
+ /**
285
+ * Converts comma separated csv data to array
286
+ *
287
+ * @param $exportData
288
+ * @return array
289
+ */
290
+ private function csvToArray ($ exportData ): array
291
+ {
292
+ $ rows = [];
293
+ $ headers = [];
294
+ foreach (str_getcsv ($ exportData , "\n" ) as $ row ) {
295
+ if (!$ headers ) {
296
+ $ headers = str_getcsv ($ row );
297
+ } else {
298
+ $ rows [] = array_combine ($ headers , str_getcsv ($ row ));
299
+ }
300
+ }
301
+ return $ rows ;
302
+ }
303
+
283
304
/**
284
305
* @magentoDataFixture Magento/CatalogImportExport/_files/product_export_with_product_links_data.php
285
306
* @magentoDbIsolation enabled
0 commit comments