10
10
11
11
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
12
12
use Magento \Catalog \Model \Product \Visibility ;
13
+ use Magento \Framework \Pricing \PriceCurrencyInterface ;
13
14
14
15
/**
15
- * Class ProductsListTest
16
+ * Test for \Magento\CatalogWidget\Block\Product\ProductsList.
16
17
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
17
18
*/
18
19
class ProductsListTest extends \PHPUnit_Framework_TestCase
@@ -72,26 +73,32 @@ class ProductsListTest extends \PHPUnit_Framework_TestCase
72
73
*/
73
74
protected $ layout ;
74
75
76
+ /**
77
+ * @var PriceCurrencyInterface|\PHPUnit_Framework_MockObject_MockObject
78
+ */
79
+ private $ priceCurrency ;
80
+
75
81
protected function setUp ()
76
82
{
83
+ $ this ->priceCurrency = $ this ->getMock (PriceCurrencyInterface::class);
77
84
$ this ->collectionFactory =
78
- $ this ->getMockBuilder (' Magento\Catalog\Model\ResourceModel\Product\CollectionFactory ' )
85
+ $ this ->getMockBuilder (\ Magento \Catalog \Model \ResourceModel \Product \CollectionFactory::class )
79
86
->setMethods (['create ' ])
80
87
->disableOriginalConstructor ()->getMock ();
81
- $ this ->visibility = $ this ->getMockBuilder (' Magento\Catalog\Model\Product\Visibility ' )
88
+ $ this ->visibility = $ this ->getMockBuilder (\ Magento \Catalog \Model \Product \Visibility::class )
82
89
->setMethods (['getVisibleInCatalogIds ' ])
83
90
->disableOriginalConstructor ()
84
91
->getMock ();
85
- $ this ->httpContext = $ this ->getMock (' Magento\Framework\App\Http\Context ' );
86
- $ this ->builder = $ this ->getMock (' Magento\Rule\Model\Condition\Sql\Builder ' , [], [], '' , false );
87
- $ this ->rule = $ this ->getMock (' Magento\CatalogWidget\Model\Rule ' , [], [], '' , false );
88
- $ this ->widgetConditionsHelper = $ this ->getMock (' Magento\Widget\Helper\Conditions ' );
89
- $ this ->storeManager = $ this ->getMock (' \Magento\Store\Model\StoreManagerInterface ' );
90
- $ this ->design = $ this ->getMock (' \Magento\Framework\View\DesignInterface ' );
92
+ $ this ->httpContext = $ this ->getMock (\ Magento \Framework \App \Http \Context::class );
93
+ $ this ->builder = $ this ->getMock (\ Magento \Rule \Model \Condition \Sql \Builder::class , [], [], '' , false );
94
+ $ this ->rule = $ this ->getMock (\ Magento \CatalogWidget \Model \Rule::class , [], [], '' , false );
95
+ $ this ->widgetConditionsHelper = $ this ->getMock (\ Magento \Widget \Helper \Conditions::class );
96
+ $ this ->storeManager = $ this ->getMock (\Magento \Store \Model \StoreManagerInterface::class );
97
+ $ this ->design = $ this ->getMock (\Magento \Framework \View \DesignInterface::class );
91
98
92
99
$ objectManagerHelper = new ObjectManagerHelper ($ this );
93
100
$ arguments = $ objectManagerHelper ->getConstructArguments (
94
- ' Magento\CatalogWidget\Block\Product\ProductsList ' ,
101
+ \ Magento \CatalogWidget \Block \Product \ProductsList::class ,
95
102
[
96
103
'productCollectionFactory ' => $ this ->collectionFactory ,
97
104
'catalogProductVisibility ' => $ this ->visibility ,
@@ -100,59 +107,60 @@ protected function setUp()
100
107
'rule ' => $ this ->rule ,
101
108
'conditionsHelper ' => $ this ->widgetConditionsHelper ,
102
109
'storeManager ' => $ this ->storeManager ,
103
- 'design ' => $ this ->design
110
+ 'design ' => $ this ->design ,
111
+ 'priceCurrency ' => $ this ->priceCurrency ,
104
112
]
105
113
);
106
114
$ this ->request = $ arguments ['context ' ]->getRequest ();
107
115
$ this ->layout = $ arguments ['context ' ]->getLayout ();
108
116
109
117
$ this ->productsList = $ objectManagerHelper ->getObject (
110
- ' Magento\CatalogWidget\Block\Product\ProductsList ' ,
118
+ \ Magento \CatalogWidget \Block \Product \ProductsList::class ,
111
119
$ arguments
112
120
);
113
121
}
114
122
115
123
public function testGetCacheKeyInfo ()
116
124
{
117
- $ store = $ this ->getMockBuilder (' \Magento\Store\Model\Store ' )
125
+ $ store = $ this ->getMockBuilder (\Magento \Store \Model \Store::class )
118
126
->disableOriginalConstructor ()->setMethods (['getId ' ])->getMock ();
119
127
$ store ->expects ($ this ->once ())->method ('getId ' )->willReturn (1 );
120
128
$ this ->storeManager ->expects ($ this ->once ())->method ('getStore ' )->willReturn ($ store );
121
129
122
- $ theme = $ this ->getMock (' \Magento\Framework\View\Design\ThemeInterface ' );
130
+ $ theme = $ this ->getMock (\Magento \Framework \View \Design \ThemeInterface::class );
123
131
$ theme ->expects ($ this ->once ())->method ('getId ' )->willReturn ('blank ' );
124
132
$ this ->design ->expects ($ this ->once ())->method ('getDesignTheme ' )->willReturn ($ theme );
125
133
126
134
$ this ->httpContext ->expects ($ this ->once ())->method ('getValue ' )->willReturn ('context_group ' );
127
135
$ this ->productsList ->setData ('conditions ' , 'some_serialized_conditions ' );
128
-
129
136
$ this ->productsList ->setData ('page_var_name ' , 'page_number ' );
130
137
$ this ->request ->expects ($ this ->once ())->method ('getParam ' )->with ('page_number ' )->willReturn (1 );
131
-
132
138
$ this ->request ->expects ($ this ->once ())->method ('getParams ' )->willReturn ('request_params ' );
139
+ $ this ->priceCurrency ->expects ($ this ->once ())->method ('getCurrencySymbol ' )->willReturn ('$ ' );
133
140
134
141
$ cacheKey = [
135
142
'CATALOG_PRODUCTS_LIST_WIDGET ' ,
143
+ '$ ' ,
136
144
1 ,
137
145
'blank ' ,
138
146
'context_group ' ,
139
147
1 ,
140
148
5 ,
141
149
'some_serialized_conditions ' ,
142
- serialize ('request_params ' )
150
+ serialize ('request_params ' ),
143
151
];
144
152
$ this ->assertEquals ($ cacheKey , $ this ->productsList ->getCacheKeyInfo ());
145
153
}
146
154
147
155
public function testGetProductPriceHtml ()
148
156
{
149
- $ product = $ this ->getMockBuilder (' Magento\Catalog\Model\Product ' )
157
+ $ product = $ this ->getMockBuilder (\ Magento \Catalog \Model \Product::class )
150
158
->setMethods (['getId ' ])
151
159
->disableOriginalConstructor ()
152
160
->getMock ();
153
161
$ product ->expects ($ this ->once ())->method ('getId ' )->willReturn (1 );
154
162
155
- $ priceRenderer = $ this ->getMockBuilder (' \Magento\Framework\Pricing\Render ' )
163
+ $ priceRenderer = $ this ->getMockBuilder (\Magento \Framework \Pricing \Render::class )
156
164
->setMethods (['render ' ])
157
165
->disableOriginalConstructor ()
158
166
->getMock ();
@@ -173,7 +181,7 @@ public function testGetProductPriceHtml()
173
181
\Magento \Framework \Pricing \Render::ZONE_ITEM_LIST ,
174
182
[
175
183
'include_container ' => false ,
176
- 'display_minimal_price ' => false
184
+ 'display_minimal_price ' => false ,
177
185
]
178
186
));
179
187
}
@@ -185,7 +193,7 @@ public function testGetPagerHtmlEmpty()
185
193
186
194
public function testGetPagerHtml ()
187
195
{
188
- $ collection = $ this ->getMockBuilder (' \Magento\Catalog\Model\ResourceModel\Product\Collection ' )
196
+ $ collection = $ this ->getMockBuilder (\Magento \Catalog \Model \ResourceModel \Product \Collection::class )
189
197
->setMethods (['getSize ' ])
190
198
->disableOriginalConstructor ()
191
199
->getMock ();
@@ -195,7 +203,7 @@ public function testGetPagerHtml()
195
203
$ this ->productsList ->setData ('products_per_page ' , 2 );
196
204
$ this ->productsList ->setData ('product_collection ' , $ collection );
197
205
198
- $ pagerBlock = $ this ->getMockBuilder (' Magento\Catalog\Block\Product\Widget\Html\Pager ' )
206
+ $ pagerBlock = $ this ->getMockBuilder (\ Magento \Catalog \Block \Product \Widget \Html \Pager::class )
199
207
->setMethods ([
200
208
'toHtml ' ,
201
209
'setUseContainer ' ,
@@ -205,7 +213,9 @@ public function testGetPagerHtml()
205
213
'setLimit ' ,
206
214
'setTotalLimit ' ,
207
215
'setCollection ' ,
208
- ])->disableOriginalConstructor ()->getMock ();
216
+ ])
217
+ ->disableOriginalConstructor ()
218
+ ->getMock ();
209
219
210
220
$ pagerBlock ->expects ($ this ->once ())->method ('setUseContainer ' )->willReturnSelf ();
211
221
$ pagerBlock ->expects ($ this ->once ())->method ('setShowAmounts ' )->willReturnSelf ();
@@ -233,7 +243,7 @@ public function testCreateCollection($pagerEnable, $productsCount, $productsPerP
233
243
{
234
244
$ this ->visibility ->expects ($ this ->once ())->method ('getVisibleInCatalogIds ' )
235
245
->willReturn ([Visibility::VISIBILITY_IN_CATALOG , Visibility::VISIBILITY_BOTH ]);
236
- $ collection = $ this ->getMockBuilder (' \Magento\Catalog\Model\ResourceModel\Product\Collection ' )
246
+ $ collection = $ this ->getMockBuilder (\Magento \Catalog \Model \ResourceModel \Product \Collection::class )
237
247
->setMethods ([
238
248
'setVisibility ' ,
239
249
'addMinimalPrice ' ,
@@ -322,14 +332,15 @@ public function testShowPager()
322
332
323
333
public function testGetIdentities ()
324
334
{
325
- $ collection = $ this ->getMockBuilder (' \Magento\Catalog\Model\ResourceModel\Product\Collection ' )
335
+ $ collection = $ this ->getMockBuilder (\Magento \Catalog \Model \ResourceModel \Product \Collection::class )
326
336
->setMethods ([
327
337
'addAttributeToSelect ' ,
328
338
'getIterator ' ,
329
- ])->disableOriginalConstructor ()
339
+ ])
340
+ ->disableOriginalConstructor ()
330
341
->getMock ();
331
342
332
- $ product = $ this ->getMock (' Magento\Framework\DataObject\IdentityInterface ' , ['getIdentities ' ]);
343
+ $ product = $ this ->getMock (\ Magento \Framework \DataObject \IdentityInterface::class , ['getIdentities ' ]);
333
344
$ notProduct = $ this ->getMock ('NotProduct ' , ['getIdentities ' ]);
334
345
$ product ->expects ($ this ->once ())->method ('getIdentities ' )->willReturn (['product_identity ' ]);
335
346
$ collection ->expects ($ this ->once ())->method ('getIterator ' )->willReturn (
@@ -349,7 +360,7 @@ public function testGetIdentities()
349
360
*/
350
361
private function getConditionsForCollection ($ collection )
351
362
{
352
- $ conditions = $ this ->getMockBuilder (' \Magento\Rule\Model\Condition\Combine ' )
363
+ $ conditions = $ this ->getMockBuilder (\Magento \Rule \Model \Condition \Combine::class )
353
364
->setMethods (['collectValidatedAttributes ' ])
354
365
->disableOriginalConstructor ()
355
366
->getMock ();
@@ -359,6 +370,7 @@ private function getConditionsForCollection($collection)
359
370
360
371
$ this ->rule ->expects ($ this ->once ())->method ('loadPost ' )->willReturnSelf ();
361
372
$ this ->rule ->expects ($ this ->once ())->method ('getConditions ' )->willReturn ($ conditions );
373
+
362
374
return $ conditions ;
363
375
}
364
376
0 commit comments