1616use Magento \Framework \EntityManager \EntityMetadataInterface ;
1717use Magento \Framework \EntityManager \MetadataPool ;
1818use Magento \Framework \Session \SessionManagerInterface ;
19+ use Magento \Store \Api \Data \StoreInterface ;
20+ use Magento \Store \Model \StoreManagerInterface ;
1921use PHPUnit \Framework \MockObject \MockObject ;
2022use PHPUnit \Framework \TestCase ;
2123
@@ -37,10 +39,15 @@ class SpecialPriceBulkResolverTest extends TestCase
3739 private SpecialPriceBulkResolver $ specialPriceBulkResolver ;
3840
3941 /**
40- * @var SessionManagerInterface
42+ * @var SessionManagerInterface|MockObject
4143 */
4244 private SessionManagerInterface $ customerSession ;
4345
46+ /**
47+ * @var StoreManagerInterface|MockObject
48+ */
49+ private StoreManagerInterface $ storeManager ;
50+
4451 /**
4552 * @return void
4653 */
@@ -52,11 +59,12 @@ protected function setUp(): void
5259 ->disableOriginalConstructor ()
5360 ->addMethods (['getCustomerGroupId ' ])
5461 ->getMockForAbstractClass ();
55-
62+ $ this -> storeManager = $ this -> createMock (StoreManagerInterface::class);
5663 $ this ->specialPriceBulkResolver = new SpecialPriceBulkResolver (
5764 $ this ->resource ,
5865 $ this ->metadataPool ,
59- $ this ->customerSession
66+ $ this ->customerSession ,
67+ $ this ->storeManager
6068 );
6169 }
6270
@@ -75,9 +83,19 @@ public function testGenerateSpecialPriceMapNoCollection(): void
7583 */
7684 public function testGenerateSpecialPriceMapCollection (): void
7785 {
86+ $ storeId = 2 ;
87+ $ websiteId = 1 ;
88+ $ customerGroupId = 3 ;
7889 $ product = $ this ->createMock (Product::class);
79-
80- $ this ->customerSession ->expects ($ this ->once ())->method ('getCustomerGroupId ' )->willReturn (1 );
90+ $ store = $ this ->createMock (StoreInterface::class);
91+ $ store ->expects ($ this ->once ())->method ('getWebsiteId ' )->willReturn ($ websiteId );
92+ $ this ->storeManager ->expects ($ this ->once ())
93+ ->method ('getStore ' )
94+ ->with ($ storeId )
95+ ->willReturn ($ store );
96+ $ this ->customerSession ->expects ($ this ->once ())
97+ ->method ('getCustomerGroupId ' )
98+ ->willReturn ($ customerGroupId );
8199 $ collection = $ this ->getMockBuilder (AbstractCollection::class)
82100 ->disableOriginalConstructor ()
83101 ->onlyMethods (['getAllIds ' , 'getIterator ' ])
@@ -92,14 +110,13 @@ public function testGenerateSpecialPriceMapCollection(): void
92110 ->method ('getMetadata ' )
93111 ->with (ProductInterface::class)
94112 ->willReturn ($ metadata );
95-
96113 $ connection = $ this ->getMockBuilder (AdapterInterface::class)
97114 ->addMethods (['from ' , 'joinInner ' , 'where ' , 'columns ' , 'joinLeft ' ])
98115 ->getMockForAbstractClass ();
99116 $ connection ->expects ($ this ->once ())->method ('select ' )->willReturnSelf ();
100117 $ connection ->expects ($ this ->once ())
101118 ->method ('from ' )
102- ->with (['e ' => 'catalog_product_super_link ' ])
119+ ->with (['e ' => 'catalog_product_entity ' ])
103120 ->willReturnSelf ();
104121 $ connection ->expects ($ this ->exactly (3 ))
105122 ->method ('joinLeft ' )
@@ -130,12 +147,13 @@ public function testGenerateSpecialPriceMapCollection(): void
130147 $ this ->resource ->expects ($ this ->exactly (4 ))
131148 ->method ('getTableName ' )
132149 ->willReturnOnConsecutiveCalls (
133- 'catalog_product_super_link ' ,
134150 'catalog_product_entity ' ,
151+ 'catalog_product_super_link ' ,
135152 'catalog_product_website ' ,
136153 'catalog_product_index_price '
137154 );
138-
139- $ this ->specialPriceBulkResolver ->generateSpecialPriceMap (1 , $ collection );
155+ $ result = $ this ->specialPriceBulkResolver ->generateSpecialPriceMap ($ storeId , $ collection );
156+ $ expectedResult = [1 => true ];
157+ $ this ->assertEquals ($ expectedResult , $ result );
140158 }
141159}
0 commit comments