38
38
use Magento \Framework \Stdlib \DateTime \TimezoneInterface ;
39
39
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
40
40
use Magento \Framework \Validator \UniversalFactory ;
41
+ use Magento \Store \Model \Store ;
41
42
use Magento \Store \Model \StoreManagerInterface ;
42
43
use PHPUnit \Framework \MockObject \MockObject ;
43
44
use PHPUnit \Framework \TestCase ;
@@ -93,6 +94,11 @@ class CollectionTest extends TestCase
93
94
*/
94
95
private $ storeManager ;
95
96
97
+ /**
98
+ * @var ProductLimitation|MockObject
99
+ */
100
+ private $ productLimitationMock ;
101
+
96
102
/**
97
103
* @var EntityFactory|MockObject
98
104
*/
@@ -192,7 +198,7 @@ protected function setUp(): void
192
198
$ this ->entityMock ->expects ($ this ->any ())->method ('getTable ' )->willReturnArgument (0 );
193
199
$ this ->connectionMock ->expects ($ this ->atLeastOnce ())->method ('select ' )->willReturn ($ this ->selectMock );
194
200
195
- $ productLimitationMock = $ this ->createMock (
201
+ $ this -> productLimitationMock = $ this ->createMock (
196
202
ProductLimitation::class
197
203
);
198
204
$ productLimitationFactoryMock = $ this ->getMockBuilder (
@@ -201,7 +207,7 @@ protected function setUp(): void
201
207
->setMethods (['create ' ])->getMock ();
202
208
203
209
$ productLimitationFactoryMock ->method ('create ' )
204
- ->willReturn ($ productLimitationMock );
210
+ ->willReturn ($ this -> productLimitationMock );
205
211
$ this ->collection = $ this ->objectManager ->getObject (
206
212
Collection::class,
207
213
[
@@ -432,4 +438,44 @@ public function testGetNewEmptyItem()
432
438
$ secondItem = $ this ->collection ->getNewEmptyItem ();
433
439
$ this ->assertEquals ($ firstItem , $ secondItem );
434
440
}
441
+
442
+ /**
443
+ * Test to add website filter in admin area
444
+ */
445
+ public function testAddWebsiteFilterOnAdminStore (): void
446
+ {
447
+ $ websiteIds = [2 ];
448
+ $ websiteTable = 'catalog_product_website ' ;
449
+ $ joinCondition = 'join condition ' ;
450
+ $ this ->productLimitationMock ->expects ($ this ->atLeastOnce ())
451
+ ->method ('offsetSet ' )
452
+ ->with ('website_ids ' , $ websiteIds );
453
+ $ this ->productLimitationMock ->method ('offsetExists ' )
454
+ ->with ('website_ids ' )
455
+ ->willReturn (true );
456
+ $ this ->productLimitationMock ->method ('offsetGet ' )
457
+ ->with ('website_ids ' )
458
+ ->willReturn ($ websiteIds );
459
+ $ this ->connectionMock ->expects ($ this ->once ())
460
+ ->method ('quoteInto ' )
461
+ ->with ('product_website.website_id IN(?) ' , $ websiteIds , 'int ' )
462
+ ->willReturn ($ joinCondition );
463
+ $ this ->selectMock ->method ('getPart ' )->with (Select::FROM )->willReturn ([]);
464
+ /** @var AbstractEntity|MockObject $eavEntity */
465
+ $ eavEntity = $ this ->createMock (AbstractEntity::class);
466
+ $ eavEntity ->method ('getTable ' )
467
+ ->with ('catalog_product_website ' )
468
+ ->willReturn ($ websiteTable );
469
+ $ this ->selectMock ->expects ($ this ->once ())
470
+ ->method ('join ' )
471
+ ->with (
472
+ ['product_website ' => $ websiteTable ],
473
+ 'product_website.product_id = e.entity_id AND ' . $ joinCondition ,
474
+ []
475
+ );
476
+
477
+ $ this ->collection ->setEntity ($ eavEntity );
478
+ $ this ->collection ->setStoreId (Store::DEFAULT_STORE_ID );
479
+ $ this ->collection ->addWebsiteFilter ($ websiteIds );
480
+ }
435
481
}
0 commit comments