1
- <?php
1
+ <?php declare (strict_types= 1 );
2
2
/**
3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
6
7
7
namespace Magento \CatalogWidget \Test \Unit \Block \Product ;
8
8
9
+ use Magento \Catalog \Block \Product \Widget \Html \Pager ;
10
+ use Magento \Catalog \Model \Product ;
9
11
use Magento \Catalog \Model \Product \Visibility ;
10
-
12
+ use Magento \Catalog \Model \ResourceModel \Product \Collection ;
13
+ use Magento \Catalog \Model \ResourceModel \Product \CollectionFactory ;
11
14
use Magento \CatalogWidget \Block \Product \ProductsList ;
15
+ use Magento \CatalogWidget \Model \Rule ;
16
+ use Magento \Directory \Model \Currency ;
17
+ use Magento \Framework \App \Http \Context ;
18
+ use Magento \Framework \App \RequestInterface ;
19
+ use Magento \Framework \DataObject \IdentityInterface ;
12
20
use Magento \Framework \Pricing \PriceCurrencyInterface ;
21
+ use Magento \Framework \Pricing \Render ;
22
+ use Magento \Framework \Serialize \Serializer \Json ;
13
23
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
24
+ use Magento \Framework \View \Design \ThemeInterface ;
25
+ use Magento \Framework \View \DesignInterface ;
26
+ use Magento \Framework \View \LayoutInterface ;
27
+ use Magento \Rule \Model \Condition \Combine ;
28
+ use Magento \Rule \Model \Condition \Sql \Builder ;
29
+ use Magento \Store \Model \Store ;
30
+ use Magento \Store \Model \StoreManagerInterface ;
31
+
32
+ use Magento \Widget \Helper \Conditions ;
33
+ use PHPUnit \Framework \MockObject \MockObject ;
34
+ use PHPUnit \Framework \TestCase ;
14
35
15
36
/**
16
- * Class ProductsListTest
17
37
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
18
38
*/
19
- class ProductsListTest extends \ PHPUnit \ Framework \ TestCase
39
+ class ProductsListTest extends TestCase
20
40
{
21
41
/**
22
- * @var \Magento\CatalogWidget\Block\Product\ ProductsList
42
+ * @var ProductsList
23
43
*/
24
44
protected $ productsList ;
25
45
26
46
/**
27
- * @var \Magento\Catalog\Model\ResourceModel\Product\ CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
47
+ * @var CollectionFactory|MockObject
28
48
*/
29
49
protected $ collectionFactory ;
30
50
31
51
/**
32
- * @var \Magento\Catalog\Model\Product\ Visibility|\PHPUnit_Framework_MockObject_MockObject
52
+ * @var Visibility|MockObject
33
53
*/
34
54
protected $ visibility ;
35
55
36
56
/**
37
- * @var \Magento\Framework\App\Http\ Context|\PHPUnit_Framework_MockObject_MockObject
57
+ * @var Context|MockObject
38
58
*/
39
59
protected $ httpContext ;
40
60
41
61
/**
42
- * @var \Magento\Rule\Model\Condition\Sql\ Builder|\PHPUnit_Framework_MockObject_MockObject
62
+ * @var Builder|MockObject
43
63
*/
44
64
protected $ builder ;
45
65
46
66
/**
47
- * @var \Magento\CatalogWidget\Model\ Rule|\PHPUnit_Framework_MockObject_MockObject
67
+ * @var Rule|MockObject
48
68
*/
49
69
protected $ rule ;
50
70
51
71
/**
52
- * @var \Magento\Widget\Helper\ Conditions|\PHPUnit_Framework_MockObject_MockObject
72
+ * @var Conditions|MockObject
53
73
*/
54
74
protected $ widgetConditionsHelper ;
55
75
56
76
/**
57
- * @var \Magento\Store\Model\ StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
77
+ * @var StoreManagerInterface|MockObject
58
78
*/
59
79
protected $ storeManager ;
60
80
61
81
/**
62
- * @var \Magento\Framework\View\ DesignInterface
82
+ * @var DesignInterface
63
83
*/
64
84
protected $ design ;
65
85
66
86
/**
67
- * @var \Magento\Framework\App\ RequestInterface
87
+ * @var RequestInterface
68
88
*/
69
89
protected $ request ;
70
90
71
91
/**
72
- * @var \Magento\Framework\View\ LayoutInterface
92
+ * @var LayoutInterface
73
93
*/
74
94
protected $ layout ;
75
95
76
96
/**
77
- * @var PriceCurrencyInterface|\PHPUnit_Framework_MockObject_MockObject
97
+ * @var PriceCurrencyInterface|MockObject
78
98
*/
79
99
private $ priceCurrency ;
80
100
81
101
/**
82
- * @var \Magento\Framework\Serialize\Serializer\ Json|\PHPUnit_Framework_MockObject_MockObject
102
+ * @var Json|MockObject
83
103
*/
84
104
private $ serializer ;
85
105
86
- protected function setUp ()
106
+ protected function setUp (): void
87
107
{
88
108
$ this ->collectionFactory =
89
- $ this ->getMockBuilder (\ Magento \ Catalog \ Model \ ResourceModel \ Product \ CollectionFactory::class)
109
+ $ this ->getMockBuilder (CollectionFactory::class)
90
110
->setMethods (['create ' ])
91
111
->disableOriginalConstructor ()->getMock ();
92
- $ this ->visibility = $ this ->getMockBuilder (\ Magento \ Catalog \ Model \ Product \ Visibility::class)
112
+ $ this ->visibility = $ this ->getMockBuilder (Visibility::class)
93
113
->setMethods (['getVisibleInCatalogIds ' ])
94
114
->disableOriginalConstructor ()
95
115
->getMock ();
96
- $ this ->httpContext = $ this ->createMock (\ Magento \ Framework \ App \ Http \ Context::class);
97
- $ this ->builder = $ this ->createMock (\ Magento \ Rule \ Model \ Condition \ Sql \ Builder::class);
98
- $ this ->rule = $ this ->createMock (\ Magento \ CatalogWidget \ Model \ Rule::class);
99
- $ this ->serializer = $ this ->createMock (\ Magento \ Framework \ Serialize \ Serializer \ Json::class);
100
- $ this ->widgetConditionsHelper = $ this ->getMockBuilder (\ Magento \ Widget \ Helper \ Conditions::class)
116
+ $ this ->httpContext = $ this ->createMock (Context::class);
117
+ $ this ->builder = $ this ->createMock (Builder::class);
118
+ $ this ->rule = $ this ->createMock (Rule::class);
119
+ $ this ->serializer = $ this ->createMock (Json::class);
120
+ $ this ->widgetConditionsHelper = $ this ->getMockBuilder (Conditions::class)
101
121
->disableOriginalConstructor ()
102
122
->getMock ();
103
- $ this ->storeManager = $ this ->createMock (\ Magento \ Store \ Model \ StoreManagerInterface::class);
104
- $ this ->design = $ this ->createMock (\ Magento \ Framework \ View \ DesignInterface::class);
123
+ $ this ->storeManager = $ this ->createMock (StoreManagerInterface::class);
124
+ $ this ->design = $ this ->createMock (DesignInterface::class);
105
125
106
126
$ objectManagerHelper = new ObjectManagerHelper ($ this );
107
127
$ arguments = $ objectManagerHelper ->getConstructArguments (
108
- \ Magento \ CatalogWidget \ Block \ Product \ ProductsList::class,
128
+ ProductsList::class,
109
129
[
110
130
'productCollectionFactory ' => $ this ->collectionFactory ,
111
131
'catalogProductVisibility ' => $ this ->visibility ,
@@ -123,20 +143,20 @@ protected function setUp()
123
143
$ this ->priceCurrency = $ this ->createMock (PriceCurrencyInterface::class);
124
144
125
145
$ this ->productsList = $ objectManagerHelper ->getObject (
126
- \ Magento \ CatalogWidget \ Block \ Product \ ProductsList::class,
146
+ ProductsList::class,
127
147
$ arguments
128
148
);
129
149
$ objectManagerHelper ->setBackwardCompatibleProperty ($ this ->productsList , 'priceCurrency ' , $ this ->priceCurrency );
130
150
}
131
151
132
152
public function testGetCacheKeyInfo ()
133
153
{
134
- $ store = $ this ->getMockBuilder (\ Magento \ Store \ Model \ Store::class)
154
+ $ store = $ this ->getMockBuilder (Store::class)
135
155
->disableOriginalConstructor ()->setMethods (['getId ' ])->getMock ();
136
156
$ store ->expects ($ this ->once ())->method ('getId ' )->willReturn (1 );
137
157
$ this ->storeManager ->expects ($ this ->once ())->method ('getStore ' )->willReturn ($ store );
138
158
139
- $ theme = $ this ->createMock (\ Magento \ Framework \ View \ Design \ ThemeInterface::class);
159
+ $ theme = $ this ->createMock (ThemeInterface::class);
140
160
$ theme ->expects ($ this ->once ())->method ('getId ' )->willReturn ('blank ' );
141
161
$ this ->design ->expects ($ this ->once ())->method ('getDesignTheme ' )->willReturn ($ theme );
142
162
@@ -149,7 +169,7 @@ public function testGetCacheKeyInfo()
149
169
$ this ->request ->expects ($ this ->once ())->method ('getParam ' )->with ('page_number ' )->willReturn (1 );
150
170
151
171
$ this ->request ->expects ($ this ->once ())->method ('getParams ' )->willReturn ('request_params ' );
152
- $ currency = $ this ->createMock (\ Magento \ Directory \ Model \ Currency::class);
172
+ $ currency = $ this ->createMock (Currency::class);
153
173
$ currency ->expects ($ this ->once ())->method ('getCode ' )->willReturn ('USD ' );
154
174
$ this ->priceCurrency ->expects ($ this ->once ())->method ('getCurrency ' )->willReturn ($ currency );
155
175
@@ -178,13 +198,13 @@ public function testGetCacheKeyInfo()
178
198
179
199
public function testGetProductPriceHtml ()
180
200
{
181
- $ product = $ this ->getMockBuilder (\ Magento \ Catalog \ Model \ Product::class)
201
+ $ product = $ this ->getMockBuilder (Product::class)
182
202
->setMethods (['getId ' ])
183
203
->disableOriginalConstructor ()
184
204
->getMock ();
185
205
$ product ->expects ($ this ->once ())->method ('getId ' )->willReturn (1 );
186
206
187
- $ priceRenderer = $ this ->getMockBuilder (\ Magento \ Framework \ Pricing \ Render::class)
207
+ $ priceRenderer = $ this ->getMockBuilder (Render::class)
188
208
->setMethods (['render ' ])
189
209
->disableOriginalConstructor ()
190
210
->getMock ();
@@ -202,7 +222,7 @@ public function testGetProductPriceHtml()
202
222
$ this ->assertEquals ('<html> ' , $ this ->productsList ->getProductPriceHtml (
203
223
$ product ,
204
224
'some-price-type ' ,
205
- \ Magento \ Framework \ Pricing \ Render::ZONE_ITEM_LIST ,
225
+ Render::ZONE_ITEM_LIST ,
206
226
[
207
227
'include_container ' => false ,
208
228
'display_minimal_price ' => false
@@ -217,7 +237,7 @@ public function testGetPagerHtmlEmpty()
217
237
218
238
public function testGetPagerHtml ()
219
239
{
220
- $ collection = $ this ->getMockBuilder (\ Magento \ Catalog \ Model \ ResourceModel \ Product \ Collection::class)
240
+ $ collection = $ this ->getMockBuilder (Collection::class)
221
241
->setMethods (['getSize ' ])
222
242
->disableOriginalConstructor ()
223
243
->getMock ();
@@ -227,7 +247,7 @@ public function testGetPagerHtml()
227
247
$ this ->productsList ->setData ('products_per_page ' , 2 );
228
248
$ this ->productsList ->setData ('product_collection ' , $ collection );
229
249
230
- $ pagerBlock = $ this ->getMockBuilder (\ Magento \ Catalog \ Block \ Product \ Widget \ Html \ Pager::class)
250
+ $ pagerBlock = $ this ->getMockBuilder (Pager::class)
231
251
->setMethods ([
232
252
'toHtml ' ,
233
253
'setUseContainer ' ,
@@ -266,7 +286,7 @@ public function testCreateCollection($pagerEnable, $productsCount, $productsPerP
266
286
{
267
287
$ this ->visibility ->expects ($ this ->once ())->method ('getVisibleInCatalogIds ' )
268
288
->willReturn ([Visibility::VISIBILITY_IN_CATALOG , Visibility::VISIBILITY_BOTH ]);
269
- $ collection = $ this ->getMockBuilder (\ Magento \ Catalog \ Model \ ResourceModel \ Product \ Collection::class)
289
+ $ collection = $ this ->getMockBuilder (Collection::class)
270
290
->setMethods ([
271
291
'setVisibility ' ,
272
292
'addMinimalPrice ' ,
@@ -367,14 +387,14 @@ public function testShowPager()
367
387
368
388
public function testGetIdentities ()
369
389
{
370
- $ collection = $ this ->getMockBuilder (\ Magento \ Catalog \ Model \ ResourceModel \ Product \ Collection::class)
390
+ $ collection = $ this ->getMockBuilder (Collection::class)
371
391
->setMethods ([
372
392
'addAttributeToSelect ' ,
373
393
'getIterator ' ,
374
394
])->disableOriginalConstructor ()
375
395
->getMock ();
376
396
377
- $ product = $ this ->createPartialMock (\ Magento \ Framework \ DataObject \ IdentityInterface::class, ['getIdentities ' ]);
397
+ $ product = $ this ->createPartialMock (IdentityInterface::class, ['getIdentities ' ]);
378
398
$ notProduct = $ this ->getMockBuilder ('NotProduct ' )
379
399
->setMethods (['getIdentities ' ])
380
400
->disableOriginalConstructor ()
@@ -394,11 +414,11 @@ public function testGetIdentities()
394
414
/**
395
415
* @param $collection
396
416
*
397
- * @return \PHPUnit_Framework_MockObject_MockObject
417
+ * @return MockObject
398
418
*/
399
419
private function getConditionsForCollection ($ collection )
400
420
{
401
- $ conditions = $ this ->getMockBuilder (\ Magento \ Rule \ Model \ Condition \ Combine::class)
421
+ $ conditions = $ this ->getMockBuilder (Combine::class)
402
422
->setMethods (['collectValidatedAttributes ' ])
403
423
->disableOriginalConstructor ()
404
424
->getMock ();
0 commit comments