Skip to content

Commit bd88ed8

Browse files
⏫ Forwardport of #12207 to 2.3-develop branch
1 parent c7207f6 commit bd88ed8

File tree

11 files changed

+159
-36
lines changed

11 files changed

+159
-36
lines changed

Diff for: app/code/Magento/Backend/etc/adminhtml/di.xml

+3
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@
145145
<item name="dev" xsi:type="const">Magento\Config\Model\Config\Structure\ElementVisibilityInterface::HIDDEN</item>
146146
<item name="general/locale/code" xsi:type="const">Magento\Config\Model\Config\Structure\ElementVisibilityInterface::DISABLED</item>
147147
</argument>
148+
<argument name="exemptions" xsi:type="array">
149+
<item name="dev/debug/debug_logging" xsi:type="string"/>
150+
</argument>
148151
</arguments>
149152
</type>
150153
<type name="Magento\Backend\Model\Search\Config\Result\Builder">

Diff for: app/code/Magento/Config/Model/Config/Structure/ConcealInProductionConfigList.php

+37-4
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,36 @@ class ConcealInProductionConfigList implements ElementVisibilityInterface
4242
*/
4343
private $state;
4444

45+
/**
46+
*
47+
* The list of form element paths which ignore visibility status.
48+
*
49+
* E.g.
50+
*
51+
* ```php
52+
* [
53+
* 'general/country/default' => '',
54+
* ];
55+
* ```
56+
*
57+
* It means that:
58+
* - field 'default' in group Country Options (in section General) will be showed, even if all group(section)
59+
* will be hidden.
60+
*
61+
* @var array
62+
*/
63+
private $exemptions = [];
64+
4565
/**
4666
* @param State $state The object that has information about the state of the system
4767
* @param array $configs The list of form element paths with concrete visibility status.
68+
* @param array $exemptions The list of form element paths which ignore visibility status.
4869
*/
49-
public function __construct(State $state, array $configs = [])
70+
public function __construct(State $state, array $configs = [], array $exemptions = [])
5071
{
5172
$this->state = $state;
5273
$this->configs = $configs;
74+
$this->exemptions = $exemptions;
5375
}
5476

5577
/**
@@ -58,10 +80,21 @@ public function __construct(State $state, array $configs = [])
5880
*/
5981
public function isHidden($path)
6082
{
83+
$result = false;
6184
$path = $this->normalizePath($path);
62-
return $this->state->getMode() === State::MODE_PRODUCTION
63-
&& !empty($this->configs[$path])
64-
&& $this->configs[$path] === static::HIDDEN;
85+
if ($this->state->getMode() === State::MODE_PRODUCTION
86+
&& preg_match('/(?<group>(?<section>.*?)\/.*?)\/.*?/', $path, $match)) {
87+
$group = $match['group'];
88+
$section = $match['section'];
89+
$exemptions = array_keys($this->exemptions);
90+
foreach ($this->configs as $configPath => $value) {
91+
if ($value === static::HIDDEN && strpos($path, $configPath) !==false) {
92+
$result = empty(array_intersect([$section, $group, $path], $exemptions));
93+
}
94+
}
95+
}
96+
97+
return $result;
6598
}
6699

