Skip to content

[Backport] issue 18941 #19945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function testBeforeSetRouteParamsScopeInParams()
$routeParamsResolverMock->expects($this->once())->method('setScope')->with($storeCode);
$routeParamsResolverMock->expects($this->once())->method('getScope')->willReturn($storeCode);

$this->queryParamsResolverMock->expects($this->never())->method('setQueryParam');
$this->queryParamsResolverMock->expects($this->any())->method('setQueryParam');

$this->model->beforeSetRouteParams(
$routeParamsResolverMock,
Expand Down Expand Up @@ -113,7 +113,7 @@ public function testBeforeSetRouteParamsScopeUseStoreInUrl()
$routeParamsResolverMock->expects($this->once())->method('setScope')->with($storeCode);
$routeParamsResolverMock->expects($this->once())->method('getScope')->willReturn($storeCode);

$this->queryParamsResolverMock->expects($this->once())->method('setQueryParam')->with('___store', $storeCode);
$this->queryParamsResolverMock->expects($this->never())->method('setQueryParam')->with('___store', $storeCode);

$this->model->beforeSetRouteParams(
$routeParamsResolverMock,
Expand Down Expand Up @@ -178,7 +178,7 @@ public function testBeforeSetRouteParamsNoScopeInParams()
$routeParamsResolverMock->expects($this->never())->method('setScope');
$routeParamsResolverMock->expects($this->once())->method('getScope')->willReturn(false);

$this->queryParamsResolverMock->expects($this->once())->method('setQueryParam')->with('___store', $storeCode);
$this->queryParamsResolverMock->expects($this->never())->method('setQueryParam')->with('___store', $storeCode);

$this->model->beforeSetRouteParams(
$routeParamsResolverMock,
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Store/Url/Plugin/RouteParamsResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function beforeSetRouteParams(
$storeCode
);

if ($useStoreInUrl && !$this->storeManager->hasSingleStore()) {
if (!$useStoreInUrl && !$this->storeManager->hasSingleStore()) {
$this->queryParamsResolver->setQueryParam('___store', $storeCode);
}
}
Expand Down
91 changes: 86 additions & 5 deletions dev/tests/integration/testsuite/Magento/Store/Model/StoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile

namespace Magento\Store\Model;

use Magento\Catalog\Model\ProductRepository;
use Magento\Framework\App\Bootstrap;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\UrlInterface;
use Magento\Store\Api\StoreRepositoryInterface;
use Zend\Stdlib\Parameters;

/**
Expand Down Expand Up @@ -200,7 +200,7 @@ public function testGetBaseUrlInPub()
*/
public function testGetBaseUrlForCustomEntryPoint($type, $useCustomEntryPoint, $useStoreCode, $expected)
{
/* config operations require store to be loaded */
/* config operations require store to be loaded */
$this->model->load('default');
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()
->get(\Magento\Framework\App\Config\MutableScopeConfigInterface::class)
Expand Down Expand Up @@ -269,12 +269,89 @@ public function testIsCanDelete()
$this->assertFalse($this->model->isCanDelete());
}

/**
* @magentoDataFixture Magento/Store/_files/core_second_third_fixturestore.php
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
* @magentoDbIsolation disabled
*/
public function testGetCurrentUrl()
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$objectManager->get(\Magento\Framework\App\Config\MutableScopeConfigInterface::class)
->setValue('web/url/use_store', true, ScopeInterface::SCOPE_STORE, 'secondstore');

$this->model->load('admin');
$this->model->expects($this->any())->method('getUrl')->will($this->returnValue('http://localhost/index.php'));
$this->model
->expects($this->any())->method('getUrl')
->will($this->returnValue('http://localhost/index.php'));
$this->assertStringEndsWith('default', $this->model->getCurrentUrl());
$this->assertStringEndsNotWith('default', $this->model->getCurrentUrl(false));

/** @var \Magento\Store\Model\Store $secondStore */
$secondStore = $objectManager->get(StoreRepositoryInterface::class)->get('secondstore');

/** @var \Magento\Catalog\Model\ProductRepository $productRepository */
$productRepository = $objectManager->create(ProductRepository::class);
$product = $productRepository->get('simple');
$product->setStoreId($secondStore->getId());
$url = $product->getUrlInStore();

$this->assertEquals(
$secondStore->getBaseUrl().'catalog/product/view/id/1/s/simple-product/',
$url
);
$this->assertEquals(
$secondStore->getBaseUrl().'?___from_store=default',
$secondStore->getCurrentUrl()
);
$this->assertEquals(
$secondStore->getBaseUrl(),
$secondStore->getCurrentUrl(false)
);
}

/**
* @magentoDataFixture Magento/Store/_files/second_store.php
* @magentoDataFixture Magento/Catalog/_files/category_product.php
* @magentoDbIsolation disabled
*/
public function testGetCurrentUrlWithUseStoreInUrlFalse()
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$objectManager->get(\Magento\Framework\App\Config\ReinitableConfigInterface::class)
->setValue('web/url/use_store', false, ScopeInterface::SCOPE_STORE, 'default');

/** @var \Magento\Store\Model\Store $secondStore */
$secondStore = $objectManager->get(StoreRepositoryInterface::class)->get('fixture_second_store');

/** @var \Magento\Catalog\Model\ProductRepository $productRepository */
$productRepository = $objectManager->create(ProductRepository::class);
$product = $productRepository->get('simple333');

$product->setStoreId($secondStore->getId());
$url = $product->getUrlInStore();

/** @var \Magento\Catalog\Model\CategoryRepository $categoryRepository */
$categoryRepository = $objectManager->get(\Magento\Catalog\Model\CategoryRepository::class);
$category = $categoryRepository->get(333, $secondStore->getStoreId());

$this->assertEquals(
$secondStore->getBaseUrl().'catalog/category/view/s/category-1/id/333/',
$category->getUrl()
);
$this->assertEquals(
$secondStore->getBaseUrl().
'catalog/product/view/id/333/s/simple-product-three/?___store=fixture_second_store',
$url
);
$this->assertEquals(
$secondStore->getBaseUrl().'?___store=fixture_second_store&___from_store=default',
$secondStore->getCurrentUrl()
);
$this->assertEquals(
$secondStore->getBaseUrl().'?___store=fixture_second_store',
$secondStore->getCurrentUrl(false)
);
}

/**
Expand All @@ -292,7 +369,11 @@ public function testCRUD()
'sort_order' => 0,
'is_active' => 1,
]);
$crud = new \Magento\TestFramework\Entity($this->model, ['name' => 'new name'], \Magento\Store\Model\Store::class);
$crud = new \Magento\TestFramework\Entity(
$this->model,
['name' => 'new name'],
\Magento\Store\Model\Store::class
);
$crud->testCrud();
}

Expand Down