Skip to content

Commit f51d8f0

Browse files
Merge remote-tracking branch '40065/patch-27' into sept-comprs
2 parents 588eac3 + 2443bbc commit f51d8f0

File tree

7 files changed

+76
-120
lines changed

7 files changed

+76
-120
lines changed

app/code/Magento/Catalog/Test/Unit/Block/Widget/LinkTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,17 @@ public function testStoreCodeShouldBeIncludedInURLOnlyIfItIsConfiguredSo(
195195
[
196196
[Store::XML_PATH_USE_REWRITES, ReinitableConfigInterface::SCOPE_TYPE_DEFAULT, null, true],
197197
[Store::XML_PATH_UNSECURE_BASE_LINK_URL, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null, ''],
198+
]
199+
);
200+
$config->expects($this->any())
201+
->method('isSetFlag')
202+
->willReturnMap(
203+
[
198204
[
199205
Store::XML_PATH_STORE_IN_URL,
200206
ReinitableConfigInterface::SCOPE_TYPE_DEFAULT,
201-
null, $includeStoreCode
207+
null,
208+
$includeStoreCode
202209
]
203210
]
204211
);

app/code/Magento/Store/App/Request/StorePathInfoValidator.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,16 @@ public function __construct(
7777
*/
7878
public function getValidStoreCode(Http $request, string $pathInfo = '') : ?string
7979
{
80-
$useStoreCodeInUrl = (bool) $this->config->getValue(Store::XML_PATH_STORE_IN_URL);
81-
if (!$useStoreCodeInUrl) {
80+
if (!$this->config->isSetFlag(Store::XML_PATH_STORE_IN_URL)) {
8281
return null;
8382
}
8483

85-
if (empty($pathInfo)) {
84+
if ($pathInfo === '') {
8685
$pathInfo = $this->pathInfo->getPathInfo($request->getRequestUri(), $request->getBaseUrl());
8786
}
8887
$storeCode = $this->getStoreCode($pathInfo);
8988

90-
if (empty($storeCode) || $storeCode === Store::ADMIN_CODE || !$this->storeCodeValidator->isValid($storeCode)) {
89+
if ($storeCode === '' || $storeCode === Store::ADMIN_CODE || !$this->storeCodeValidator->isValid($storeCode)) {
9190
return null;
9291
}
9392

@@ -98,14 +97,9 @@ public function getValidStoreCode(Http $request, string $pathInfo = '') : ?strin
9897
try {
9998
$this->storeRepository->getActiveStoreByCode($storeCode);
10099

101-
$this->validatedStoreCodes[$storeCode] = $storeCode;
102-
return $storeCode;
103-
} catch (NoSuchEntityException $e) {
104-
$this->validatedStoreCodes[$storeCode] = null;
105-
return null;
106-
} catch (StoreIsInactiveException $e) {
107-
$this->validatedStoreCodes[$storeCode] = null;
108-
return null;
100+
return $this->validatedStoreCodes[$storeCode] = $storeCode;
101+
} catch (NoSuchEntityException|StoreIsInactiveException) {
102+
return $this->validatedStoreCodes[$storeCode] = null;
109103
}
110104
}
111105

app/code/Magento/Store/Model/Store.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -764,8 +764,8 @@ protected function _updatePathUseStoreView($url)
764764
public function isUseStoreInUrl()
765765
{
766766
return !($this->hasDisableStoreInUrl() && $this->getDisableStoreInUrl())
767-
&& !$this->getConfig(StoreManager::XML_PATH_SINGLE_STORE_MODE_ENABLED)
768-
&& $this->getConfig(self::XML_PATH_STORE_IN_URL);
767+
&& !$this->_config->isSetFlag(StoreManager::XML_PATH_SINGLE_STORE_MODE_ENABLED)
768+
&& $this->_config->isSetFlag(self::XML_PATH_STORE_IN_URL);
769769
}
770770

771771
/**

app/code/Magento/Store/Test/Unit/App/Request/StorePathInfoValidatorTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function testGetValidStoreCodeWithoutStoreInUrl(): void
8080
->willReturn(true);
8181

8282
$this->configMock->expects($this->once())
83-
->method('getValue')
83+
->method('isSetFlag')
8484
->with(Store::XML_PATH_STORE_IN_URL)
8585
->willReturn(false);
8686
$this->storeRepositoryMock->expects($this->never())
@@ -95,7 +95,7 @@ public function testGetValidStoreCodeWithoutPathInfo(): void
9595
$storeCode = 'store1';
9696

9797
$this->configMock->expects($this->once())
98-
->method('getValue')
98+
->method('isSetFlag')
9999
->with(Store::XML_PATH_STORE_IN_URL)
100100
->willReturn(true);
101101
$this->pathInfoMock->expects($this->once())
@@ -118,7 +118,7 @@ public function testGetValidStoreCodeWithoutPathInfo(): void
118118
public function testGetValidStoreCodeWithEmptyPathInfo(): void
119119
{
120120
$this->configMock->expects($this->once())
121-
->method('getValue')
121+
->method('isSetFlag')
122122
->with(Store::XML_PATH_STORE_IN_URL)
123123
->willReturn(true);
124124
$this->pathInfoMock->expects($this->once())
@@ -139,7 +139,7 @@ public function testGetValidStoreCodeWithEmptyPathInfo(): void
139139
*/
140140
public function testGetValidStoreCodeThrowsException(\Throwable $exception): void
141141
{
142-
$this->configMock->method('getValue')
142+
$this->configMock->method('isSetFlag')
143143
->with(Store::XML_PATH_STORE_IN_URL)
144144
->willReturn(true);
145145
$this->storeCodeValidatorMock->method('isValid')
@@ -169,7 +169,7 @@ public static function getValidStoreCodeExceptionDataProvider(): array
169169
*/
170170
public function testGetValidStoreCode(string $pathInfo, bool $isStoreCodeValid, ?string $expectedResult): void
171171
{
172-
$this->configMock->method('getValue')
172+
$this->configMock->method('isSetFlag')
173173
->with(Store::XML_PATH_STORE_IN_URL)
174174
->willReturn(true);
175175
$this->pathInfoMock->method('getPathInfo')
@@ -195,7 +195,7 @@ public function testGetValidStoreCodeResultIsCached(
195195
bool $isStoreCodeValid,
196196
?string $expectedResult
197197
): void {
198-
$this->configMock->method('getValue')
198+
$this->configMock->method('isSetFlag')
199199
->with(Store::XML_PATH_STORE_IN_URL)
200200
->willReturn(true);
201201
$this->pathInfoMock->method('getPathInfo')

app/code/Magento/Store/Test/Unit/Url/Plugin/RouteParamsResolverTest.php

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -54,10 +54,7 @@ protected function setUp(): void
5454
$this->storeMock->expects($this->any())->method('getCode')->willReturn('custom_store');
5555

5656
$this->storeManagerMock = $this->getMockForAbstractClass(StoreManagerInterface::class);
57-
$this->storeManagerMock
58-
->expects($this->once())
59-
->method('getStore')
60-
->willReturn($this->storeMock);
57+
$this->storeManagerMock->method('getStore')->willReturn($this->storeMock);
6158

6259
$this->queryParamsResolverMock = $this->getMockForAbstractClass(QueryParamsResolverInterface::class);
6360
$this->model = new RouteParamsResolver(
@@ -74,12 +71,8 @@ public function testBeforeSetRouteParamsScopeInParams()
7471

7572
$this->scopeConfigMock
7673
->expects($this->once())
77-
->method('getValue')
78-
->with(
79-
Store::XML_PATH_STORE_IN_URL,
80-
ScopeInterface::SCOPE_STORE,
81-
$storeCode
82-
)
74+
->method('isSetFlag')
75+
->with(Store::XML_PATH_STORE_IN_URL)
8376
->willReturn(false);
8477
$this->storeManagerMock->expects($this->any())->method('hasSingleStore')->willReturn(false);
8578

@@ -106,30 +99,23 @@ public function testBeforeSetRouteParamsScopeUseStoreInUrl()
10699

107100
$this->scopeConfigMock
108101
->expects($this->once())
109-
->method('getValue')
110-
->with(
111-
Store::XML_PATH_STORE_IN_URL,
112-
ScopeInterface::SCOPE_STORE,
113-
$storeCode
114-
)
102+
->method('isSetFlag')
103+
->with(Store::XML_PATH_STORE_IN_URL)
115104
->willReturn(true);
116105

117-
$this->storeManagerMock->expects($this->any())->method('hasSingleStore')->willReturn(false);
106+
$this->storeManagerMock->expects($this->never())->method('hasSingleStore');
118107

119108
/** @var MockObject $routeParamsResolverMock */
120109
$routeParamsResolverMock = $this->getMockBuilder(\Magento\Framework\Url\RouteParamsResolver::class)
121110
->addMethods(['setScope', 'getScope'])
122111
->disableOriginalConstructor()
123112
->getMock();
124113
$routeParamsResolverMock->expects($this->once())->method('setScope')->with($storeCode);
125-
$routeParamsResolverMock->expects($this->once())->method('getScope')->willReturn($storeCode);
114+
$routeParamsResolverMock->expects($this->never())->method('getScope');
126115

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

129-
$this->model->beforeSetRouteParams(
130-
$routeParamsResolverMock,
131-
$data
132-
);
118+
$this->model->beforeSetRouteParams($routeParamsResolverMock, $data);
133119
}
134120

135121
public function testBeforeSetRouteParamsSingleStore()
@@ -139,22 +125,18 @@ public function testBeforeSetRouteParamsSingleStore()
139125

140126
$this->scopeConfigMock
141127
->expects($this->once())
142-
->method('getValue')
143-
->with(
144-
Store::XML_PATH_STORE_IN_URL,
145-
ScopeInterface::SCOPE_STORE,
146-
$storeCode
147-
)
128+
->method('isSetFlag')
129+
->with(Store::XML_PATH_STORE_IN_URL)
148130
->willReturn(false);
149-
$this->storeManagerMock->expects($this->any())->method('hasSingleStore')->willReturn(true);
131+
$this->storeManagerMock->expects($this->once())->method('hasSingleStore')->willReturn(true);
150132

151133
/** @var MockObject $routeParamsResolverMock */
152134
$routeParamsResolverMock = $this->getMockBuilder(\Magento\Framework\Url\RouteParamsResolver::class)
153135
->addMethods(['setScope', 'getScope'])
154136
->disableOriginalConstructor()
155137
->getMock();
156138
$routeParamsResolverMock->expects($this->once())->method('setScope')->with($storeCode);
157-
$routeParamsResolverMock->expects($this->once())->method('getScope')->willReturn($storeCode);
139+
$routeParamsResolverMock->expects($this->never())->method('getScope');
158140

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

@@ -171,23 +153,19 @@ public function testBeforeSetRouteParamsNoScopeInParams()
171153

172154
$this->scopeConfigMock
173155
->expects($this->once())
174-
->method('getValue')
175-
->with(
176-
Store::XML_PATH_STORE_IN_URL,
177-
ScopeInterface::SCOPE_STORE,
178-
$storeCode
179-
)
156+
->method('isSetFlag')
157+
->with(Store::XML_PATH_STORE_IN_URL)
180158
->willReturn(true);
181159

182-
$this->storeManagerMock->expects($this->any())->method('hasSingleStore')->willReturn(false);
160+
$this->storeManagerMock->expects($this->never())->method('hasSingleStore');
183161

184162
/** @var MockObject $routeParamsResolverMock */
185163
$routeParamsResolverMock = $this->getMockBuilder(\Magento\Framework\Url\RouteParamsResolver::class)
186164
->addMethods(['setScope', 'getScope'])
187165
->disableOriginalConstructor()
188166
->getMock();
189167
$routeParamsResolverMock->expects($this->never())->method('setScope');
190-
$routeParamsResolverMock->expects($this->once())->method('getScope')->willReturn(false);
168+
$routeParamsResolverMock->expects($this->never())->method('getScope');
191169

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

app/code/Magento/Store/Url/Plugin/RouteParamsResolver.php

Lines changed: 24 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,37 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Store\Url\Plugin;
79

8-
use \Magento\Store\Model\Store;
9-
use \Magento\Store\Api\Data\StoreInterface;
10-
use \Magento\Store\Model\ScopeInterface as StoreScopeInterface;
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Framework\Url\RouteParamsResolver as UrlRouteParamsResolver;
12+
use Magento\Framework\Url\QueryParamsResolverInterface;
13+
use Magento\Store\Api\Data\StoreInterface;
14+
use Magento\Store\Model\ScopeInterface as StoreScopeInterface;
15+
use Magento\Store\Model\StoreManagerInterface;
16+
use Magento\Store\Model\Store;
1117

1218
/**
1319
* Plugin for \Magento\Framework\Url\RouteParamsResolver
1420
*/
1521
class RouteParamsResolver
1622
{
17-
/**
18-
* @var \Magento\Framework\App\Config\ScopeConfigInterface
19-
*/
20-
protected $scopeConfig;
21-
22-
/**
23-
* @var \Magento\Store\Model\StoreManagerInterface
24-
*/
25-
protected $storeManager;
26-
27-
/**
28-
* @var \Magento\Framework\Url\QueryParamsResolverInterface
29-
*/
30-
protected $queryParamsResolver;
31-
3223
/**
3324
* Initialize dependencies.
3425
*
35-
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
36-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
37-
* @param \Magento\Framework\Url\QueryParamsResolverInterface $queryParamsResolver
26+
* @param ScopeConfigInterface $scopeConfig
27+
* @param StoreManagerInterface $storeManager
28+
* @param QueryParamsResolverInterface $queryParamsResolver
3829
*/
3930
public function __construct(
40-
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
41-
\Magento\Store\Model\StoreManagerInterface $storeManager,
42-
\Magento\Framework\Url\QueryParamsResolverInterface $queryParamsResolver
31+
protected ScopeConfigInterface $scopeConfig,
32+
protected StoreManagerInterface $storeManager,
33+
protected QueryParamsResolverInterface $queryParamsResolver
4334
) {
44-
$this->scopeConfig = $scopeConfig;
45-
$this->storeManager = $storeManager;
46-
$this->queryParamsResolver = $queryParamsResolver;
4735
}
4836

4937
/**
@@ -56,29 +44,19 @@ public function __construct(
5644
*
5745
* @return array
5846
*/
59-
public function beforeSetRouteParams(
60-
\Magento\Framework\Url\RouteParamsResolver $subject,
61-
array $data,
62-
$unsetOldParams = true
63-
) {
47+
public function beforeSetRouteParams(UrlRouteParamsResolver $subject, array $data, $unsetOldParams = true)
48+
{
6449
if (isset($data['_scope'])) {
6550
$subject->setScope($data['_scope']);
6651
unset($data['_scope']);
6752
}
6853
if (isset($data['_scope_to_url']) && (bool)$data['_scope_to_url'] === true) {
69-
/** @var StoreInterface $currentScope */
70-
$currentScope = $subject->getScope();
71-
$storeCode = $currentScope && $currentScope instanceof StoreInterface ?
72-
$currentScope->getCode() :
73-
$this->storeManager->getStore()->getCode();
74-
75-
$useStoreInUrl = $this->scopeConfig->getValue(
76-
Store::XML_PATH_STORE_IN_URL,
77-
StoreScopeInterface::SCOPE_STORE,
78-
$storeCode
79-
);
80-
54+
$useStoreInUrl = $this->scopeConfig->isSetFlag(Store::XML_PATH_STORE_IN_URL);
8155
if (!$useStoreInUrl && !$this->storeManager->hasSingleStore()) {
56+
$currentScope = $subject->getScope();
57+
$storeCode = $currentScope instanceof StoreInterface
58+
? $currentScope->getCode()
59+
: $this->storeManager->getStore()->getCode();
8260
$this->queryParamsResolver->setQueryParam('___store', $storeCode);
8361
}
8462
}

0 commit comments

Comments
 (0)