67100
/**

Diff for: app/code/Magento/Config/Test/Unit/Model/Config/Structure/ConcealInProductionConfigListTest.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ protected function setUp()
3333
'third/path' => 'no',
3434
'third/path/field' => ConcealInProductionConfigList::DISABLED,
3535
'first/path/field' => 'no',
36+
'fourth' => ConcealInProductionConfigList::HIDDEN,
37+
];
38+
$exemptions = [
39+
'fourth/path/value' => '',
3640
];
3741

38-
$this->model = new ConcealInProductionConfigList($this->stateMock, $configs);
42+
$this->model = new ConcealInProductionConfigList($this->stateMock, $configs, $exemptions);
3943
}
4044

4145
/**
@@ -96,8 +100,10 @@ public function hiddenDataProvider()
96100
['first/path', State::MODE_PRODUCTION, false],
97101
['first/path', State::MODE_DEFAULT, false],
98102
['some/path', State::MODE_PRODUCTION, false],
99-
['second/path', State::MODE_PRODUCTION, true],
103+
['second/path/field', State::MODE_PRODUCTION, true],
100104
['second/path', State::MODE_DEVELOPER, false],
105+
['fourth/path/value', State::MODE_PRODUCTION, false],
106+
['fourth/path/test', State::MODE_PRODUCTION, true],
101107
];
102108
}
103109
}

Diff for: app/code/Magento/Deploy/App/Mode/ConfigProvider.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ConfigProvider
1616
* [
1717
* 'developer' => [
1818
* 'production' => [
19-
* {{setting_path}} => {{setting_value}}
19+
* {{setting_path}} => ['value' => {{setting_value}}, 'lock' => {{lock_value}}]
2020
* ]
2121
* ]
2222
* ]
@@ -41,7 +41,7 @@ public function __construct(array $config = [])
4141
* need to turn off 'dev/debug/debug_logging' setting in this case method
4242
* will return array
4343
* [
44-
* {{setting_path}} => {{setting_value}}
44+
* {{setting_path}} => ['value' => {{setting_value}}, 'lock' => {{lock_value}}]
4545
* ]
4646
*
4747
* @param string $currentMode

Diff for: app/code/Magento/Deploy/Model/Mode.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -224,17 +224,17 @@ protected function setStoreMode($mode)
224224
private function saveAppConfigs($mode)
225225
{
226226
$configs = $this->configProvider->getConfigs($this->getMode(), $mode);
227-
foreach ($configs as $path => $value) {
228-
$this->emulatedAreaProcessor->process(function () use ($path, $value) {
227+
foreach ($configs as $path => $item) {
228+
$this->emulatedAreaProcessor->process(function () use ($path, $item) {
229229
$this->processorFacadeFactory->create()->process(
230230
$path,
231-
$value,
231+
$item['value'],
232232
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
233233
null,
234-
true
234+
$item['lock']
235235
);
236236
});
237-
$this->output->writeln('Config "' . $path . ' = ' . $value . '" has been saved.');
237+
$this->output->writeln('Config "' . $path . ' = ' . $item['value'] . '" has been saved.');
238238
}
239239
}
240240

Diff for: app/code/Magento/Deploy/Test/Unit/Model/ModeTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public function testEnableProductionModeMinimal()
226226
->method('getConfigs')
227227
->with('developer', 'production')
228228
->willReturn([
229-
'dev/debug/debug_logging' => 0
229+
'dev/debug/debug_logging' => ['value' => 0, 'lock' => false]
230230
]);
231231
$this->emulatedAreaProcessor->expects($this->once())
232232
->method('process')
@@ -245,7 +245,7 @@ public function testEnableProductionModeMinimal()
245245
0,
246246
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
247247
null,
248-
true
248+
false
249249
);
250250
$this->outputMock->expects($this->once())
251251
->method('writeln')

Diff for: app/code/Magento/Deploy/etc/di.xml

+26-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,32 @@
7575
<argument name="config" xsi:type="array">
7676
<item name="developer" xsi:type="array">
7777
<item name="production" xsi:type="array">
78-
<item name="dev/debug/debug_logging" xsi:type="string">0</item>
78+
<item name="dev/debug/debug_logging" xsi:type="array">
79+
<item name="value" xsi:type="string">0</item>
80+
<item name="lock" xsi:type="boolean">false</item>
81+
</item>
82+
</item>
83+
</item>
84+
<item name="production" xsi:type="array">
85+
<item name="developer" xsi:type="array">
86+
<item name="dev/debug/debug_logging" xsi:type="array">
87+
<item name="value" xsi:type="string">1</item>
88+
<item name="lock" xsi:type="boolean">false</item>
89+
</item>
90+
</item>
91+
</item>
92+
<item name="default" xsi:type="array">
93+
<item name="production" xsi:type="array">
94+
<item name="dev/debug/debug_logging" xsi:type="array">
95+
<item name="value" xsi:type="string">0</item>
96+
<item name="lock" xsi:type="boolean">false</item>
97+
</item>
98+
</item>
99+
<item name="developer" xsi:type="array">
100+
<item name="dev/debug/debug_logging" xsi:type="array">
101+
<item name="value" xsi:type="string">1</item>
102+
<item name="lock" xsi:type="boolean">false</item>
103+
</item>
79104
</item>
80105
</item>
81106
</argument>

Diff for: app/code/Magento/Developer/etc/adminhtml/system.xml

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
<group id="debug" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
2929
<field id="debug_logging" translate="label comment" type="select" sortOrder="30" showInDefault="1" showInWebsite="0" showInStore="0">
3030
<label>Log to File</label>
31-
<comment>Not available in production mode.</comment>
3231
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
3332
</field>
3433
</group>

Diff for: dev/tests/functional/tests/app/Magento/Backend/Test/Block/System/Config/Form.php

+39-11
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,7 @@ class Form extends Block
6060
*/
6161
public function getGroup($tabName, $groupName)
6262
{
63-
$this->baseUrl = $this->getBrowserUrl();
64-
if (substr($this->baseUrl, -1) !== '/') {
65-
$this->baseUrl = $this->baseUrl . '/';
66-
}
67-
68-
$tabUrl = $this->getTabUrl($tabName);
69-
70-
if ($this->getBrowserUrl() !== $tabUrl) {
71-
$this->browser->open($tabUrl);
72-
}
73-
$this->waitForElementNotVisible($this->tabReadiness);
63+
$this->openTab($tabName);
7464

7565
$groupElement = $this->_rootElement->find(
7666
sprintf($this->groupBlock, $tabName, $groupName),
@@ -95,6 +85,24 @@ public function getGroup($tabName, $groupName)
9585
return $blockFactory->getMagentoBackendSystemConfigFormGroup($groupElement);
9686
}
9787

88+
/**
89+
* Check whether specified group presented on page.
90+
*
91+
* @param string $tabName
92+
* @param string $groupName
93+
*
94+
* @return bool
95+
*/
96+
public function isGroupVisible(string $tabName, string $groupName)
97+
{
98+
$this->openTab($tabName);
99+
100+
return $this->_rootElement->find(
101+
sprintf($this->groupBlockLink, $tabName, $groupName),
102+
Locator::SELECTOR_CSS
103+
)->isVisible();
104+
}
105+
98106
/**
99107
* Retrieve url associated with the form.
100108
*/
@@ -137,4 +145,24 @@ private function getTabUrl($tabName)
137145

138146
return $tabUrl;
139147
}
148+
149+
/**
150+
* Open specified tab.
151+
*
152+
* @param string $tabName
153+
* @return void
154+
*/
155+
private function openTab(string $tabName)
156+
{
157+
$this->baseUrl = $this->getBrowserUrl();
158+
if (substr($this->baseUrl, -1) !== '/') {
159+
$this->baseUrl = $this->baseUrl . '/';
160+
}
161+
$tabUrl = $this->getTabUrl($tabName);
162+
163+
if ($this->getBrowserUrl() !== $tabUrl) {
164+
$this->browser->open($tabUrl);
165+
}
166+
$this->waitForElementNotVisible($this->tabReadiness);
167+
}
140168
}

