@@ -261,21 +261,10 @@ public function testCreateCollection($pagerEnable, $productsCount, $productsPerP
261
261
$ this ->collectionFactory ->expects ($ this ->once ())->method ('create ' )->willReturn ($ collection );
262
262
$ this ->productsList ->setData ('conditions_encoded ' , 'some_serialized_conditions ' );
263
263
264
- $ conditions = $ this ->getMockBuilder ('\Magento\Rule\Model\Condition\Combine ' )
265
- ->setMethods (['collectValidatedAttributes ' ])
266
- ->disableOriginalConstructor ()
267
- ->getMock ();
268
- $ conditions ->expects ($ this ->once ())->method ('collectValidatedAttributes ' )
269
- ->with ($ collection )
270
- ->willReturnSelf ();
271
-
272
264
$ this ->builder ->expects ($ this ->once ())->method ('attachConditionToCollection ' )
273
- ->with ($ collection , $ conditions )
265
+ ->with ($ collection , $ this -> getConditionsForCollection ( $ collection ) )
274
266
->willReturnSelf ();
275
267
276
- $ this ->rule ->expects ($ this ->once ())->method ('loadPost ' )->willReturnSelf ();
277
- $ this ->rule ->expects ($ this ->once ())->method ('getConditions ' )->willReturn ($ conditions );
278
-
279
268
if ($ productsPerPage ) {
280
269
$ this ->productsList ->setData ('products_per_page ' , $ productsPerPage );
281
270
} else {
@@ -333,7 +322,46 @@ public function testShowPager()
333
322
334
323
public function testGetIdentities ()
335
324
{
336
- $ this ->assertEquals ([\Magento \Catalog \Model \Product::CACHE_TAG ], $ this ->productsList ->getIdentities ());
325
+ $ collection = $ this ->getMockBuilder ('\Magento\Catalog\Model\ResourceModel\Product\Collection ' )
326
+ ->setMethods ([
327
+ 'addAttributeToSelect ' ,
328
+ 'getIterator ' ,
329
+ ])->disableOriginalConstructor ()
330
+ ->getMock ();
331
+
332
+ $ this ->collectionFactory ->expects ($ this ->once ())->method ('create ' )->willReturn ($ collection );
333
+ $ this ->productsList ->setData ('conditions_encoded ' , 'some_serialized_conditions ' );
334
+
335
+ $ this ->builder ->expects ($ this ->once ())->method ('attachConditionToCollection ' )
336
+ ->with ($ collection , $ this ->getConditionsForCollection ($ collection ))
337
+ ->willReturnSelf ();
338
+ $ product = $ this ->getMock ('Magento\Catalog\Api\ProductInterface ' , ['getId ' ]);
339
+ $ product ->expects ($ this ->once ())->method ('getId ' )->willReturn ('product_id ' );
340
+ $ collection ->expects ($ this ->once ())->method ('getIterator ' )->willReturn (new \ArrayIterator ([$ product ]));
341
+
342
+ $ this ->assertEquals (
343
+ [\Magento \Catalog \Model \Product::CACHE_TAG . '_ ' . 'product_id ' ],
344
+ $ this ->productsList ->getIdentities ()
345
+ );
346
+ }
347
+
348
+ /**
349
+ * @param $collection
350
+ * @return \PHPUnit_Framework_MockObject_MockObject
351
+ */
352
+ private function getConditionsForCollection ($ collection )
353
+ {
354
+ $ conditions = $ this ->getMockBuilder ('\Magento\Rule\Model\Condition\Combine ' )
355
+ ->setMethods (['collectValidatedAttributes ' ])
356
+ ->disableOriginalConstructor ()
357
+ ->getMock ();
358
+ $ conditions ->expects ($ this ->once ())->method ('collectValidatedAttributes ' )
359
+ ->with ($ collection )
360
+ ->willReturnSelf ();
361
+
362
+ $ this ->rule ->expects ($ this ->once ())->method ('loadPost ' )->willReturnSelf ();
363
+ $ this ->rule ->expects ($ this ->once ())->method ('getConditions ' )->willReturn ($ conditions );
364
+ return $ conditions ;
337
365
}
338
366
339
367
public function testGetTitle ()
0 commit comments