@@ -49,6 +49,26 @@ class ListProductTest extends \PHPUnit_Framework_TestCase
49
49
* @var \Magento\Framework\Url\Helper\Data | \PHPUnit_Framework_MockObject_MockObject
50
50
*/
51
51
protected $ urlHelperMock ;
52
+
53
+ /**
54
+ * @var \Magento\Catalog\Model\ResourceModel\Category | \PHPUnit_Framework_MockObject_MockObject
55
+ */
56
+ protected $ catCollectionMock ;
57
+
58
+ /**
59
+ * @var \Magento\Catalog\Model\ResourceModel\Product | \PHPUnit_Framework_MockObject_MockObject
60
+ */
61
+ protected $ prodCollectionMock ;
62
+
63
+ /**
64
+ * @var \Magento\Framework\View\LayoutInterface | \PHPUnit_Framework_MockObject_MockObject
65
+ */
66
+ protected $ layoutMock ;
67
+
68
+ /**
69
+ * @var \Magento\Catalog\Block\Product\ProductList\Toolbar | \PHPUnit_Framework_MockObject_MockObject
70
+ */
71
+ protected $ toolbarMock ;
52
72
53
73
protected function setUp ()
54
74
{
@@ -92,6 +112,34 @@ protected function setUp()
92
112
'' ,
93
113
false
94
114
);
115
+ $ this ->catCollectionMock = $ this ->getMock (
116
+ \Magento \Catalog \Model \ResourceModel \Category \Collection::class,
117
+ [],
118
+ [],
119
+ '' ,
120
+ false
121
+ );
122
+ $ this ->prodCollectionMock = $ this ->getMock (
123
+ \Magento \Catalog \Model \ResourceModel \Product \Collection::class,
124
+ [],
125
+ [],
126
+ '' ,
127
+ false
128
+ );
129
+ $ this ->layoutMock = $ this ->getMock (
130
+ \Magento \Framework \View \LayoutInterface::class,
131
+ [],
132
+ [],
133
+ '' ,
134
+ false
135
+ );
136
+ $ this ->toolbarMock = $ this ->getMock (
137
+ \Magento \Catalog \Block \Product \ProductList \Toolbar::class,
138
+ [],
139
+ [],
140
+ '' ,
141
+ false
142
+ );
95
143
96
144
$ this ->urlHelperMock = $ this ->getMockBuilder (\Magento \Framework \Url \Helper \Data::class)
97
145
->disableOriginalConstructor ()->getMock ();
@@ -105,6 +153,8 @@ protected function setUp()
105
153
'urlHelper ' => $ this ->urlHelperMock ,
106
154
]
107
155
);
156
+ $ this ->block ->setToolbarBlockName ('mock ' );
157
+ $ this ->block ->setLayout ($ this ->layoutMock );
108
158
}
109
159
110
160
protected function tearDown ()
@@ -121,26 +171,59 @@ public function testGetIdentities()
121
171
->method ('getIdentities ' )
122
172
->will ($ this ->returnValue ([$ productTag ]));
123
173
124
- $ itemsCollection = new \ReflectionProperty (
125
- \Magento \Catalog \Block \Product \ListProduct::class,
126
- '_productCollection '
127
- );
128
- $ itemsCollection ->setAccessible (true );
129
- $ itemsCollection ->setValue ($ this ->block , [$ this ->productMock ]);
174
+ $ this ->productMock ->expects ($ this ->once ())
175
+ ->method ('getCategoryCollection ' )
176
+ ->will ($ this ->returnValue ($ this ->catCollectionMock ));
177
+
178
+ $ this ->catCollectionMock ->expects ($ this ->once ())
179
+ ->method ('load ' )
180
+ ->will ($ this ->returnValue ($ this ->catCollectionMock ));
181
+
182
+ $ this ->catCollectionMock ->expects ($ this ->once ())
183
+ ->method ('setPage ' )
184
+ ->will ($ this ->returnValue ($ this ->catCollectionMock ));
185
+
186
+ $ this ->catCollectionMock ->expects ($ this ->once ())
187
+ ->method ('count ' )
188
+ ->will ($ this ->returnValue (1 ));
189
+
190
+ $ this ->registryMock ->expects ($ this ->any ())
191
+ ->method ('registry ' )
192
+ ->will ($ this ->returnValue ($ this ->productMock ));
130
193
131
194
$ currentCategory = $ this ->getMock (\Magento \Catalog \Model \Category::class, [], [], '' , false );
132
- $ currentCategory ->expects ($ this ->once ())
195
+ $ currentCategory ->expects ($ this ->any ())
133
196
->method ('getId ' )
134
197
->will ($ this ->returnValue ('1 ' ));
135
198
136
- $ this ->layerMock ->expects ($ this ->once ())
199
+ $ this ->catCollectionMock ->expects ($ this ->once ())
200
+ ->method ('getIterator ' )
201
+ ->will ($ this ->returnValue ([$ currentCategory ]));
202
+
203
+ $ this ->prodCollectionMock ->expects ($ this ->any ())
204
+ ->method ('getIterator ' )
205
+ ->will ($ this ->returnValue (new \ArrayIterator ([$ this ->productMock ])));
206
+
207
+ $ this ->layerMock ->expects ($ this ->any ())
137
208
->method ('getCurrentCategory ' )
138
209
->will ($ this ->returnValue ($ currentCategory ));
139
210
211
+ $ this ->layerMock ->expects ($ this ->once ())
212
+ ->method ('getProductCollection ' )
213
+ ->will ($ this ->returnValue ($ this ->prodCollectionMock ));
214
+
215
+ $ this ->layoutMock ->expects ($ this ->once ())
216
+ ->method ('getBlock ' )
217
+ ->will ($ this ->returnValue ($ this ->toolbarMock ));
218
+
140
219
$ this ->assertEquals (
141
- [$ productTag , $ categoryTag ],
220
+ [$ productTag , $ categoryTag ],
142
221
$ this ->block ->getIdentities ()
143
222
);
223
+ $ this ->assertEquals (
224
+ '1 ' ,
225
+ $ this ->block ->getCategoryId ()
226
+ );
144
227
}
145
228
146
229
public function testGetAddToCartPostParams ()
0 commit comments