Skip to content

Commit

Permalink
Merge pull request #2251 from magento-tsg/2.2.4-develop-pr22
Browse files Browse the repository at this point in the history
[TSG] Backporting for 2.2 (pr22) (2.2.4)
  • Loading branch information
Alexander Akimov authored Mar 22, 2018
2 parents c42130d + 36f707b commit db679be
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 160 deletions.
3 changes: 0 additions & 3 deletions app/code/Magento/Backend/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,6 @@
<item name="dev" xsi:type="const">Magento\Config\Model\Config\Structure\ElementVisibilityInterface::HIDDEN</item>
<item name="general/locale/code" xsi:type="const">Magento\Config\Model\Config\Structure\ElementVisibilityInterface::DISABLED</item>
</argument>
<argument name="exemptions" xsi:type="array">
<item name="dev/debug/debug_logging" xsi:type="string"/>
</argument>
</arguments>
</type>
<type name="Magento\Framework\View\Layout\Generator\Block">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,36 +42,14 @@ class ConcealInProductionConfigList implements ElementVisibilityInterface
*/
private $state;

/**
*
* The list of form element paths which ignore visibility status.
*
* E.g.
*
* ```php
* [
* 'general/country/default' => '',
* ];
* ```
*
* It means that:
* - field 'default' in group Country Options (in section General) will be showed, even if all group(section)
* will be hidden.
*
* @var array
*/
private $exemptions = [];

/**
* @param State $state The object that has information about the state of the system
* @param array $configs The list of form element paths with concrete visibility status.
* @param array $exemptions The list of form element paths which ignore visibility status.
*/
public function __construct(State $state, array $configs = [], array $exemptions = [])
public function __construct(State $state, array $configs = [])
{
$this->state = $state;
$this->configs = $configs;
$this->exemptions = $exemptions;
}

/**
Expand All @@ -80,21 +58,10 @@ public function __construct(State $state, array $configs = [], array $exemptions
*/
public function isHidden($path)
{
$result = false;
$path = $this->normalizePath($path);
if ($this->state->getMode() === State::MODE_PRODUCTION
&& preg_match('/(?<group>(?<section>.*?)\/.*?)\/.*?/', $path, $match)) {
$group = $match['group'];
$section = $match['section'];
$exemptions = array_keys($this->exemptions);
foreach ($this->configs as $configPath => $value) {
if ($value === static::HIDDEN && strpos($path, $configPath) !==false) {
$result = empty(array_intersect([$section, $group, $path], $exemptions));
}
}
}

return $result;
return $this->state->getMode() === State::MODE_PRODUCTION
&& !empty($this->configs[$path])
&& $this->configs[$path] === static::HIDDEN;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,9 @@ protected function setUp()
'third/path' => 'no',
'third/path/field' => ConcealInProductionConfigList::DISABLED,
'first/path/field' => 'no',
'fourth' => ConcealInProductionConfigList::HIDDEN,
];
$exemptions = [
'fourth/path/value' => '',
];

$this->model = new ConcealInProductionConfigList($this->stateMock, $configs, $exemptions);
$this->model = new ConcealInProductionConfigList($this->stateMock, $configs);
}

