/** * 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; }
public function testGetProductPriceHtmlBlockExists() { $price = 10.0; $productMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock(); $renderBlockMock = $this->getMockBuilder('Magento\\Framework\\Pricing\\Render')->disableOriginalConstructor()->getMock(); $renderBlockMock->expects($this->once())->method('render')->with('wishlist_configured_price', $productMock, ['zone' => \Magento\Framework\Pricing\Render::ZONE_ITEM_LIST])->willReturn($price); $this->layoutMock->expects($this->once())->method('getBlock')->with('product.price.render.default')->willReturn($renderBlockMock); $this->assertEquals($price, $this->model->getProductPriceHtml($productMock)); }
public function testGetRssData() { $this->rssUrlBuilder->expects($this->once())->method('getUrl')->with(['type' => 'special_products', 'store_id' => 1])->will($this->returnValue('http://magento.com/rss/feed/index/type/special_products/store_id/1')); $item = $this->getItemMock(); $this->rssModel->expects($this->once())->method('getProductsCollection')->will($this->returnValue([$item])); $this->msrpHelper->expects($this->once())->method('canApplyMsrp')->will($this->returnValue(false)); $this->localeDate->expects($this->once())->method('formatDateTime')->will($this->returnValue(date('Y-m-d'))); $this->priceCurrency->expects($this->any())->method('convertAndFormat')->will($this->returnArgument(0)); $this->imageHelper->expects($this->once())->method('init')->with($item, 'rss_thumbnail')->will($this->returnSelf()); $this->imageHelper->expects($this->once())->method('getUrl')->will($this->returnValue('image_link')); $this->outputHelper->expects($this->once())->method('productAttribute')->will($this->returnValue('')); $data = ['title' => 'Store 1 - Special Products', 'description' => 'Store 1 - Special Products', 'link' => 'http://magento.com/rss/feed/index/type/special_products/store_id/1', 'charset' => 'UTF-8', 'language' => 'en_US', 'entries' => [['title' => 'Product Name', 'link' => 'http://magento.com/product-name.html']]]; $rssData = $this->block->getRssData(); $description = $rssData['entries'][0]['description']; unset($rssData['entries'][0]['description']); $this->assertEquals($data, $rssData); $this->assertContains('<a href="http://magento.com/product-name.html"><', $description); $this->assertContains(sprintf('<p>Price: Special Price: 10<br />Special Expires On: %s</p>', date('Y-m-d')), $description); $this->assertContains('<img src="image_link" alt="" border="0" align="left" height="75" width="75" />', $description); }