@@ -141,16 +141,19 @@ public function testGetHrefIfRewriteIsNotFound()
141
141
*
142
142
* @dataProvider dataProviderForTestGetHrefWithoutUrlStoreSuffix
143
143
* @param string $path
144
+ * @param int|null $storeId
144
145
* @param bool $includeStoreCode
145
146
* @param string $expected
146
147
* @throws \ReflectionException
147
148
*/
148
149
public function testStoreCodeShouldBeIncludedInURLOnlyIfItIsConfiguredSo (
149
150
string $ path ,
151
+ ?int $ storeId ,
150
152
bool $ includeStoreCode ,
151
153
string $ expected
152
154
) {
153
155
$ this ->block ->setData ('id_path ' , 'entity_type/entity_id ' );
156
+ $ this ->block ->setData ('store_id ' , $ storeId );
154
157
$ objectManager = new ObjectManager ($ this );
155
158
156
159
$ rewrite = $ this ->createPartialMock (UrlRewrite::class, ['getRequestPath ' ]);
@@ -192,25 +195,35 @@ public function testStoreCodeShouldBeIncludedInURLOnlyIfItIsConfiguredSo(
192
195
$ url ->expects ($ this ->any ())
193
196
->method ('getUrl ' )
194
197
->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 ' ], '/ ' );
197
201
}
198
202
);
199
203
200
204
$ store ->addData (['store_id ' => 1 , 'code ' => 'french ' ]);
201
205
206
+ $ store2 = clone $ store ;
207
+ $ store2 ->addData (['store_id ' => 2 , 'code ' => 'german ' ]);
208
+
202
209
$ this ->storeManager
203
210
->expects ($ this ->any ())
204
211
->method ('getStore ' )
205
- ->willReturn ($ store );
212
+ ->willReturnMap (
213
+ [
214
+ [null , $ store ],
215
+ [1 , $ store ],
216
+ [2 , $ store2 ],
217
+ ]
218
+ );
206
219
207
220
$ this ->urlFinder ->expects ($ this ->once ())
208
221
->method ('findOneByData ' )
209
222
->with (
210
223
[
211
224
UrlRewrite::ENTITY_ID => 'entity_id ' ,
212
225
UrlRewrite::ENTITY_TYPE => 'entity_type ' ,
213
- UrlRewrite::STORE_ID => $ store ->getStoreId (),
226
+ UrlRewrite::STORE_ID => $ this -> storeManager -> getStore ( $ storeId ) ->getStoreId (),
214
227
]
215
228
)
216
229
->will ($ this ->returnValue ($ rewrite ));
@@ -219,7 +232,7 @@ function ($route, $params) use ($store) {
219
232
->method ('getRequestPath ' )
220
233
->will ($ this ->returnValue ($ path ));
221
234
222
- $ this ->assertContains ($ expected , $ this ->block ->getHref ());
235
+ $ this ->assertEquals ($ expected , $ this ->block ->getHref ());
223
236
}
224
237
225
238
/**
@@ -255,8 +268,13 @@ public function testGetLabelWithoutCustomText()
255
268
public function dataProviderForTestGetHrefWithoutUrlStoreSuffix ()
256
269
{
257
270
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 ' ],
260
278
];
261
279
}
262
280
0 commit comments