3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
6
7
namespace Magento \Catalog \Test \Unit \Block \Rss ;
7
8
8
9
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
@@ -73,6 +74,16 @@ class CategoryTest extends \PHPUnit\Framework\TestCase
73
74
*/
74
75
protected $ categoryRepository ;
75
76
77
+ /**
78
+ * @var \Magento\Framework\View\ConfigInterface|\PHPUnit_Framework_MockObject_MockObject
79
+ */
80
+ protected $ viewConfig ;
81
+
82
+ /**
83
+ * @var \Magento\Framework\Config\View
84
+ */
85
+ protected $ configView ;
86
+
76
87
/**
77
88
* @var array
78
89
*/
@@ -115,6 +126,8 @@ protected function setUp()
115
126
$ this ->storeManager ->expects ($ this ->any ())->method ('getStore ' )->will ($ this ->returnValue ($ store ));
116
127
$ this ->scopeConfig = $ this ->createMock (\Magento \Framework \App \Config \ScopeConfigInterface::class);
117
128
$ this ->categoryRepository = $ this ->createMock (\Magento \Catalog \Api \CategoryRepositoryInterface::class);
129
+ $ this ->viewConfig = $ this ->getMockBuilder (\Magento \Framework \View \ConfigInterface::class)
130
+ ->getMockForAbstractClass ();
118
131
$ objectManagerHelper = new ObjectManagerHelper ($ this );
119
132
$ this ->block = $ objectManagerHelper ->getObject (
120
133
\Magento \Catalog \Block \Rss \Category::class,
@@ -130,6 +143,7 @@ protected function setUp()
130
143
'customerSession ' => $ this ->customerSession ,
131
144
'storeManager ' => $ this ->storeManager ,
132
145
'categoryRepository ' => $ this ->categoryRepository ,
146
+ 'viewConfig ' => $ this ->viewConfig ,
133
147
]
134
148
);
135
149
}
@@ -145,16 +159,26 @@ public function testGetRssData()
145
159
146
160
$ this ->categoryRepository ->expects ($ this ->once ())->method ('get ' )->will ($ this ->returnValue ($ category ));
147
161
162
+ $ configViewMock = $ this ->getMockBuilder (\Magento \Framework \Config \View::class)
163
+ ->disableOriginalConstructor ()
164
+ ->getMock ();
165
+
166
+ $ this ->viewConfig ->expects ($ this ->once ())
167
+ ->method ('getViewConfig ' )
168
+ ->willReturn ($ configViewMock );
169
+
148
170
$ product = $ this ->getMockBuilder (\Magento \catalog \Model \Product::class)
149
- ->setMethods ([
150
- '__sleep ' ,
151
- '__wakeup ' ,
152
- 'getName ' ,
153
- 'getAllowedInRss ' ,
154
- 'getProductUrl ' ,
155
- 'getDescription ' ,
156
- 'getAllowedPriceInRss ' ,
157
- ])->disableOriginalConstructor ()->getMock ();
171
+ ->setMethods (
172
+ [
173
+ '__sleep ' ,
174
+ '__wakeup ' ,
175
+ 'getName ' ,
176
+ 'getAllowedInRss ' ,
177
+ 'getProductUrl ' ,
178
+ 'getDescription ' ,
179
+ 'getAllowedPriceInRss '
180
+ ]
181
+ )->disableOriginalConstructor ()->getMock ();
158
182
$ product ->expects ($ this ->once ())->method ('getName ' )->will ($ this ->returnValue ('Product Name ' ));
159
183
$ product ->expects ($ this ->once ())->method ('getAllowedInRss ' )->will ($ this ->returnValue (true ));
160
184
$ product ->expects ($ this ->exactly (2 ))->method ('getProductUrl ' )
@@ -213,23 +237,23 @@ public function testGetFeeds()
213
237
->disableOriginalConstructor ()->getMock ();
214
238
215
239
$ collection = $ this ->getMockBuilder (\Magento \Catalog \Model \ResourceModel \Category \Collection::class)
216
- ->setMethods ([
217
- 'addIdFilter ' ,
218
- 'addAttributeToSelect ' ,
219
- 'addAttributeToSort ' ,
220
- 'load ' ,
221
- 'addAttributeToFilter ' ,
222
- 'getIterator ' ,
223
- ])->disableOriginalConstructor ()->getMock ();
240
+ ->setMethods (
241
+ [
242
+ 'addIdFilter ' ,
243
+ 'addAttributeToSelect ' ,
244
+ 'addAttributeToSort ' ,
245
+ 'load ' ,
246
+ 'addAttributeToFilter ' ,
247
+ 'getIterator '
248
+ ]
249
+ )->disableOriginalConstructor ()->getMock ();
224
250
$ collection ->expects ($ this ->once ())->method ('addIdFilter ' )->will ($ this ->returnSelf ());
225
251
$ collection ->expects ($ this ->exactly (3 ))->method ('addAttributeToSelect ' )->will ($ this ->returnSelf ());
226
252
$ collection ->expects ($ this ->once ())->method ('addAttributeToSort ' )->will ($ this ->returnSelf ());
227
253
$ collection ->expects ($ this ->once ())->method ('addAttributeToFilter ' )->will ($ this ->returnSelf ());
228
254
$ collection ->expects ($ this ->once ())->method ('load ' )->will ($ this ->returnSelf ());
229
- $ collection ->expects ($ this ->once ())->method ('getIterator ' )->will ($ this ->returnValue (
230
- new \ArrayIterator ([$ category ])
231
- ));
232
-
255
+ $ collection ->expects ($ this ->once ())->method ('getIterator ' )
256
+ ->will ($ this ->returnValue (new \ArrayIterator ([$ category ])));
233
257
$ category ->expects ($ this ->once ())->method ('getId ' )->will ($ this ->returnValue (1 ));
234
258
$ category ->expects ($ this ->once ())->method ('getName ' )->will ($ this ->returnValue ('Category Name ' ));
235
259
$ category ->expects ($ this ->once ())->method ('getResourceCollection ' )->will ($ this ->returnValue ($ collection ));
@@ -250,9 +274,12 @@ public function testGetFeeds()
250
274
251
275
$ this ->rssUrlBuilder ->expects ($ this ->once ())->method ('getUrl ' )
252
276
->will ($ this ->returnValue ('http://magento.com/category-name.html ' ));
253
- $ feeds = ['group ' => 'Categories ' , 'feeds ' => [
254
- ['label ' => 'Category Name ' , 'link ' => 'http://magento.com/category-name.html ' ],
255
- ]];
277
+ $ feeds = [
278
+ 'group ' => 'Categories ' ,
279
+ 'feeds ' => [
280
+ ['label ' => 'Category Name ' , 'link ' => 'http://magento.com/category-name.html ' ],
281
+ ]
282
+ ];
256
283
$ this ->assertEquals ($ feeds , $ this ->block ->getFeeds ());
257
284
}
258
285
}
0 commit comments