/** * Set up */ protected function setUp() { $this->urlPersist = $this->getMock(\Magento\UrlRewrite\Model\UrlPersistInterface::class, [], [], '', false); $this->product = $this->getMock(\Magento\Catalog\Model\Product::class, ['getId', 'dataHasChangedFor', 'isVisibleInSiteVisibility', 'getIsChangedWebsites', 'getIsChangedCategories', 'getStoreId'], [], '', false); $this->product->expects($this->any())->method('getId')->will($this->returnValue(3)); $this->event = $this->getMock(\Magento\Framework\Event::class, ['getProduct'], [], '', false); $this->event->expects($this->any())->method('getProduct')->willReturn($this->product); $this->observer = $this->getMock(\Magento\Framework\Event\Observer::class, ['getEvent'], [], '', false); $this->observer->expects($this->any())->method('getEvent')->willReturn($this->event); $this->productUrlRewriteGenerator = $this->getMock(\Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator::class, ['generate'], [], '', false); $this->productUrlRewriteGenerator->expects($this->any())->method('generate')->will($this->returnValue([3 => 'rewrite'])); $this->objectManager = new ObjectManager($this); $this->model = $this->objectManager->getObject(\Magento\CatalogUrlRewrite\Observer\ProductProcessUrlRewriteSavingObserver::class, ['productUrlRewriteGenerator' => $this->productUrlRewriteGenerator, 'urlPersist' => $this->urlPersist]); }
/** * Test for afterImportData() */ public function testAfterImportData() { $this->productUrlRewriteGenerator->expects($this->any())->method('generate')->willReturn(['url1', 'url2']); $this->import->afterImportData($this->observer); }