Diff for: dev/tests/functional/tests/app/Magento/Backend/Test/Constraint/AssertDeveloperSectionVisibility.php

+37-7
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,57 @@
99
use Magento\Backend\Test\Page\Adminhtml\SystemConfigEdit;
1010

1111
/**
12-
* Assert that Developer section is not present in production mode.
12+
* Assert that all groups in Developer section is not present in production mode except debug group "Log to File" field.
1313
*/
1414
class AssertDeveloperSectionVisibility extends AbstractConstraint
1515
{
1616
/**
17-
* Assert Developer section is not present in production mode.
17+
* List of groups not visible in production mode.
18+
*
19+
* @var array
20+
*/
21+
private $groups = [
22+
'front_end_development_workflow',
23+
'restrict',
24+
'template',
25+
'translate_inline',
26+
'js',
27+
'css',
28+
'image',
29+
'static',
30+
'grid',
31+
];
32+
33+
/**
34+
* Assert all groups in Developer section is not present in production mode except debug group "Log to File" field.
1835
*
1936
* @param SystemConfigEdit $configEdit
2037
* @return void
2138
*/
2239
public function processAssert(SystemConfigEdit $configEdit)
2340
{
41+
$configEdit->open();
2442
if ($_ENV['mage_mode'] === 'production') {
25-
\PHPUnit_Framework_Assert::assertFalse(
26-
in_array('Developer', $configEdit->getTabs()->getSubTabsNames('Advanced')),
27-
'Developer section should be hidden in production mode.'
43+
foreach ($this->groups as $group) {
44+
\PHPUnit_Framework_Assert::assertFalse(
45+
$configEdit->getForm()->isGroupVisible('dev', $group),
46+
sprintf('%s group should be hidden in production mode.', $group)
47+
);
48+
}
49+
\PHPUnit_Framework_Assert::assertTrue(
50+
$configEdit->getForm()->getGroup('dev', 'debug')->isFieldVisible('dev', 'debug_debug', 'logging'),
51+
'"Log to File" should be presented in production mode.'
2852
);
2953
} else {
54+
foreach ($this->groups as $group) {
55+
\PHPUnit_Framework_Assert::assertTrue(
56+
$configEdit->getForm()->isGroupVisible('dev', $group),
57+
sprintf('%s group should be visible in developer mode.', $group)
58+
);
59+
}
3060
\PHPUnit_Framework_Assert::assertTrue(
31-
in_array('Developer', $configEdit->getTabs()->getSubTabsNames('Advanced')),
32-
'Developer section should be not hidden in developer or default mode.'
61+
$configEdit->getForm()->isGroupVisible('dev', 'debug'),
62+
'Debug group should be visible in developer mode.'
3363
);
3464
}
3565
}

Diff for: dev/tests/integration/testsuite/Magento/Developer/Model/Logger/Handler/DebugTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ public function setUp()
9595

9696
// Preconditions
9797
$this->mode->enableDeveloperMode();
98-
$this->enableDebugging();
9998
if (file_exists($this->getDebuggerLogPath())) {
10099
unlink($this->getDebuggerLogPath());
101100
}

0 commit comments

Comments
 (0)