/**
Expand Down Expand Up @@ -100,10 +96,8 @@ public function hiddenDataProvider()
['first/path', State::MODE_PRODUCTION, false],
['first/path', State::MODE_DEFAULT, false],
['some/path', State::MODE_PRODUCTION, false],
['second/path/field', State::MODE_PRODUCTION, true],
['second/path', State::MODE_PRODUCTION, true],
['second/path', State::MODE_DEVELOPER, false],
['fourth/path/value', State::MODE_PRODUCTION, false],
['fourth/path/test', State::MODE_PRODUCTION, true],
];
}
}
4 changes: 2 additions & 2 deletions app/code/Magento/Deploy/App/Mode/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ConfigProvider
* [
* 'developer' => [
* 'production' => [
* {{setting_path}} => ['value' => {{setting_value}}, 'lock' => {{lock_value}}]
* {{setting_path}} => {{setting_value}}
* ]
* ]
* ]
Expand All @@ -41,7 +41,7 @@ public function __construct(array $config = [])
* need to turn off 'dev/debug/debug_logging' setting in this case method
* will return array
* [
* {{setting_path}} => ['value' => {{setting_value}}, 'lock' => {{lock_value}}]
* {{setting_path}} => {{setting_value}}
* ]
*
* @param string $currentMode
Expand Down
10 changes: 5 additions & 5 deletions app/code/Magento/Deploy/Model/Mode.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,17 @@ protected function setStoreMode($mode)
private function saveAppConfigs($mode)
{
$configs = $this->configProvider->getConfigs($this->getMode(), $mode);
foreach ($configs as $path => $item) {
$this->emulatedAreaProcessor->process(function () use ($path, $item) {
foreach ($configs as $path => $value) {
$this->emulatedAreaProcessor->process(function () use ($path, $value) {
$this->processorFacadeFactory->create()->processWithLockTarget(
$path,
$item['value'],
$value,
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
null,
$item['lock']
true
);
});
$this->output->writeln('Config "' . $path . ' = ' . $item['value'] . '" has been saved.');
$this->output->writeln('Config "' . $path . ' = ' . $value . '" has been saved.');
}
}
}
4 changes: 2 additions & 2 deletions app/code/Magento/Deploy/Test/Unit/Model/ModeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public function testEnableProductionModeMinimal()
->method('getConfigs')
->with('developer', 'production')
->willReturn([
'dev/debug/debug_logging' => ['value' => 0, 'lock' => false]
'dev/debug/debug_logging' => 0
]);
$this->emulatedAreaProcessor->expects($this->once())
->method('process')
Expand All @@ -247,7 +247,7 @@ public function testEnableProductionModeMinimal()
0,
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
null,
false
true
);
$this->outputMock->expects($this->once())
->method('writeln')
Expand Down
28 changes: 1 addition & 27 deletions app/code/Magento/Deploy/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
<item name="dumpApplicationCommand" xsi:type="object">\Magento\Deploy\Console\Command\App\ApplicationDumpCommand</item>
<item name="sensitiveConfigSetCommand" xsi:type="object">\Magento\Deploy\Console\Command\App\SensitiveConfigSetCommand</item>
<item name="configImportCommand" xsi:type="object">Magento\Deploy\Console\Command\App\ConfigImportCommand</item>
<item name="configStatusCommand" xsi:type="object">Magento\Deploy\Console\Command\App\ConfigStatusCommand</item>
</argument>
</arguments>
</type>
Expand Down Expand Up @@ -76,32 +75,7 @@
<argument name="config" xsi:type="array">
<item name="developer" xsi:type="array">
<item name="production" xsi:type="array">
<item name="dev/debug/debug_logging" xsi:type="array">
<item name="value" xsi:type="string">0</item>
<item name="lock" xsi:type="boolean">false</item>
</item>
</item>
</item>
<item name="production" xsi:type="array">
<item name="developer" xsi:type="array">
<item name="dev/debug/debug_logging" xsi:type="array">
<item name="value" xsi:type="string">1</item>
<item name="lock" xsi:type="boolean">false</item>
</item>
</item>
</item>
<item name="default" xsi:type="array">
<item name="production" xsi:type="array">
<item name="dev/debug/debug_logging" xsi:type="array">
<item name="value" xsi:type="string">0</item>
<item name="lock" xsi:type="boolean">false</item>
</item>
</item>
<item name="developer" xsi:type="array">
<item name="dev/debug/debug_logging" xsi:type="array">
<item name="value" xsi:type="string">1</item>
<item name="lock" xsi:type="boolean">false</item>
</item>
<item name="dev/debug/debug_logging" xsi:type="string">0</item>
</item>
</item>
</argument>
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Developer/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<group id="debug" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<field id="debug_logging" translate="label comment" type="select" sortOrder="30" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Log to File</label>
<comment>Not available in production mode.</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,17 @@ class Form extends Block
*/
public function getGroup($tabName, $groupName)
{
$this->openTab($tabName);
$this->baseUrl = $this->getBrowserUrl();
if (substr($this->baseUrl, -1) !== '/') {
$this->baseUrl = $this->baseUrl . '/';
}

$tabUrl = $this->getTabUrl($tabName);

if ($this->getBrowserUrl() !== $tabUrl) {
$this->browser->open($tabUrl);
}
$this->waitForElementNotVisible($this->tabReadiness);

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

/**
* Check whether specified group presented on page.
*
* @param string $tabName
* @param string $groupName
*
* @return bool
*/
public function isGroupVisible(string $tabName, string $groupName)
{
$this->openTab($tabName);

return $this->_rootElement->find(
sprintf($this->groupBlockLink, $tabName, $groupName),
Locator::SELECTOR_CSS
)->isVisible();
}

/**
* Retrieve url associated with the form.
*/
Expand Down Expand Up @@ -145,24 +137,4 @@ private function getTabUrl($tabName)

return $tabUrl;
}

