5
5
*/
6
6
declare (strict_types=1 );
7
7
8
- /**
9
- * Test class for \Magento\CatalogImportExport\Model\Import\Product
10
- *
11
- * The "CouplingBetweenObjects" warning is caused by tremendous complexity of the original class
12
- */
13
8
namespace Magento \CatalogImportExport \Model \Import ;
14
9
15
10
use Magento \Catalog \Api \Data \ProductInterface ;
18
13
use Magento \Catalog \Model \Category ;
19
14
use Magento \Catalog \Model \Product ;
20
15
use Magento \Catalog \Model \ResourceModel \Product as ProductResource ;
16
+ use Magento \CatalogImportExport \Model \Import \Product as ImportProduct ;
21
17
use Magento \CatalogImportExport \Model \Import \Product \RowValidatorInterface ;
22
18
use Magento \CatalogInventory \Model \Stock ;
23
19
use Magento \CatalogInventory \Model \StockRegistry ;
30
26
use Magento \Framework \Filesystem ;
31
27
use Magento \Framework \Registry ;
32
28
use Magento \ImportExport \Model \Import ;
29
+ use Magento \ImportExport \Model \Import \ErrorProcessing \ProcessingErrorAggregatorInterface ;
33
30
use Magento \ImportExport \Model \Import \Source \Csv ;
34
31
use Magento \Store \Model \Store ;
35
32
use Magento \Store \Model \StoreManagerInterface ;
38
35
use Psr \Log \LoggerInterface ;
39
36
40
37
/**
41
- * Class ProductTest
38
+ * Integration test for \Magento\CatalogImportExport\Model\Import\Product class.
39
+ *
42
40
* @magentoAppIsolation enabled
43
41
* @magentoDbIsolation enabled
44
42
* @magentoAppArea adminhtml
@@ -81,6 +79,14 @@ class ProductTest extends \Magento\TestFramework\Indexer\TestCase
81
79
*/
82
80
private $ logger ;
83
81
82
+ /**
83
+ * @var ProductRepositoryInterface
84
+ */
85
+ private $ productRepository ;
86
+
87
+ /**
88
+ * @inheritdoc
89
+ */
84
90
protected function setUp ()
85
91
{
86
92
$ this ->objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
@@ -92,6 +98,7 @@ protected function setUp()
92
98
['logger ' => $ this ->logger ]
93
99
);
94
100
$ this ->importedProducts = [];
101
+ $ this ->productRepository = $ this ->objectManager ->get (ProductRepositoryInterface::class);
95
102
96
103
parent ::setUp ();
97
104
}
@@ -3022,4 +3029,25 @@ public function testProductStockStatusShouldBeUpdatedOnSchedule()
3022
3029
$ status = $ stockRegistry ->getStockStatusBySku ('simple ' );
3023
3030
$ this ->assertEquals (Stock::STOCK_IN_STOCK , $ status ->getStockStatus ());
3024
3031
}
3032
+
3033
+ /**
3034
+ * Tests that empty attribute value in the CSV file will be ignored after update a product by the import.
3035
+ *
3036
+ * @magentoDataFixture Magento/Catalog/_files/product_with_varchar_attribute.php
3037
+ */
3038
+ public function testEmptyAttributeValueShouldBeIgnoredAfterUpdateProductByImport ()
3039
+ {
3040
+ $ pathToFile = __DIR__ . DIRECTORY_SEPARATOR . '_files ' . DIRECTORY_SEPARATOR
3041
+ . 'import_product_with_empty_attribute_value.csv ' ;
3042
+ /** @var ImportProduct $importModel */
3043
+ $ importModel = $ this ->createImportModel ($ pathToFile );
3044
+ /** @var ProcessingErrorAggregatorInterface $errors */
3045
+ $ errors = $ importModel ->validateData ();
3046
+ $ this ->assertTrue ($ errors ->getErrorsCount () === 0 , 'Import file validation failed. ' );
3047
+ $ importModel ->importData ();
3048
+
3049
+ $ simpleProduct = $ this ->productRepository ->get ('simple ' , false , null , true );
3050
+ $ this ->assertEquals ('Varchar default value ' , $ simpleProduct ->getData ('varchar_attribute ' ));
3051
+ $ this ->assertEquals ('Short description ' , $ simpleProduct ->getData ('short_description ' ));
3052
+ }
3025
3053
}
0 commit comments