public function testGetRssData() { $this->rssUrlBuilder->expects($this->once())->method('getUrl')->will($this->returnValue('http://magento.com/rss/feeds/index/type/notifystock')); $item = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->setMethods(['__sleep', '__wakeup', 'getId', 'getQty', 'getName'])->disableOriginalConstructor()->getMock(); $item->expects($this->once())->method('getId')->will($this->returnValue(1)); $item->expects($this->once())->method('getQty')->will($this->returnValue(1)); $item->expects($this->any())->method('getName')->will($this->returnValue('Low Stock Product')); $this->rssModel->expects($this->once())->method('getProductsCollection')->will($this->returnValue([$item])); $this->urlBuilder->expects($this->once())->method('getUrl')->with('catalog/product/edit', ['id' => 1, '_secure' => true, '_nosecret' => true])->will($this->returnValue('http://magento.com/catalog/product/edit/id/1')); $this->assertEquals($this->rssFeed, $this->block->getRssData()); }
public function testGetProductsCollection() { /** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection */ $productCollection = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection', [], [], '', false); $this->product->expects($this->once())->method('getCollection')->will($this->returnValue($productCollection)); $productCollection->expects($this->once())->method('addAttributeToSelect')->will($this->returnSelf()); $productCollection->expects($this->once())->method('addAttributeToFilter')->will($this->returnSelf()); $productCollection->expects($this->once())->method('setOrder')->will($this->returnSelf()); $this->eventManager->expects($this->once())->method('dispatch')->with('rss_catalog_notify_stock_collection_select'); $this->stock->expects($this->once())->method('addLowStockFilter')->with($productCollection); $products = $this->notifyStock->getProductsCollection(); $this->assertEquals($productCollection, $products); }
/** * {@inheritdoc} */ public function getRssData() { $newUrl = $this->rssUrlBuilder->getUrl(['_secure' => true, '_nosecret' => true, 'type' => 'notifystock']); $title = __('Low Stock Products'); $data = ['title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8']; foreach ($this->rssModel->getProductsCollection() as $item) { /* @var $item \Magento\Catalog\Model\Product */ $url = $this->getUrl('catalog/product/edit', ['id' => $item->getId(), '_secure' => true, '_nosecret' => true]); $qty = 1 * $item->getQty(); $description = __('%1 has reached a quantity of %2.', $item->getName(), $qty); $data['entries'][] = ['title' => $item->getName(), 'link' => $url, 'description' => $description]; } return $data; }