@@ -141,16 +141,19 @@ public function testGetHrefIfRewriteIsNotFound()
141141 *
142142 * @dataProvider dataProviderForTestGetHrefWithoutUrlStoreSuffix
143143 * @param string $path
144+ * @param int|null $storeId
144145 * @param bool $includeStoreCode
145146 * @param string $expected
146147 * @throws \ReflectionException
147148 */
148149 public function testStoreCodeShouldBeIncludedInURLOnlyIfItIsConfiguredSo (
149150 string $ path ,
151+ ?int $ storeId ,
150152 bool $ includeStoreCode ,
151153 string $ expected
152154 ) {
153155 $ this ->block ->setData ('id_path ' , 'entity_type/entity_id ' );
156+ $ this ->block ->setData ('store_id ' , $ storeId );
154157 $ objectManager = new ObjectManager ($ this );
155158
156159 $ rewrite = $ this ->createPartialMock (UrlRewrite::class, ['getRequestPath ' ]);
@@ -192,25 +195,35 @@ public function testStoreCodeShouldBeIncludedInURLOnlyIfItIsConfiguredSo(
192195 $ url ->expects ($ this ->any ())
193196 ->method ('getUrl ' )
194197 ->willReturnCallback (
195- function ($ route , $ params ) use ($ store ) {
196- return rtrim ($ store ->getBaseUrl (), '/ ' ) .'/ ' . ltrim ($ params ['_direct ' ], '/ ' );
198+ function ($ route , $ params ) use ($ storeId ) {
199+ $ baseUrl = rtrim ($ this ->storeManager ->getStore ($ storeId )->getBaseUrl (), '/ ' );
200+ return $ baseUrl .'/ ' . ltrim ($ params ['_direct ' ], '/ ' );
197201 }
198202 );
199203
200204 $ store ->addData (['store_id ' => 1 , 'code ' => 'french ' ]);
201205
206+ $ store2 = clone $ store ;
207+ $ store2 ->addData (['store_id ' => 2 , 'code ' => 'german ' ]);
208+
202209 $ this ->storeManager
203210 ->expects ($ this ->any ())
204211 ->method ('getStore ' )
205- ->willReturn ($ store );
212+ ->willReturnMap (
213+ [
214+ [null , $ store ],
215+ [1 , $ store ],
216+ [2 , $ store2 ],
217+ ]
218+ );
206219
207220 $ this ->urlFinder ->expects ($ this ->once ())
208221 ->method ('findOneByData ' )
209222 ->with (
210223 [
211224 UrlRewrite::ENTITY_ID => 'entity_id ' ,
212225 UrlRewrite::ENTITY_TYPE => 'entity_type ' ,
213- UrlRewrite::STORE_ID => $ store ->getStoreId (),
226+ UrlRewrite::STORE_ID => $ this -> storeManager -> getStore ( $ storeId ) ->getStoreId (),
214227 ]
215228 )
216229 ->will ($ this ->returnValue ($ rewrite ));
@@ -219,7 +232,7 @@ function ($route, $params) use ($store) {
219232 ->method ('getRequestPath ' )
220233 ->will ($ this ->returnValue ($ path ));
221234
222- $ this ->assertContains ($ expected , $ this ->block ->getHref ());
235+ $ this ->assertEquals ($ expected , $ this ->block ->getHref ());
223236 }
224237
225238 /**
@@ -255,8 +268,13 @@ public function testGetLabelWithoutCustomText()
255268 public function dataProviderForTestGetHrefWithoutUrlStoreSuffix ()
256269 {
257270 return [
258- ['/accessories.html ' , true , 'french/accessories.html ' ],
259- ['/accessories.html ' , false , '/accessories.html ' ],
271+ ['/accessories.html ' , null , true , 'french/accessories.html ' ],
272+ ['/accessories.html ' , null , false , '/accessories.html ' ],
273+ ['/accessories.html ' , 1 , true , 'french/accessories.html ' ],
274+ ['/accessories.html ' , 1 , false , '/accessories.html ' ],
275+ ['/accessories.html ' , 2 , true , 'german/accessories.html ' ],
276+ ['/accessories.html ' , 2 , false , '/accessories.html?___store=german ' ],
277+ ['/accessories.html?___store=german ' , 2 , false , '/accessories.html?___store=german ' ],
260278 ];
261279 }
262280
0 commit comments