/** * Test for method addNewItemXmlCallback */ public function testAddNewItemXmlCallback() { $priceHtmlForTest = '<div class="price">Price is 10 for example</div>'; $productMock = $this->getMock('Magento\\Catalog\\Model\\Product', ['getProductUrl', 'getDescription', 'getAllowedInRss', 'getName', '__wakeup'], [], '', false); $rssObjMock = $this->getMock('Magento\\Rss\\Model\\Rss', [], [], '', false); $layoutMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\LayoutInterface', [], '', true, true, true, ['getBlock']); $priceRendererMock = $this->getMock('Magento\\Framework\\Pricing\\Render', ['render'], [], '', false); $productTitle = 'Product title'; $productUrl = '<a href="http://product.url">Product Url</a>'; $imgThumbSrc = 'http://source-for-thumbnail'; $productDescription = 'Product description'; $description = '<table><tr><td><a href="' . $productUrl . '"><img src="' . $imgThumbSrc . '" border="0" align="left" height="75" width="75"></a></td><td style="text-decoration:none;">' . $productDescription . $priceHtmlForTest . '</td></tr></table>'; $productMock->expects($this->exactly(2))->method('getProductUrl')->will($this->returnValue($productUrl)); $productMock->expects($this->once())->method('getDescription')->will($this->returnValue($productDescription)); $productMock->expects($this->any())->method('getAllowedInRss')->will($this->returnValue(true)); $productMock->expects($this->once())->method('getName')->will($this->returnValue($productTitle)); $this->imageHelperMock->expects($this->once())->method('init')->will($this->returnSelf()); $this->imageHelperMock->expects($this->once())->method('resize')->will($this->returnValue($imgThumbSrc)); $layoutMock->expects($this->once())->method('getBlock')->will($this->returnValue($priceRendererMock)); $priceRendererMock->expects($this->once())->method('render')->will($this->returnValue($priceHtmlForTest)); $expectedData = ['title' => $productTitle, 'link' => $productUrl, 'description' => $description]; $rssObjMock->expects($this->once())->method('_addEntry')->with($expectedData)->will($this->returnSelf()); $args = ['product' => $productMock, 'rssObj' => $rssObjMock]; $this->block->setLayout($layoutMock); $this->assertNull($this->block->addNewItemXmlCallback($args)); }
/** * Additional function to process forming description for wishlist item * * @param \Magento\Wishlist\Model\Wishlist $wishlistModelMock * @param array $staticArgs * @return string */ protected function processWishlistItemDescription($wishlistModelMock, $staticArgs) { $imgThumbSrc = 'http://source-for-thumbnail'; $priceHtmlForTest = '<div class="price">Price is 10 for example</div>'; $productDescription = 'Product description'; $productShortDescription = 'Product short description'; $wishlistItem = $this->getMock('Magento\\Wishlist\\Model\\Item', [], [], '', false); $wishlistItemsCollection = [$wishlistItem]; $productMock = $this->getMock('Magento\\Catalog\\Model\\Product', ['getAllowedInRss', 'getAllowedPriceInRss', 'getDescription', 'getShortDescription', 'getName', 'getVisibleInSiteVisibilities', 'getUrlModel', '__wakeup'], [], '', false); $urlModelMock = $this->getMock('Magento\\Catalog\\Model\\Product\\Url', [], [], '', false); $layoutMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\LayoutInterface', [], '', true, true, true, ['getBlock']); $wishlistModelMock->expects($this->once())->method('getItemCollection')->will($this->returnValue($wishlistItemsCollection)); $wishlistItem->expects($this->once())->method('getProduct')->will($this->returnValue($productMock)); $productMock->expects($this->once())->method('getUrlModel')->will($this->returnValue($urlModelMock)); $productMock->expects($this->once())->method('getAllowedPriceInRss')->will($this->returnValue($urlModelMock)); $urlModelMock->expects($this->once())->method('getUrl')->will($this->returnValue($staticArgs['productUrl'])); $productMock->expects($this->once())->method('getName')->will($this->returnValue($staticArgs['productName'])); $productMock->expects($this->once())->method('getAllowedInRss')->will($this->returnValue(true)); $productMock->expects($this->once())->method('getVisibleInSiteVisibilities')->will($this->returnValue(true)); $this->imageHelperMock->expects($this->once())->method('init')->will($this->returnSelf()); $this->imageHelperMock->expects($this->once())->method('resize')->will($this->returnValue($imgThumbSrc)); $priceRendererMock = $this->getMock('Magento\\Framework\\Pricing\\Render', ['render'], [], '', false); $layoutMock->expects($this->once())->method('getBlock')->will($this->returnValue($priceRendererMock)); $priceRendererMock->expects($this->once())->method('render')->will($this->returnValue($priceHtmlForTest)); $productMock->expects($this->any())->method('getDescription')->will($this->returnValue($productDescription)); $productMock->expects($this->any())->method('getShortDescription')->will($this->returnValue($productShortDescription)); $this->catalogOutputMock->expects($this->any())->method('productAttribute')->will($this->returnArgument(1)); $this->block->setLayout($layoutMock); $description = '<table><tr><td><a href="' . $staticArgs['productUrl'] . '"><img src="' . $imgThumbSrc . '" border="0" align="left" height="75" width="75"></a></td><td style="text-decoration:none;">' . $productShortDescription . '<p>' . $priceHtmlForTest . '</p><p>Comment: ' . $productDescription . '<p>' . '</td></tr></table>'; return $description; }