78 $this->request = $this->createMock(\
Magento\Framework\
App\RequestInterface::class);
79 $this->request->expects($this->at(0))->method(
'getParam')->with(
'store_id')->will($this->returnValue(
null));
80 $this->request->expects($this->at(1))->method(
'getParam')->with(
'cid')->will($this->returnValue(
null));
82 $this->httpContext = $this->getMockBuilder(\
Magento\Framework\
App\Http\Context::class)
83 ->setMethods([
'getValue'])->disableOriginalConstructor()->getMock();
84 $this->httpContext->expects($this->any())->method(
'getValue')->will($this->returnValue(1));
86 $this->imageHelper = $this->createMock(\
Magento\Catalog\Helper\Image::class);
87 $this->outputHelper = $this->createPartialMock(\
Magento\Catalog\Helper\Output::class, [
'productAttribute']);
88 $this->msrpHelper = $this->createPartialMock(\
Magento\Msrp\Helper\Data::class, [
'canApplyMsrp']);
89 $this->priceCurrency = $this->createMock(\
Magento\Framework\Pricing\PriceCurrencyInterface::class);
90 $this->rssModel = $this->createMock(\
Magento\Catalog\Model\Rss\Product\Special::class);
91 $this->rssUrlBuilder = $this->createMock(\
Magento\Framework\
App\Rss\UrlBuilderInterface::class);
93 $this->storeManager = $this->createMock(\
Magento\Store\Model\StoreManagerInterface::class);
94 $store = $this->getMockBuilder(\
Magento\Store\Model\Store::class)
95 ->setMethods([
'getId',
'getFrontendName',
'__wakeup'])->disableOriginalConstructor()->getMock();
96 $store->expects($this->any())->method(
'getId')->will($this->returnValue(1));
97 $store->expects($this->any())->method(
'getFrontendName')->will($this->returnValue(
'Store 1'));
98 $this->storeManager->expects($this->any())->method(
'getStore')->will($this->returnValue(
$store));
100 $this->scopeConfig = $this->createMock(\
Magento\Framework\
App\Config\ScopeConfigInterface::class);
101 $this->scopeConfig->expects($this->any())->method(
'getValue')->will($this->returnValue(
'en_US'));
103 $this->localeDate = $this->createMock(\
Magento\Framework\Stdlib\DateTime\TimezoneInterface::class);
105 $objectManagerHelper =
new ObjectManagerHelper($this);
106 $this->block = $objectManagerHelper->getObject(
107 \
Magento\Catalog\Block\Rss\Product\Special::class,
109 'request' => $this->request,
110 'httpContext' => $this->httpContext,
111 'imageHelper' => $this->imageHelper,
112 'outputHelper' => $this->outputHelper,
113 'msrpHelper' => $this->msrpHelper,
114 'priceCurrency' => $this->priceCurrency,
115 'rssModel' => $this->rssModel,
116 'rssUrlBuilder' => $this->rssUrlBuilder,
117 'storeManager' => $this->storeManager,
118 'scopeConfig' => $this->scopeConfig,
119 'localeDate' => $this->localeDate,
126 $this->rssUrlBuilder->expects($this->once())->method(
'getUrl')
127 ->with([
'type' =>
'special_products',
'store_id' => 1])
128 ->will($this->returnValue(
'http://magento.com/rss/feed/index/type/special_products/store_id/1'));
130 $this->rssModel->expects($this->once())->method(
'getProductsCollection')
131 ->will($this->returnValue([
$item]));
132 $this->msrpHelper->expects($this->once())->method(
'canApplyMsrp')->will($this->returnValue(
false));
133 $this->localeDate->expects($this->once())->method(
'formatDateTime')->will($this->returnValue(date(
'Y-m-d')));
135 $this->priceCurrency->expects($this->any())->method(
'convertAndFormat')->will($this->returnArgument(0));
137 $this->imageHelper->expects($this->once())->method(
'init')->with(
$item,
'rss_thumbnail')
138 ->will($this->returnSelf());
139 $this->imageHelper->expects($this->once())->method(
'getUrl')
140 ->will($this->returnValue(
'image_link'));
141 $this->outputHelper->expects($this->once())->method(
'productAttribute')->will($this->returnValue(
''));
143 'title' =>
'Store 1 - Special Products',
144 'description' =>
'Store 1 - Special Products',
145 'link' =>
'http://magento.com/rss/feed/index/type/special_products/store_id/1',
146 'charset' =>
'UTF-8',
147 'language' =>
'en_US',
150 'title' =>
'Product Name',
151 'link' =>
'http://magento.com/product-name.html',
155 $rssData = $this->block->getRssData();
157 unset($rssData[
'entries'][0][
'description']);
158 $this->assertEquals(
$data, $rssData);
159 $this->assertContains(
'<a href="http://magento.com/product-name.html"><',
$description);
160 $this->assertContains(
161 sprintf(
'<p>Price: Special Price: 10<br />Special Expires On: %s</p>', date(
'Y-m-d')),
164 $this->assertContains(
165 '<img src="image_link" alt="" border="0" align="left" height="75" width="75" />',
175 $item = $this->getMockBuilder(\
Magento\Catalog\Model\Product::class)
183 'getAllowedPriceInRss',
189 ])->disableOriginalConstructor()->getMock();
190 $item->expects($this->once())->method(
'getAllowedInRss')->will($this->returnValue(
true));
191 $item->expects($this->any())->method(
'getSpecialToDate')->will($this->returnValue(date(
'Y-m-d')));
192 $item->expects($this->exactly(2))->method(
'getFinalPrice')->will($this->returnValue(10));
193 $item->expects($this->once())->method(
'getSpecialPrice')->will($this->returnValue(15));
194 $item->expects($this->exactly(2))->method(
'getAllowedPriceInRss')->will($this->returnValue(
true));
195 $item->expects($this->once())->method(
'getUseSpecial')->will($this->returnValue(
true));
196 $item->expects($this->once())->method(
'getDescription')->will($this->returnValue(
'Product Description'));
197 $item->expects($this->once())->method(
'getName')->will($this->returnValue(
'Product Name'));
198 $item->expects($this->exactly(2))->method(
'getProductUrl')
199 ->will($this->returnValue(
'http://magento.com/product-name.html'));
206 $this->scopeConfig->expects($this->once())->method(
'isSetFlag')
207 ->with(
'rss/catalog/special', \
Magento\Store\Model\ScopeInterface::SCOPE_STORE)
208 ->will($this->returnValue(
true));
209 $this->assertEquals(
true, $this->block->isAllowed());
214 $this->assertEquals(600, $this->block->getCacheLifetime());
219 $this->scopeConfig->expects($this->once())->method(
'isSetFlag')
220 ->with(
'rss/catalog/special', \
Magento\Store\Model\ScopeInterface::SCOPE_STORE)
221 ->will($this->returnValue(
true));
222 $this->rssUrlBuilder->expects($this->once())->method(
'getUrl')
223 ->with([
'type' =>
'special_products'])
224 ->will($this->returnValue(
'http://magento.com/rss/feed/index/type/special_products/store_id/1'));
226 'label' =>
'Special Products',
227 'link' =>
'http://magento.com/rss/feed/index/type/special_products/store_id/1',
229 $this->assertEquals($expected, $this->block->getFeeds());