|
6 | 6 |
|
7 | 7 | namespace Magento\Store\Model;
|
8 | 8 |
|
| 9 | +use Magento\Catalog\Model\ProductRepository; |
9 | 10 | use Magento\Framework\App\Bootstrap;
|
| 11 | +use Magento\Framework\App\Config\ScopeConfigInterface; |
10 | 12 | use Magento\Framework\App\Filesystem\DirectoryList;
|
11 | 13 | use Magento\Framework\UrlInterface;
|
| 14 | +use Magento\Store\Api\StoreRepositoryInterface; |
12 | 15 | use Zend\Stdlib\Parameters;
|
13 | 16 |
|
14 | 17 | /**
|
@@ -267,12 +270,89 @@ public function testIsCanDelete()
|
267 | 270 | $this->assertFalse($this->model->isCanDelete());
|
268 | 271 | }
|
269 | 272 |
|
| 273 | + /** |
| 274 | + * @magentoDataFixture Magento/Store/_files/core_second_third_fixturestore.php |
| 275 | + * @magentoDataFixture Magento/Catalog/_files/product_simple.php |
| 276 | + * @magentoDbIsolation disabled |
| 277 | + */ |
270 | 278 | public function testGetCurrentUrl()
|
271 | 279 | {
|
| 280 | + $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); |
| 281 | + $objectManager->get(\Magento\Framework\App\Config\MutableScopeConfigInterface::class) |
| 282 | + ->setValue('web/url/use_store', true, ScopeInterface::SCOPE_STORE, 'secondstore'); |
| 283 | + |
272 | 284 | $this->model->load('admin');
|
273 |
| - $this->model->expects($this->any())->method('getUrl')->will($this->returnValue('http://localhost/index.php')); |
| 285 | + $this->model |
| 286 | + ->expects($this->any())->method('getUrl') |
| 287 | + ->will($this->returnValue('http://localhost/index.php')); |
274 | 288 | $this->assertStringEndsWith('default', $this->model->getCurrentUrl());
|
275 | 289 | $this->assertStringEndsNotWith('default', $this->model->getCurrentUrl(false));
|
| 290 | + |
| 291 | + /** @var \Magento\Store\Model\Store $secondStore */ |
| 292 | + $secondStore = $objectManager->get(StoreRepositoryInterface::class)->get('secondstore'); |
| 293 | + |
| 294 | + /** @var \Magento\Catalog\Model\ProductRepository $productRepository */ |
| 295 | + $productRepository = $objectManager->create(ProductRepository::class); |
| 296 | + $product = $productRepository->get('simple'); |
| 297 | + $product->setStoreId($secondStore->getId()); |
| 298 | + $url = $product->getUrlInStore(); |
| 299 | + |
| 300 | + $this->assertEquals( |
| 301 | + $secondStore->getBaseUrl().'catalog/product/view/id/1/s/simple-product/', |
| 302 | + $url |
| 303 | + ); |
| 304 | + $this->assertEquals( |
| 305 | + $secondStore->getBaseUrl().'?___from_store=default', |
| 306 | + $secondStore->getCurrentUrl() |
| 307 | + ); |
| 308 | + $this->assertEquals( |
| 309 | + $secondStore->getBaseUrl(), |
| 310 | + $secondStore->getCurrentUrl(false) |
| 311 | + ); |
| 312 | + } |
| 313 | + |
| 314 | + /** |
| 315 | + * @magentoDataFixture Magento/Store/_files/second_store.php |
| 316 | + * @magentoDataFixture Magento/Catalog/_files/category_product.php |
| 317 | + * @magentoDbIsolation disabled |
| 318 | + */ |
| 319 | + public function testGetCurrentUrlWithUseStoreInUrlFalse() |
| 320 | + { |
| 321 | + $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); |
| 322 | + $objectManager->get(\Magento\Framework\App\Config\ReinitableConfigInterface::class) |
| 323 | + ->setValue('web/url/use_store', false, ScopeInterface::SCOPE_STORE, 'default'); |
| 324 | + |
| 325 | + /** @var \Magento\Store\Model\Store $secondStore */ |
| 326 | + $secondStore = $objectManager->get(StoreRepositoryInterface::class)->get('fixture_second_store'); |
| 327 | + |
| 328 | + /** @var \Magento\Catalog\Model\ProductRepository $productRepository */ |
| 329 | + $productRepository = $objectManager->create(ProductRepository::class); |
| 330 | + $product = $productRepository->get('simple333'); |
| 331 | + |
| 332 | + $product->setStoreId($secondStore->getId()); |
| 333 | + $url = $product->getUrlInStore(); |
| 334 | + |
| 335 | + /** @var \Magento\Catalog\Model\CategoryRepository $categoryRepository */ |
| 336 | + $categoryRepository = $objectManager->get(\Magento\Catalog\Model\CategoryRepository::class); |
| 337 | + $category = $categoryRepository->get(333, $secondStore->getStoreId()); |
| 338 | + |
| 339 | + $this->assertEquals( |
| 340 | + $secondStore->getBaseUrl().'catalog/category/view/s/category-1/id/333/', |
| 341 | + $category->getUrl() |
| 342 | + ); |
| 343 | + $this->assertEquals( |
| 344 | + $secondStore->getBaseUrl(). |
| 345 | + 'catalog/product/view/id/333/s/simple-product-three/?___store=fixture_second_store', |
| 346 | + $url |
| 347 | + ); |
| 348 | + $this->assertEquals( |
| 349 | + $secondStore->getBaseUrl().'?___store=fixture_second_store&___from_store=default', |
| 350 | + $secondStore->getCurrentUrl() |
| 351 | + ); |
| 352 | + $this->assertEquals( |
| 353 | + $secondStore->getBaseUrl().'?___store=fixture_second_store', |
| 354 | + $secondStore->getCurrentUrl(false) |
| 355 | + ); |
276 | 356 | }
|
277 | 357 |
|
278 | 358 | /**
|
|
0 commit comments