/** * 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)); }
/** * Test for method _toHtml for the case, when wishlist is absent */ public function testToHtmlWithoutWishlist() { $url = 'http://base.url/index'; $rssString = '<xml>Some empty xml</xml>'; $rssObjMock = $this->getMock('Magento\\Rss\\Model\\Rss', [], [], '', false); $customerServiceMock = $this->getMock('Magento\\Customer\\Service\\V1\\Data\\Customer', [], [], '', false); $wishlistModelMock = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', ['getId', '__wakeup', 'getCustomerId'], [], '', false); $expectedHeaders = ['title' => __('We cannot retrieve the wish list.'), 'description' => __('We cannot retrieve the wish list.'), 'link' => $url, 'charset' => 'UTF-8']; $this->rssFactoryMock->expects($this->once())->method('create')->will($this->returnValue($rssObjMock)); $this->wishlistHelperMock->expects($this->once())->method('getWishlist')->will($this->returnValue($wishlistModelMock)); $wishlistModelMock->expects($this->once())->method('getId')->will($this->returnValue(false)); $this->urlBuilderMock->expects($this->once())->method('getUrl')->will($this->returnValue($url)); $this->wishlistHelperMock->expects($this->once())->method('getCustomer')->will($this->returnValue($customerServiceMock)); $rssObjMock->expects($this->once())->method('_addHeader')->with($expectedHeaders)->will($this->returnSelf()); $rssObjMock->expects($this->once())->method('createRssXml')->will($this->returnValue($rssString)); $this->assertEquals($rssString, $this->block->toHtml()); }