73 $this->storeManagerInterface = $this->createMock(\
Magento\Store\Model\StoreManagerInterface::class);
74 $this->requestInterface = $this->createMock(\
Magento\Framework\
App\RequestInterface::class);
75 $this->rssBuilderInterface = $this->createMock(\
Magento\Framework\
App\Rss\UrlBuilderInterface::class);
76 $this->urlBuilderInterface = $this->createMock(\
Magento\Framework\UrlInterface::class);
77 $this->scopeConfigInterface = $this->createMock(\
Magento\Framework\
App\Config\ScopeConfigInterface::class);
78 $this->timezoneInterface = $this->createMock(\
Magento\Framework\Stdlib\DateTime\TimezoneInterface::class);
79 $this->discounts = $this->createMock(\
Magento\SalesRule\Model\Rss\Discounts::class);
80 $this->rssModel = $this->createPartialMock(\
Magento\SalesRule\Model\Rss\Discounts::class, [
82 'getDiscountCollection' 84 $this->storeModel = $this->createPartialMock(\
Magento\Store\Model\Store::class, [
92 $this->storeManagerInterface->expects($this->any())->method(
'getStore')
93 ->will($this->returnValue($this->storeModel));
94 $this->storeModel->expects($this->any())->method(
'getId')->will($this->returnValue(1));
96 $this->objectManagerHelper =
new ObjectManagerHelper($this);
97 $this->block = $this->objectManagerHelper->getObject(
98 \
Magento\SalesRule\Block\Rss\Discounts::class,
100 'storeManager' => $this->storeManagerInterface,
101 'rssModel' => $this->discounts,
102 'rssUrlBuilder' => $this->rssBuilderInterface,
103 'urlBuilder' => $this->urlBuilderInterface,
104 'request' => $this->requestInterface,
105 'scopeConfig' => $this->scopeConfigInterface,
106 'rssModel' => $this->rssModel,
107 'localeDate' => $this->timezoneInterface
115 'to_date' =>
'12/12/14',
116 'from_date' =>
'12/12/14',
117 'coupon_code' =>
'1234567',
118 'description' =>
'Rule Description',
119 'name' =>
'Rule Name',
122 'title' =>
'Frontend Name - Discounts and Coupons',
123 'description' =>
'Frontend Name - Discounts and Coupons',
124 'link' =>
'http://rss.magento.com/discount',
125 'charset' =>
'UTF-8',
126 'language' =>
'en_US',
128 'title' =>
'Rule Name',
129 'link' =>
'http://rss.magento.com',
131 'description' =>
'Rule Description',
132 'start_date' =>
'12/12/14',
133 'end_date' =>
'12/12/14',
134 'coupon_code' =>
'1234567',
138 $rssUrl =
'http://rss.magento.com/discount';
139 $url =
'http://rss.magento.com';
141 $ruleModel = $this->createPartialMock(\
Magento\SalesRule\Model\Rule::class, [
150 $this->storeModel->expects($this->once())->method(
'getWebsiteId')->will($this->returnValue(1));
151 $this->storeModel->expects($this->never())->method(
'getName');
152 $this->storeModel->expects($this->atLeastOnce())->method(
'getFrontendName')->willReturn(
'Frontend Name');
154 $this->requestInterface->expects($this->any())->method(
'getParam')->will($this->returnValue(1));
155 $this->urlBuilderInterface->expects($this->any())->method(
'getUrl')->will($this->returnValue(
$url));
156 $this->rssBuilderInterface->expects($this->any())->method(
'getUrl')->will($this->returnValue($rssUrl));
157 $this->scopeConfigInterface->expects($this->any())->method(
'getValue')->will($this->returnValue(
'en_US'));
158 $ruleModel->expects($this->any())->method(
'getCouponCode')->will($this->returnValue(
$ruleData[
'coupon_code']));
159 $ruleModel->expects($this->any())->method(
'getToDate')->will($this->returnValue(
$ruleData[
'to_date']));
160 $ruleModel->expects($this->once())->method(
'getFromDate')->will($this->returnValue(
$ruleData[
'from_date']));
161 $ruleModel->expects($this->once())->method(
'getDescription')
162 ->will($this->returnValue(
$ruleData[
'description']));
163 $ruleModel->expects($this->once())->method(
'getName')->will($this->returnValue(
$ruleData[
'name']));
164 $this->rssModel->expects($this->any())->method(
'getDiscountCollection')
165 ->will($this->returnValue([$ruleModel]));
166 $this->timezoneInterface->expects($this->any())->method(
'formatDateTime')->will($this->returnValue(
'12/12/14'));
168 $data = $this->block->getRssData();
170 $this->assertEquals($rssData[
'title'],
$data[
'title']);
171 $this->assertEquals($rssData[
'description'],
$data[
'description']);
172 $this->assertEquals($rssData[
'link'],
$data[
'link']);
173 $this->assertEquals($rssData[
'charset'],
$data[
'charset']);
174 $this->assertEquals($rssData[
'language'],
$data[
'language']);
175 $this->assertEquals($rssData[
'entries'][
'title'],
$data[
'entries'][0][
'title']);
176 $this->assertEquals($rssData[
'entries'][
'link'],
$data[
'entries'][0][
'link']);
177 $this->assertContains($rssData[
'entries'][
'description'][
'description'],
$data[
'entries'][0][
'description']);
178 $this->assertContains($rssData[
'entries'][
'description'][
'start_date'],
$data[
'entries'][0][
'description']);
179 $this->assertContains($rssData[
'entries'][
'description'][
'end_date'],
$data[
'entries'][0][
'description']);
180 $this->assertContains($rssData[
'entries'][
'description'][
'coupon_code'],
$data[
'entries'][0][
'description']);
185 $this->assertEquals(0, $this->block->getCacheLifetime());
194 $this->scopeConfigInterface->expects($this->once())->method(
'isSetFlag')->will($this->returnValue(
$isAllowed));
195 $this->assertEquals(
$isAllowed, $this->block->isAllowed());
212 'label' =>
'Coupons/Discounts',
213 'link' =>
'http://rss.magento.com/discount',
215 $this->rssBuilderInterface->expects($this->any())
217 ->will($this->returnValue($feedData[
'link']));
219 $this->scopeConfigInterface->expects($this->once())->method(
'isSetFlag')->will($this->returnValue(
true));
220 $this->assertEquals($feedData, $this->block->getFeeds());