61 $this->fileSystem = $this->objectManager->get(\
Magento\Framework\Filesystem::class);
62 $this->productResource = $this->objectManager->create(
65 \Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType::$commonAttributesCache = [];
70 $this->executeRollbackFixtures($this->fixtures);
125 $csvfile = $this->exportProducts();
135 $this->assertEqualsOtherThanSkippedAttributes(
136 $origProducts[
$index]->getData(),
137 $newProduct->getData(),
145 private function assertEqualsOtherThanSkippedAttributes($expected, $actual,
$skippedAttributes)
147 foreach ($expected as $key =>
$value) {
154 isset($actual[$key]) ? $actual[$key] :
null,
155 'Assert value at key - ' . $key .
' failed' 175 $this->executeImportDeleteTest(
$skus);
178 protected function executeImportDeleteTest(
$skus)
180 $csvfile = $this->exportProducts();
183 $product = $this->objectManager->create(\
Magento\Catalog\Model\Product::class);
184 foreach (
$skus as $sku) {
185 $productId = $this->productResource->getIdBySku($sku);
187 $this->assertNull(
$product->getId());
203 ->getAbsolutePath(
'/dev/tests/integration/testsuite/' . $fixture);
204 include $fixturePath;
214 private function executeRollbackFixtures(
$fixtures)
218 ->getAbsolutePath(
'/dev/tests/integration/testsuite/' . $fixture);
225 if (file_exists($rollbackfixturePath)) {
226 include $rollbackfixturePath;
289 $replacedAttributes = [
308 $exportProduct = $this->objectManager->create(\
Magento\CatalogImportExport\Model\Export\Product::class);
309 if ($usePagination) {
311 $itemsPerPageProperty = $this->objectManager->create(\ReflectionProperty::class, [
312 'class' => \
Magento\CatalogImportExport\Model\Export\Product::class,
313 'name' =>
'_itemsPerPage' 315 $itemsPerPageProperty->setAccessible(
true);
316 $itemsPerPageProperty->setValue($exportProduct, 1);
319 $csvfile = $this->exportProducts($exportProduct);
326 $origProduct = $this->objectManager->create(\
Magento\Catalog\Model\Product::class)->load($ids[
$index]);
327 $this->assertNull($origProduct->getId());
333 $origProductData = $origProducts[
$index]->getData();
334 $newProductData = $newProduct->getData();
335 $this->assertEqualsOtherThanSkippedAttributes($origProductData, $newProductData,
$skippedAttributes);
341 $expected = is_array($origProductData[
$attribute]) ?
344 if (!empty($expected)) {
346 $actual = is_array($actual) ? array_filter($actual) : $actual;
347 $this->assertNotEquals($expected, $actual,
$attribute .
' is expected to be changed');
360 private function exportProducts(\
Magento\CatalogImportExport\Model\Export\Product $exportProduct =
null)
362 $csvfile = uniqid(
'importexport_') .
'.csv';
364 $exportProduct = $exportProduct ?: $this->objectManager->create(
365 \
Magento\CatalogImportExport\Model\Export\Product::class
367 $exportProduct->setWriter(
370 [
'fileSystem' => $this->fileSystem,
'destination' => $csvfile]
373 $this->assertNotEmpty($exportProduct->export());
384 private function importProducts($csvfile, $behavior)
387 $importModel = $this->objectManager->create(
388 \
Magento\CatalogImportExport\Model\Import\Product::class
391 $source = $this->objectManager->create(
395 'directory' => $directory
402 $uploader = $importModel->getUploader();
413 $this->assertTrue($uploader->setDestDir($destDir));
414 $this->assertTrue($uploader->setTmpDir($tmpDir));
416 $errors = $importModel->setParameters(
418 'behavior' => $behavior,
419 'entity' =>
'catalog_product',
424 $errorMessage = $this->extractErrorMessage(
$errors->getAllErrors());
428 'Product import from file ' . $csvfile .
' validation errors: ' . $errorMessage
430 $importModel->importData();
431 $importErrors = $importModel->getErrorAggregator()->getAllErrors();
432 $importErrorMessage = $this->extractErrorMessage($importErrors);
435 'Product import from file ' . $csvfile .
' errors: ' . $importErrorMessage
443 private function extractErrorMessage(
$errors)
447 $errorMessage =
"\n" . $error->getErrorMessage();
449 return $errorMessage;
const INIT_PARAM_FILESYSTEM_DIR_PATHS
static $skippedAttributes
testImportDelete($fixtures, $skus, $skippedAttributes=[])
foreach($websiteCodes as $websiteCode) $skus
exportImportDataProvider()
testExport($fixtures, $skus, $skippedAttributes=[])
assertEqualsSpecificAttributes($expectedProduct, $actualProduct)
executeFixtures($fixtures, $skus=[])
testImportReplace($fixtures, $skus, $skippedAttributes=[])
testImportReplaceWithPagination($fixtures, $skus, $skippedAttributes=[])
static getObjectManager()