17
17
use Magento \Catalog \Model \ResourceModel \Product \Compare \Item \Collection ;
18
18
use Magento \Framework \App \Config \ScopeConfigInterface ;
19
19
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
20
+ use Magento \Store \Model \Website ;
20
21
use PHPUnit \Framework \MockObject \MockObject ;
21
22
use PHPUnit \Framework \TestCase ;
23
+ use Magento \Store \Model \StoreManagerInterface ;
22
24
23
25
class CompareProductsTest extends TestCase
24
26
{
@@ -52,6 +54,16 @@ class CompareProductsTest extends TestCase
52
54
*/
53
55
private $ scopeConfigMock ;
54
56
57
+ /**
58
+ * @var StoreManagerInterface
59
+ */
60
+ private $ storeManagerMock ;
61
+
62
+ /**
63
+ * @var Website|MockObject
64
+ */
65
+ private $ websiteMock ;
66
+
55
67
/**
56
68
* @var array
57
69
*/
@@ -77,6 +89,18 @@ protected function setUp(): void
77
89
->disableOriginalConstructor ()
78
90
->getMockForAbstractClass ();
79
91
92
+ $ this ->storeManagerMock = $ this ->getMockBuilder (
93
+ StoreManagerInterface::class
94
+ )->disableOriginalConstructor ()
95
+ ->getMockForAbstractClass ();
96
+
97
+ $ this ->websiteMock = $ this ->getMockBuilder (
98
+ Website::class
99
+ )->onlyMethods (
100
+ ['getId ' ,]
101
+ )->disableOriginalConstructor ()
102
+ ->getMock ();
103
+
80
104
$ this ->objectManagerHelper = new ObjectManagerHelper ($ this );
81
105
82
106
$ this ->model = $ this ->objectManagerHelper ->getObject (
@@ -85,7 +109,9 @@ protected function setUp(): void
85
109
'helper ' => $ this ->helperMock ,
86
110
'productUrl ' => $ this ->productUrlMock ,
87
111
'outputHelper ' => $ this ->outputHelperMock ,
88
- 'scopeConfig ' => $ this ->scopeConfigMock
112
+ 'scopeConfig ' => $ this ->scopeConfigMock ,
113
+ 'storeManager ' => $ this ->storeManagerMock
114
+
89
115
]
90
116
);
91
117
}
@@ -196,7 +222,8 @@ public function testGetSectionData()
196
222
$ this ->helperMock ->expects ($ this ->once ())
197
223
->method ('getListUrl ' )
198
224
->willReturn ('http://list.url ' );
199
-
225
+ $ this ->storeManagerMock ->expects ($ this ->any ())->method ('getWebsite ' )->willReturn ($ this ->websiteMock );
226
+ $ this ->websiteMock ->expects ($ this ->any ())->method ('getId ' )->willReturn (1 );
200
227
$ this ->assertEquals (
201
228
[
202
229
'count ' => $ count ,
@@ -224,7 +251,8 @@ public function testGetSectionData()
224
251
'remove_url ' => 'http://remove.url/3 ' ,
225
252
'productScope ' => null
226
253
]
227
- ]
254
+ ],
255
+ 'websiteId ' => 1
228
256
],
229
257
$ this ->model ->getSectionData ()
230
258
);
@@ -245,12 +273,16 @@ public function testGetSectionDataNoItems()
245
273
->method ('getListUrl ' )
246
274
->willReturn ('http://list.url ' );
247
275
276
+ $ this ->storeManagerMock ->expects ($ this ->any ())->method ('getWebsite ' )->willReturn ($ this ->websiteMock );
277
+ $ this ->websiteMock ->expects ($ this ->any ())->method ('getId ' )->willReturn (1 );
278
+
248
279
$ this ->assertEquals (
249
280
[
250
281
'count ' => $ count ,
251
282
'countCaption ' => __ ('%1 items ' , $ count ),
252
283
'listUrl ' => 'http://list.url ' ,
253
- 'items ' => []
284
+ 'items ' => [],
285
+ 'websiteId ' => 1
254
286
],
255
287
$ this ->model ->getSectionData ()
256
288
);
@@ -264,6 +296,9 @@ public function testGetSectionDataSingleItem()
264
296
->method ('getItemCount ' )
265
297
->willReturn ($ count );
266
298
299
+ $ this ->storeManagerMock ->expects ($ this ->any ())->method ('getWebsite ' )->willReturn ($ this ->websiteMock );
300
+ $ this ->websiteMock ->expects ($ this ->any ())->method ('getId ' )->willReturn (1 );
301
+
267
302
$ items = $ this ->prepareProductsWithCorrespondingMocks (
268
303
[
269
304
[
@@ -296,7 +331,8 @@ public function testGetSectionDataSingleItem()
296
331
'remove_url ' => 'http://remove.url/12345 ' ,
297
332
'productScope ' => null
298
333
]
299
- ]
334
+ ],
335
+ 'websiteId ' => 1
300
336
],
301
337
$ this ->model ->getSectionData ()
302
338
);
0 commit comments