Skip to content

Commit 2874522

Browse files
authored
ENGCOM-5441: Check if setting is disabled on default scope #22891
2 parents 6e29a88 + bffbdc2 commit 2874522

File tree

2 files changed

+91
-19
lines changed

2 files changed

+91
-19
lines changed

app/code/Magento/Config/Model/Config/Reader/Source/Deployed/SettingChecker.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
*/
66
namespace Magento\Config\Model\Config\Reader\Source\Deployed;
77

8-
use Magento\Config\Model\Config\Reader;
9-
use Magento\Framework\App\Config\ScopeConfigInterface;
10-
use Magento\Framework\App\DeploymentConfig;
11-
use Magento\Config\Model\Placeholder\PlaceholderInterface;
128
use Magento\Config\Model\Placeholder\PlaceholderFactory;
9+
use Magento\Config\Model\Placeholder\PlaceholderInterface;
1310
use Magento\Framework\App\Config\ScopeCodeResolver;
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
12+
use Magento\Framework\App\DeploymentConfig;
1413

1514
/**
1615
* Class for checking settings that defined in config file
@@ -68,6 +67,12 @@ public function isReadOnly($path, $scope, $scopeCode = null)
6867
$config = $this->config->get($this->resolvePath($scope, $scopeCode) . "/" . $path);
6968
}
7069

70+
if (null === $config) {
71+
$config = $this->config->get(
72+
$this->resolvePath(ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null) . "/" . $path
73+
);
74+
}
75+
7176
return $config !== null;
7277
}
7378

@@ -78,7 +83,6 @@ public function isReadOnly($path, $scope, $scopeCode = null)
7883
*
7984
* @param string $path
8085
* @param string $scope
81-
* @param string $scopeCode
8286
* @param string|null $scopeCode
8387
* @return string|null
8488
* @since 100.1.2
@@ -97,9 +101,11 @@ public function getPlaceholderValue($path, $scope, $scopeCode = null)
97101
*/
98102
public function getEnvValue($placeholder)
99103
{
104+
// phpcs:disable Magento2.Security.Superglobal
100105
if ($this->placeholder->isApplicable($placeholder) && isset($_ENV[$placeholder])) {
101106
return $_ENV[$placeholder];
102107
}
108+
// phpcs:enable
103109

104110
return null;
105111
}

app/code/Magento/Config/Test/Unit/Model/Config/Reader/Source/Deployed/SettingCheckerTest.php

Lines changed: 80 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Config\Test\Unit\Model\Config\Reader\Source\Deployed;
78

8-
use Magento\Config\Model\Config\Reader;
99
use Magento\Config\Model\Config\Reader\Source\Deployed\SettingChecker;
10+
use Magento\Config\Model\Placeholder\PlaceholderFactory;
11+
use Magento\Config\Model\Placeholder\PlaceholderInterface;
1012
use Magento\Framework\App\Config;
1113
use Magento\Framework\App\DeploymentConfig;
12-
use Magento\Config\Model\Placeholder\PlaceholderInterface;
13-
use Magento\Config\Model\Placeholder\PlaceholderFactory;
1414

1515
/**
1616
* Test class for checking settings that defined in config file
@@ -71,15 +71,23 @@ public function setUp()
7171
* @param string $scopeCode
7272
* @param string|null $confValue
7373
* @param array $variables
74+
* @param array $configMap
7475
* @param bool $expectedResult
7576
* @dataProvider isReadonlyDataProvider
7677
*/
77-
public function testIsReadonly($path, $scope, $scopeCode, $confValue, array $variables, $expectedResult)
78-
{
79-
$this->placeholderMock->expects($this->once())
78+
public function testIsReadonly(
79+
$path,
80+
$scope,
81+
$scopeCode,
82+
$confValue,
83+
array $variables,
84+
array $configMap,
85+
$expectedResult
86+
) {
87+
$this->placeholderMock->expects($this->any())
8088
->method('isApplicable')
8189
->willReturn(true);
82-
$this->placeholderMock->expects($this->once())
90+
$this->placeholderMock->expects($this->any())
8391
->method('generate')
8492
->with($path, $scope, $scopeCode)
8593
->willReturn('SOME_PLACEHOLDER');
@@ -95,13 +103,18 @@ public function testIsReadonly($path, $scope, $scopeCode, $confValue, array $var
95103

96104
$this->configMock->expects($this->any())
97105
->method('get')
98-
->willReturnMap([
99-
[
100-
'system/' . $scope . "/" . ($scopeCode ? $scopeCode . '/' : '') . $path,
101-
null,
102-
$confValue
103-
],
104-
]);
106+
->willReturnMap(
107+
array_merge(
108+
[
109+
[
110+
'system/' . $scope . "/" . ($scopeCode ? $scopeCode . '/' : '') . $path,
111+
null,
112+
$confValue
113+
],
114+
],
115+
$configMap
116+
)
117+
);
105118

106119
$this->assertSame($expectedResult, $this->checker->isReadOnly($path, $scope, $scopeCode));
107120
}
@@ -118,6 +131,7 @@ public function isReadonlyDataProvider()
118131
'scopeCode' => 'myWebsite',
119132
'confValue' => 'value',
120133
'variables' => [],
134+
'configMap' => [],
121135
'expectedResult' => true,
122136
],
123137
[
@@ -126,6 +140,7 @@ public function isReadonlyDataProvider()
126140
'scopeCode' => 'myWebsite',
127141
'confValue' => null,
128142
'variables' => ['SOME_PLACEHOLDER' => 'value'],
143+
'configMap' => [],
129144
'expectedResult' => true,
130145
],
131146
[
@@ -134,7 +149,58 @@ public function isReadonlyDataProvider()
134149
'scopeCode' => 'myWebsite',
135150
'confValue' => null,
136151
'variables' => [],
152+
'configMap' => [],
137153
'expectedResult' => false,
154+
],
155+
[
156+
'path' => 'general/web/locale',
157+
'scope' => 'website',
158+
'scopeCode' => 'myWebsite',
159+
'confValue' => null,
160+
'variables' => [],
161+
'configMap' => [
162+
[
163+
'system/default/general/web/locale',
164+
null,
165+
'default_value',
166+
],
167+
],
168+
'expectedResult' => true,
169+
],
170+
[
171+
'path' => 'general/web/locale',
172+
'scope' => 'website',
173+
'scopeCode' => 'myWebsite',
174+
'confValue' => null,
175+
'variables' => [],
176+
'configMap' => [
177+
[
178+
'system/default/general/web/locale',
179+
null,
180+
'default_value',
181+
],
182+
],
183+
'expectedResult' => true,
184+
],
185+
[
186+
'path' => 'general/web/locale',
187+
'scope' => 'store',
188+
'scopeCode' => 'myStore',
189+
'confValue' => null,
190+
'variables' => [],
191+
'configMap' => [
192+
[
193+
'system/default/general/web/locale',
194+
null,
195+
'default_value',
196+
],
197+
[
198+
'system/website/myWebsite/general/web/locale',
199+
null,
200+
null,
201+
],
202+
],
203+
'expectedResult' => true,
138204
]
139205
];
140206
}

0 commit comments

Comments
 (0)