4
4
* See COPYING.txt for license details.
5
5
*/
6
6
7
- // @codingStandardsIgnoreFile
8
-
9
7
namespace Magento \Store \Model ;
10
8
9
+ use Magento \Catalog \Model \ProductRepository ;
11
10
use Magento \Framework \App \Bootstrap ;
12
11
use Magento \Framework \App \Filesystem \DirectoryList ;
13
12
use Magento \Framework \UrlInterface ;
13
+ use Magento \Store \Api \StoreRepositoryInterface ;
14
14
use Zend \Stdlib \Parameters ;
15
15
16
16
/**
@@ -200,7 +200,7 @@ public function testGetBaseUrlInPub()
200
200
*/
201
201
public function testGetBaseUrlForCustomEntryPoint ($ type , $ useCustomEntryPoint , $ useStoreCode , $ expected )
202
202
{
203
- /* config operations require store to be loaded */
203
+ /* config operations require store to be loaded */
204
204
$ this ->model ->load ('default ' );
205
205
\Magento \TestFramework \Helper \Bootstrap::getObjectManager ()
206
206
->get (\Magento \Framework \App \Config \MutableScopeConfigInterface::class)
@@ -269,12 +269,89 @@ public function testIsCanDelete()
269
269
$ this ->assertFalse ($ this ->model ->isCanDelete ());
270
270
}
271
271
272
+ /**
273
+ * @magentoDataFixture Magento/Store/_files/core_second_third_fixturestore.php
274
+ * @magentoDataFixture Magento/Catalog/_files/product_simple.php
275
+ * @magentoDbIsolation disabled
276
+ */
272
277
public function testGetCurrentUrl ()
273
278
{
279
+ $ objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
280
+ $ objectManager ->get (\Magento \Framework \App \Config \MutableScopeConfigInterface::class)
281
+ ->setValue ('web/url/use_store ' , true , ScopeInterface::SCOPE_STORE , 'secondstore ' );
282
+
274
283
$ this ->model ->load ('admin ' );
275
- $ this ->model ->expects ($ this ->any ())->method ('getUrl ' )->will ($ this ->returnValue ('http://localhost/index.php ' ));
284
+ $ this ->model
285
+ ->expects ($ this ->any ())->method ('getUrl ' )
286
+ ->will ($ this ->returnValue ('http://localhost/index.php ' ));
276
287
$ this ->assertStringEndsWith ('default ' , $ this ->model ->getCurrentUrl ());
277
288
$ this ->assertStringEndsNotWith ('default ' , $ this ->model ->getCurrentUrl (false ));
289
+
290
+ /** @var \Magento\Store\Model\Store $secondStore */
291
+ $ secondStore = $ objectManager ->get (StoreRepositoryInterface::class)->get ('secondstore ' );
292
+
293
+ /** @var \Magento\Catalog\Model\ProductRepository $productRepository */
294
+ $ productRepository = $ objectManager ->create (ProductRepository::class);
295
+ $ product = $ productRepository ->get ('simple ' );
296
+ $ product ->setStoreId ($ secondStore ->getId ());
297
+ $ url = $ product ->getUrlInStore ();
298
+
299
+ $ this ->assertEquals (
300
+ $ secondStore ->getBaseUrl ().'catalog/product/view/id/1/s/simple-product/ ' ,
301
+ $ url
302
+ );
303
+ $ this ->assertEquals (
304
+ $ secondStore ->getBaseUrl ().'?___from_store=default ' ,
305
+ $ secondStore ->getCurrentUrl ()
306
+ );
307
+ $ this ->assertEquals (
308
+ $ secondStore ->getBaseUrl (),
309
+ $ secondStore ->getCurrentUrl (false )
310
+ );
311
+ }
312
+
313
+ /**
314
+ * @magentoDataFixture Magento/Store/_files/second_store.php
315
+ * @magentoDataFixture Magento/Catalog/_files/category_product.php
316
+ * @magentoDbIsolation disabled
317
+ */
318
+ public function testGetCurrentUrlWithUseStoreInUrlFalse ()
319
+ {
320
+ $ objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
321
+ $ objectManager ->get (\Magento \Framework \App \Config \ReinitableConfigInterface::class)
322
+ ->setValue ('web/url/use_store ' , false , ScopeInterface::SCOPE_STORE , 'default ' );
323
+
324
+ /** @var \Magento\Store\Model\Store $secondStore */
325
+ $ secondStore = $ objectManager ->get (StoreRepositoryInterface::class)->get ('fixture_second_store ' );
326
+
327
+ /** @var \Magento\Catalog\Model\ProductRepository $productRepository */
328
+ $ productRepository = $ objectManager ->create (ProductRepository::class);
329
+ $ product = $ productRepository ->get ('simple333 ' );
330
+
331
+ $ product ->setStoreId ($ secondStore ->getId ());
332
+ $ url = $ product ->getUrlInStore ();
333
+
334
+ /** @var \Magento\Catalog\Model\CategoryRepository $categoryRepository */
335
+ $ categoryRepository = $ objectManager ->get (\Magento \Catalog \Model \CategoryRepository::class);
336
+ $ category = $ categoryRepository ->get (333 , $ secondStore ->getStoreId ());
337
+
338
+ $ this ->assertEquals (
339
+ $ secondStore ->getBaseUrl ().'catalog/category/view/s/category-1/id/333/ ' ,
340
+ $ category ->getUrl ()
341
+ );
342
+ $ this ->assertEquals (
343
+ $ secondStore ->getBaseUrl ().
344
+ 'catalog/product/view/id/333/s/simple-product-three/?___store=fixture_second_store ' ,
345
+ $ url
346
+ );
347
+ $ this ->assertEquals (
348
+ $ secondStore ->getBaseUrl ().'?___store=fixture_second_store&___from_store=default ' ,
349
+ $ secondStore ->getCurrentUrl ()
350
+ );
351
+ $ this ->assertEquals (
352
+ $ secondStore ->getBaseUrl ().'?___store=fixture_second_store ' ,
353
+ $ secondStore ->getCurrentUrl (false )
354
+ );
278
355
}
279
356
280
357
/**
@@ -292,7 +369,11 @@ public function testCRUD()
292
369
'sort_order ' => 0 ,
293
370
'is_active ' => 1 ,
294
371
]);
295
- $ crud = new \Magento \TestFramework \Entity ($ this ->model , ['name ' => 'new name ' ], \Magento \Store \Model \Store::class);
372
+ $ crud = new \Magento \TestFramework \Entity (
373
+ $ this ->model ,
374
+ ['name ' => 'new name ' ],
375
+ \Magento \Store \Model \Store::class
376
+ );
296
377
$ crud ->testCrud ();
297
378
}
298
379
0 commit comments