/** * @param \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $product * @param array $modelData * @return \Magento\Downloadable\Model\Sample|\PHPUnit_Framework_MockObject_MockObject */ private function createSampleModel($product, array $modelData) { $sample = $this->getMockBuilder('\\Magento\\Downloadable\\Model\\Sample')->disableOriginalConstructor()->setMethods(['setData', 'setSampleType', 'setProductId', 'setStoreId', 'setProductWebsiteIds', 'setNumberOfDownloads', 'setSampleUrl', 'setLinkFile', 'setSampleFile', 'save'])->getMock(); $sample->expects($this->once())->method('setData')->with($modelData)->will($this->returnSelf()); $sample->expects($this->once())->method('setSampleType')->with($modelData['type'])->will($this->returnSelf()); $sample->expects($this->once())->method('setProductId')->with($product->getId())->will($this->returnSelf()); $sample->expects($this->once())->method('setStoreId')->with($product->getStoreId())->will($this->returnSelf()); return $sample; }
/** * @param bool $isChangedUrlKey * @param bool $isChangedVisibility * @param bool $isChangedWebsites * @param bool $isChangedCategories * @param bool $visibilityResult * @param int $expectedDeleteCount * @param int $expectedReplaceCount * * @dataProvider testUrlKeyDataProvider */ public function testExecuteUrlKey($isChangedUrlKey, $isChangedVisibility, $isChangedWebsites, $isChangedCategories, $visibilityResult, $expectedDeleteCount, $expectedReplaceCount) { $this->product->expects($this->any())->method('getStoreId')->will($this->returnValue(12)); $this->product->expects($this->any())->method('dataHasChangedFor')->will($this->returnValueMap([['visibility', $isChangedVisibility], ['url_key', $isChangedUrlKey]])); $this->product->expects($this->any())->method('getIsChangedWebsites')->will($this->returnValue($isChangedWebsites)); $this->product->expects($this->any())->method('getIsChangedCategories')->will($this->returnValue($isChangedCategories)); $this->urlPersist->expects($this->exactly($expectedDeleteCount))->method('deleteByData')->with([UrlRewrite::ENTITY_ID => $this->product->getId(), UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE, UrlRewrite::REDIRECT_TYPE => 0, UrlRewrite::STORE_ID => $this->product->getStoreId()]); $this->product->expects($this->any())->method('isVisibleInSiteVisibility')->will($this->returnValue($visibilityResult)); $this->urlPersist->expects($this->exactly($expectedReplaceCount))->method('replace')->with([3 => 'rewrite']); $this->model->execute($this->observer); }
/** * @param \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $product * @param array $modelData * @param bool $isUnlimited * @return \Magento\Downloadable\Model\Link|\PHPUnit_Framework_MockObject_MockObject */ private function createLinkkModel($product, array $modelData, $isUnlimited) { $link = $this->getMockBuilder('\\Magento\\Downloadable\\Model\\Link')->disableOriginalConstructor()->setMethods(['setData', 'setLinkType', 'setProductId', 'setStoreId', 'setWebsiteId', 'setProductWebsiteIds', 'setPrice', 'setNumberOfDownloads', 'setSampleUrl', 'setSampleType', 'setLinkFile', 'setSampleFile', 'save', 'getIsUnlimited'])->getMock(); $link->expects($this->once())->method('setData')->with($modelData)->will($this->returnSelf()); $link->expects($this->once())->method('setLinkType')->with($modelData['type'])->will($this->returnSelf()); $link->expects($this->once())->method('setProductId')->with($product->getId())->will($this->returnSelf()); $link->expects($this->once())->method('setStoreId')->with($product->getStoreId())->will($this->returnSelf()); $link->expects($this->once())->method('setWebsiteId')->with($product->getStore()->getWebsiteId())->will($this->returnSelf()); $link->expects($this->once())->method('setPrice')->with(0); $link->expects($this->any())->method('setNumberOfDownloads')->with(0); $link->expects($this->once())->method('getIsUnlimited')->will($this->returnValue($isUnlimited)); return $link; }