@@ -238,48 +238,69 @@ public function exportWithJsonAndMarkupTextAttributeDataProvider(): array
238238
239239 /**
240240 * @magentoDataFixture Magento/CatalogImportExport/_files/product_export_data_special_chars.php
241- * @magentoDbIsolation disabled
241+ * @magentoDbIsolation enabled
242242 *
243243 * @return void
244244 * @throws NoSuchEntityException
245245 */
246246 public function testExportSpecialChars (): void
247247 {
248+ /** @var \Magento\Catalog\Model\Product $product */
248249 $ product = $ this ->productRepository ->get ('simple "1" ' );
249250 $ product ->setStoreId (Store::DEFAULT_STORE_ID );
250251 $ product ->setDescription ('Description with <h2>this is test page</h2> ' );
251- $ product -> save ();
252+ $ this -> productRepository -> save ($ product );
252253
253254 $ this ->model ->setWriter (
254255 $ this ->objectManager ->create (
255256 \Magento \ImportExport \Model \Export \Adapter \Csv::class
256257 )
257258 );
258259 $ exportData = $ this ->model ->export ();
260+ $ rows = $ this ->csvToArray ($ exportData );
259261
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 ' ]);
261265 $ 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 ));
265267 }
266268
267269 /**
268270 * Verify exported data does not contain duplicate rows for product
269271 *
270- * @param $exportData
272+ * @param $rows
271273 * @return bool
272274 */
273- private function hasDuplicateRowsForProducts ($ exportData ): bool
275+ private function hasDuplicateRowsForProducts ($ rows ): bool
274276 {
275277 $ skus = [];
276- foreach (explode ( "\n" , $ exportData , - 1 ) as $ line ) {
277- $ skus [] = current ( explode ( ' , ' , $ line )) ;
278+ foreach ($ rows as $ product ) {
279+ $ skus [] = $ product [ ' sku ' ] ;
278280 }
279- array_shift ($ skus );
280281 return count ($ skus ) !== count (array_flip ($ skus ));
281282 }
282283
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+
283304 /**
284305 * @magentoDataFixture Magento/CatalogImportExport/_files/product_export_with_product_links_data.php
285306 * @magentoDbIsolation enabled
0 commit comments