Skip to content

Commit fa7559d

Browse files
committed
Merge remote-tracking branch 'origin/MC-20446' into 2.3-develop-pr104
2 parents 63d68ae + 7d7302a commit fa7559d

File tree

4 files changed

+66
-6
lines changed

4 files changed

+66
-6
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Eav\Model\Config;
9+
10+
require __DIR__ . '/product_varchar_attribute.php';
11+
require __DIR__ . '/product_simple.php';
12+
13+
/** @var Config $eavConfig */
14+
$eavConfig = $objectManager->get(Config::class);
15+
$eavConfig->clear();
16+
17+
$attribute->setDefaultValue('Varchar default value');
18+
$attributeRepository->save($attribute);
19+
20+
$product->setCustomAttribute('varchar_attribute', $attribute->getDefaultValue());
21+
$productRepository->save($product);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
require __DIR__ . '/product_varchar_attribute_rollback.php';
9+
require __DIR__ . '/product_simple_rollback.php';

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest.php

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
*/
66
declare(strict_types=1);
77

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-
*/
138
namespace Magento\CatalogImportExport\Model\Import;
149

1510
use Magento\Catalog\Api\Data\ProductInterface;
@@ -18,6 +13,7 @@
1813
use Magento\Catalog\Model\Category;
1914
use Magento\Catalog\Model\Product;
2015
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
16+
use Magento\CatalogImportExport\Model\Import\Product as ImportProduct;
2117
use Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface;
2218
use Magento\CatalogInventory\Model\Stock;
2319
use Magento\CatalogInventory\Model\StockRegistry;
@@ -30,6 +26,7 @@
3026
use Magento\Framework\Filesystem;
3127
use Magento\Framework\Registry;
3228
use Magento\ImportExport\Model\Import;
29+
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
3330
use Magento\ImportExport\Model\Import\Source\Csv;
3431
use Magento\Store\Model\Store;
3532
use Magento\Store\Model\StoreManagerInterface;
@@ -38,7 +35,8 @@
3835
use Psr\Log\LoggerInterface;
3936

4037
/**
41-
* Class ProductTest
38+
* Integration test for \Magento\CatalogImportExport\Model\Import\Product class.
39+
*
4240
* @magentoAppIsolation enabled
4341
* @magentoDbIsolation enabled
4442
* @magentoAppArea adminhtml
@@ -81,6 +79,14 @@ class ProductTest extends \Magento\TestFramework\Indexer\TestCase
8179
*/
8280
private $logger;
8381

82+
/**
83+
* @var ProductRepositoryInterface
84+
*/
85+
private $productRepository;
86+
87+
/**
88+
* @inheritdoc
89+
*/
8490
protected function setUp()
8591
{
8692
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
@@ -92,6 +98,7 @@ protected function setUp()
9298
['logger' => $this->logger]
9399
);
94100
$this->importedProducts = [];
101+
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
95102

96103
parent::setUp();
97104
}
@@ -3022,4 +3029,25 @@ public function testProductStockStatusShouldBeUpdatedOnSchedule()
30223029
$status = $stockRegistry->getStockStatusBySku('simple');
30233030
$this->assertEquals(Stock::STOCK_IN_STOCK, $status->getStockStatus());
30243031
}
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+
}
30253053
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sku,name,short_description,product_type,attribute_set_code,price,qty,additional_attributes
2+
simple,Simple Product,,simple,Default,10,100,varchar_attribute=

0 commit comments

Comments
 (0)