|
7 | 7 |
|
8 | 8 | namespace Magento\CatalogUrlRewrite\Test\Unit\Observer;
|
9 | 9 |
|
| 10 | +use Magento\Catalog\Api\Data\ProductAttributeInterface; |
| 11 | +use Magento\Catalog\Api\Data\ProductInterface; |
| 12 | +use Magento\Eav\Model\ResourceModel\AttributeValue; |
10 | 13 | use Magento\Catalog\Api\ProductRepositoryInterface;
|
11 | 14 | use Magento\Catalog\Model\ProductFactory;
|
12 | 15 | use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory;
|
| 16 | +use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory; |
13 | 17 | use Magento\CatalogImportExport\Model\Import\Product as ImportProduct;
|
14 | 18 | use Magento\CatalogUrlRewrite\Model\ObjectRegistry;
|
15 | 19 | use Magento\CatalogUrlRewrite\Model\ObjectRegistryFactory;
|
|
18 | 22 | use Magento\CatalogUrlRewrite\Observer\AfterImportDataObserver;
|
19 | 23 | use Magento\CatalogUrlRewrite\Service\V1\StoreViewService;
|
20 | 24 | use Magento\Framework\Event;
|
| 25 | +use Magento\Framework\App\Config\ScopeConfigInterface; |
21 | 26 | use Magento\Framework\Event\Observer;
|
22 | 27 | use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
|
23 | 28 | use Magento\Store\Model\Store;
|
@@ -133,6 +138,21 @@ class AfterImportDataObserverTest extends TestCase
|
133 | 138 | */
|
134 | 139 | private $categoryCollectionFactory;
|
135 | 140 |
|
| 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 | + |
136 | 156 | /**
|
137 | 157 | * Test products returned by getBunch method of event object.
|
138 | 158 | *
|
@@ -252,21 +272,29 @@ protected function setUp(): void
|
252 | 272 | ->setMethods(['create'])
|
253 | 273 | ->disableOriginalConstructor()
|
254 | 274 | ->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 |
270 | 298 | );
|
271 | 299 | }
|
272 | 300 |
|
@@ -389,6 +417,9 @@ public function testAfterImportData()
|
389 | 417 | ->expects($this->once())
|
390 | 418 | ->method('replace')
|
391 | 419 | ->with($productUrls);
|
| 420 | + $this->attributeValue->expects($this->once()) |
| 421 | + ->method('getValuesMultiple') |
| 422 | + ->with(ProductInterface::class, [0], [ProductAttributeInterface::CODE_SEO_FIELD_URL_KEY], [1]); |
392 | 423 | $this->import->execute($this->observer);
|
393 | 424 | }
|
394 | 425 |
|
|
0 commit comments