/**
* Open specified tab.
*
* @param string $tabName
* @return void
*/
private function openTab(string $tabName)
{
$this->baseUrl = $this->getBrowserUrl();
if (substr($this->baseUrl, -1) !== '/') {
$this->baseUrl = $this->baseUrl . '/';
}
$tabUrl = $this->getTabUrl($tabName);

if ($this->getBrowserUrl() !== $tabUrl) {
$this->browser->open($tabUrl);
}
$this->waitForElementNotVisible($this->tabReadiness);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,57 +9,27 @@
use Magento\Backend\Test\Page\Adminhtml\SystemConfigEdit;

/**
* Assert that all groups in Developer section is not present in production mode except debug group "Log to File" field.
* Assert that Developer section is not present in production mode.
*/
class AssertDeveloperSectionVisibility extends AbstractConstraint
{
/**
* List of groups not visible in production mode.
*
* @var array
*/
private $groups = [
'front_end_development_workflow',
'restrict',
'template',
'translate_inline',
'js',
'css',
'image',
'static',
'grid',
];

/**
* Assert all groups in Developer section is not present in production mode except debug group "Log to File" field.
* Assert Developer section is not present in production mode.
*
* @param SystemConfigEdit $configEdit
* @return void
*/
public function processAssert(SystemConfigEdit $configEdit)
{
$configEdit->open();
if ($_ENV['mage_mode'] === 'production') {
foreach ($this->groups as $group) {
\PHPUnit_Framework_Assert::assertFalse(
$configEdit->getForm()->isGroupVisible('dev', $group),
sprintf('%s group should be hidden in production mode.', $group)
);
}
\PHPUnit_Framework_Assert::assertTrue(
$configEdit->getForm()->getGroup('dev', 'debug')->isFieldVisible('dev', 'debug_debug', 'logging'),
'"Log to File" should be presented in production mode.'
\PHPUnit_Framework_Assert::assertFalse(
in_array('Developer', $configEdit->getTabs()->getSubTabsNames('Advanced')),
'Developer section should be hidden in production mode.'
);
} else {
foreach ($this->groups as $group) {
\PHPUnit_Framework_Assert::assertTrue(
$configEdit->getForm()->isGroupVisible('dev', $group),
sprintf('%s group should be visible in developer mode.', $group)
);
}
\PHPUnit_Framework_Assert::assertTrue(
$configEdit->getForm()->isGroupVisible('dev', 'debug'),
'Debug group should be visible in developer mode.'
in_array('Developer', $configEdit->getTabs()->getSubTabsNames('Advanced')),
'Developer section should be not hidden in developer or default mode.'
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public function setUp()

// Preconditions
$this->mode->enableDeveloperMode();
$this->enableDebugging();
if (file_exists($this->getDebuggerLogPath())) {
unlink($this->getDebuggerLogPath());
}
Expand Down

0 comments on commit db679be

Please sign in to comment.