Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
NotifyStockTest.php
Go to the documentation of this file.
1 <?php
7 
9 
14 class NotifyStockTest extends \PHPUnit\Framework\TestCase
15 {
19  protected $block;
20 
25 
29  protected $context;
30 
34  protected $rssModel;
35 
39  protected $rssUrlBuilder;
40 
44  protected $urlBuilder;
45 
49  protected $rssFeed = [
50  'title' => 'Low Stock Products',
51  'description' => 'Low Stock Products',
52  'link' => 'http://magento.com/rss/feeds/index/type/notifystock',
53  'charset' => 'UTF-8',
54  'entries' => [
55  [
56  'title' => 'Low Stock Product',
57  'description' => 'Low Stock Product has reached a quantity of 1.',
58  'link' => 'http://magento.com/catalog/product/edit/id/1',
59 
60  ],
61  ],
62  ];
63 
64  protected function setUp()
65  {
66  $this->rssModel = $this->getMockBuilder(\Magento\Catalog\Model\Rss\Product\NotifyStock::class)
67  ->setMethods(['getProductsCollection', '__wakeup'])
68  ->disableOriginalConstructor()->getMock();
69  $this->rssUrlBuilder = $this->createMock(\Magento\Framework\App\Rss\UrlBuilderInterface::class);
70  $this->urlBuilder = $this->createMock(\Magento\Framework\UrlInterface::class);
71  $this->objectManagerHelper = new ObjectManagerHelper($this);
72  $this->block = $this->objectManagerHelper->getObject(
73  \Magento\Catalog\Block\Adminhtml\Rss\NotifyStock::class,
74  [
75  'urlBuilder' => $this->urlBuilder,
76  'rssModel' => $this->rssModel,
77  'rssUrlBuilder' => $this->rssUrlBuilder
78  ]
79  );
80  }
81 
82  public function testGetRssData()
83  {
84  $this->rssUrlBuilder->expects($this->once())->method('getUrl')
85  ->will($this->returnValue('http://magento.com/rss/feeds/index/type/notifystock'));
86  $item = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
87  ->setMethods(['__sleep', '__wakeup', 'getId', 'getQty', 'getName'])
88  ->disableOriginalConstructor()
89  ->getMock();
90  $item->expects($this->once())->method('getId')->will($this->returnValue(1));
91  $item->expects($this->once())->method('getQty')->will($this->returnValue(1));
92  $item->expects($this->any())->method('getName')->will($this->returnValue('Low Stock Product'));
93 
94  $this->rssModel->expects($this->once())->method('getProductsCollection')
95  ->will($this->returnValue([$item]));
96  $this->urlBuilder->expects($this->once())->method('getUrl')
97  ->with('catalog/product/edit', ['id' => 1, '_secure' => true, '_nosecret' => true])
98  ->will($this->returnValue('http://magento.com/catalog/product/edit/id/1'));
99  $this->assertEquals($this->rssFeed, $this->block->getRssData());
100  }
101 
102  public function testGetCacheLifetime()
103  {
104  $this->assertEquals(600, $this->block->getCacheLifetime());
105  }
106 
107  public function testIsAllowed()
108  {
109  $this->assertTrue($this->block->isAllowed());
110  }
111 
112  public function testGetFeeds()
113  {
114  $this->assertEmpty($this->block->getFeeds());
115  }
116 }