Skip to content

Commit abd9e29

Browse files
committed
ACP2E-1754: Store level URL rewrites are removed after product import
1 parent 9a60de3 commit abd9e29

File tree

1 file changed

+46
-15
lines changed

1 file changed

+46
-15
lines changed

app/code/Magento/CatalogUrlRewrite/Test/Unit/Observer/AfterImportDataObserverTest.php

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77

88
namespace Magento\CatalogUrlRewrite\Test\Unit\Observer;
99

10+
use Magento\Catalog\Api\Data\ProductAttributeInterface;
11+
use Magento\Catalog\Api\Data\ProductInterface;
12+
use Magento\Eav\Model\ResourceModel\AttributeValue;
1013
use Magento\Catalog\Api\ProductRepositoryInterface;
1114
use Magento\Catalog\Model\ProductFactory;
1215
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory;
16+
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
1317
use Magento\CatalogImportExport\Model\Import\Product as ImportProduct;
1418
use Magento\CatalogUrlRewrite\Model\ObjectRegistry;
1519
use Magento\CatalogUrlRewrite\Model\ObjectRegistryFactory;
@@ -18,6 +22,7 @@
1822
use Magento\CatalogUrlRewrite\Observer\AfterImportDataObserver;
1923
use Magento\CatalogUrlRewrite\Service\V1\StoreViewService;
2024
use Magento\Framework\Event;
25+
use Magento\Framework\App\Config\ScopeConfigInterface;
2126
use Magento\Framework\Event\Observer;
2227
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
2328
use Magento\Store\Model\Store;
@@ -133,6 +138,21 @@ class AfterImportDataObserverTest extends TestCase
133138
*/
134139
private $categoryCollectionFactory;
135140

141+
/**
142+
* @var AttributeValue|MockObject
143+
*/
144+
private $attributeValue;
145+
146+
/**
147+
* @var ScopeConfigInterface|MockObject
148+
*/
149+
private $scopeConfig;
150+
151+
/**
152+
* @var CollectionFactory|MockObject
153+
*/
154+
private $collectionFactory;
155+
136156
/**
137157
* Test products returned by getBunch method of event object.
138158
*
@@ -252,21 +272,29 @@ protected function setUp(): void
252272
->setMethods(['create'])
253273
->disableOriginalConstructor()
254274
->getMock();
255-
$this->objectManager = new ObjectManager($this);
256-
$this->import = $this->objectManager->getObject(
257-
AfterImportDataObserver::class,
258-
[
259-
'catalogProductFactory' => $this->catalogProductFactory,
260-
'objectRegistryFactory' => $this->objectRegistryFactory,
261-
'productUrlPathGenerator' => $this->productUrlPathGenerator,
262-
'storeViewService' => $this->storeViewService,
263-
'storeManager'=> $this->storeManager,
264-
'urlPersist' => $this->urlPersist,
265-
'urlRewriteFactory' => $this->urlRewriteFactory,
266-
'urlFinder' => $this->urlFinder,
267-
'mergeDataProviderFactory' => $mergeDataProviderFactory,
268-
'categoryCollectionFactory' => $this->categoryCollectionFactory
269-
]
275+
$this->attributeValue = $this->getMockBuilder(AttributeValue::class)
276+
->disableOriginalConstructor()
277+
->getMock();
278+
$this->scopeConfig = $this->getMockBuilder(ScopeConfigInterface::class)
279+
->disableOriginalConstructor()
280+
->getMockForAbstractClass();
281+
$this->collectionFactory = $this->getMockBuilder(CollectionFactory::class)
282+
->disableOriginalConstructor()
283+
->getMock();
284+
$this->import = new AfterImportDataObserver(
285+
$this->catalogProductFactory,
286+
$this->objectRegistryFactory,
287+
$this->productUrlPathGenerator,
288+
$this->storeViewService,
289+
$this->storeManager,
290+
$this->urlPersist,
291+
$this->urlRewriteFactory,
292+
$this->urlFinder,
293+
$mergeDataProviderFactory,
294+
$this->categoryCollectionFactory,
295+
$this->scopeConfig,
296+
$this->collectionFactory,
297+
$this->attributeValue
270298
);
271299
}
272300

@@ -389,6 +417,9 @@ public function testAfterImportData()
389417
->expects($this->once())
390418
->method('replace')
391419
->with($productUrls);
420+
$this->attributeValue->expects($this->once())
421+
->method('getValuesMultiple')
422+
->with(ProductInterface::class, [0], [ProductAttributeInterface::CODE_SEO_FIELD_URL_KEY], [1]);
392423
$this->import->execute($this->observer);
393424
}
394425

0 commit comments

Comments
 (0)