Skip to content

Commit c8d1844

Browse files
author
Joan He
committed
MAGETWO-32443: [GITHUB] if_module_enabled has no effect #934
1 parent 14583b3 commit c8d1844

File tree

2 files changed

+50
-32
lines changed

2 files changed

+50
-32
lines changed

dev/tests/integration/testsuite/Magento/Config/Block/System/Config/FormTest.php

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,21 @@ public function testDependenceHtml()
7575

7676
/**
7777
* @covers \Magento\Config\Block\System\Config\Form::initFields
78-
* @param bool $useConfigField uses the test_field_use_config field if true
78+
* @param string $fieldId uses the test_field_use_config field if true
7979
* @param bool $isConfigDataEmpty if the config data array should be empty or not
80-
* @param $configDataValue the value that the field path should be set to in the config data
80+
* @param string $configDataValue The value that the field path should be set to in the config data
81+
* @param int $valueSelCtr Number of time that value is selected
8182
* @param bool $expectedUseDefault
8283
* @dataProvider initFieldsUseDefaultCheckboxDataProvider
8384
*/
8485
public function testInitFieldsUseDefaultCheckbox(
85-
$useConfigField,
86+
$fieldId,
8687
$isConfigDataEmpty,
8788
$configDataValue,
88-
$expectedUseDefault
89+
$expectedUseDefault,
90+
$valueSelCtr = 1
8991
) {
90-
$this->_setupFieldsInheritCheckbox($useConfigField, $isConfigDataEmpty, $configDataValue);
92+
$this->_setupFieldsInheritCheckbox($fieldId, $isConfigDataEmpty, $configDataValue);
9193

9294
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
9395
'Magento\Framework\Config\ScopeInterface'
@@ -126,12 +128,17 @@ public function testInitFieldsUseDefaultCheckbox(
126128
$fieldsetHtml = $fieldset->getElementHtml();
127129

128130
$this->assertSelectCount($fieldsetSel, true, $fieldsetHtml, 'Fieldset HTML is invalid');
129-
$this->assertSelectCount($valueSel, true, $fieldsetHtml, 'Field input not found in fieldset HTML');
131+
$this->assertSelectCount(
132+
$valueSel,
133+
$valueSelCtr,
134+
$fieldsetHtml,
135+
'Field input should appear ' . $valueSelCtr . ' times in fieldset HTML'
136+
);
130137
$this->assertSelectCount(
131138
$useDefaultSel,
132-
true,
139+
$valueSelCtr,
133140
$fieldsetHtml,
134-
'"Use Default" checkbox not found in fieldset HTML'
141+
'"Use Default" checkbox should appear' . $valueSelCtr . ' times in fieldset HTML.'
135142
);
136143

137144
if ($expectedUseDefault) {
@@ -159,25 +166,27 @@ public function testInitFieldsUseDefaultCheckbox(
159166
public static function initFieldsUseDefaultCheckboxDataProvider()
160167
{
161168
return [
162-
[false, true, null, true],
163-
[false, false, null, false],
164-
[false, false, '', false],
165-
[false, false, 'value', false],
166-
[true, false, 'config value', false]
169+
['test_field', true, null, true],
170+
['test_field', false, null, false],
171+
['test_field', false, '', false],
172+
['test_field', false, 'value', false],
173+
['test_field_use_config_module_1', false, 'config value', false],
174+
['test_field_use_config_module_0', false, 'config value', false, 0],
167175
];
168176
}
169177

170178
/**
171179
* @covers \Magento\Config\Block\System\Config\Form::initFields
172-
* @param bool $useConfigField uses the test_field_use_config field if true
180+
* @param string $fieldId uses the test_field_use_config field if true
173181
* @param bool $isConfigDataEmpty if the config data array should be empty or not
174-
* @param $configDataValue the value that the field path should be set to in the config data
182+
* @param string $configDataValue Value that the field path should be set to in the config data
183+
* @param int $valueSelCtr Number of time that value is selected
175184
* @dataProvider initFieldsUseConfigPathDataProvider
176185
* @magentoConfigFixture default/test_config_section/test_group_config_node/test_field_value config value
177186
*/
178-
public function testInitFieldsUseConfigPath($useConfigField, $isConfigDataEmpty, $configDataValue)
187+
public function testInitFieldsUseConfigPath($fieldId, $isConfigDataEmpty, $configDataValue, $valueSelCtr = 1)
179188
{
180-
$this->_setupFieldsInheritCheckbox($useConfigField, $isConfigDataEmpty, $configDataValue);
189+
$this->_setupFieldsInheritCheckbox($fieldId, $isConfigDataEmpty, $configDataValue);
181190

182191
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
183192
'Magento\Framework\Config\ScopeInterface'
@@ -208,7 +217,12 @@ public function testInitFieldsUseConfigPath($useConfigField, $isConfigDataEmpty,
208217
$fieldsetHtml = $fieldset->getElementHtml();
209218

210219
$this->assertSelectCount($fieldsetSel, true, $fieldsetHtml, 'Fieldset HTML is invalid');
211-
$this->assertSelectCount($valueSel, true, $fieldsetHtml, 'Field input not found in fieldset HTML');
220+
$this->assertSelectCount(
221+
$valueSel,
222+
$valueSelCtr,
223+
$fieldsetHtml,
224+
'Field input should appear ' . $valueSelCtr . ' times in fieldset HTML'
225+
);
212226
}
213227

214228
/**
@@ -217,20 +231,21 @@ public function testInitFieldsUseConfigPath($useConfigField, $isConfigDataEmpty,
217231
public static function initFieldsUseConfigPathDataProvider()
218232
{
219233
return [
220-
[false, true, null],
221-
[false, false, null],
222-
[false, false, ''],
223-
[false, false, 'value'],
224-
[true, false, 'config value']
234+
['test_field', true, null],
235+
['test_field', false, null],
236+
['test_field', false, ''],
237+
['test_field', false, 'value'],
238+
['test_field_use_config_module_1', false, 'config value'],
239+
['test_field_use_config_module_0', false, 'config value', 0]
225240
];
226241
}
227242

228243
/**
229-
* @param bool $useConfigField uses the test_field_use_config field if true
244+
* @param string $fieldId uses the test_field_use_config field if true
230245
* @param bool $isConfigDataEmpty if the config data array should be empty or not
231-
* @param $configDataValue the value that the field path should be set to in the config data
246+
* @param string $configDataValue the value that the field path should be set to in the config data
232247
*/
233-
protected function _setupFieldsInheritCheckbox($useConfigField, $isConfigDataEmpty, $configDataValue)
248+
protected function _setupFieldsInheritCheckbox($fieldId, $isConfigDataEmpty, $configDataValue)
234249
{
235250
\Magento\TestFramework\Helper\Bootstrap::getInstance()->reinitialize([
236251
State::PARAM_BAN_CACHE => true,
@@ -273,11 +288,8 @@ protected function _setupFieldsInheritCheckbox($useConfigField, $isConfigDataEmp
273288

274289
$this->_group = $structure->getElement('test_section/test_group');
275290

276-
if ($useConfigField) {
277-
$this->_field = $structure->getElement('test_section/test_group/test_field_use_config');
278-
} else {
279-
$this->_field = $structure->getElement('test_section/test_group/test_field');
280-
}
291+
$this->_field = $structure->getElement('test_section/test_group/' . $fieldId);
292+
281293
$fieldPath = $this->_field->getConfigPath();
282294

283295
if ($isConfigDataEmpty) {

dev/tests/integration/testsuite/Magento/Config/Block/System/Config/_files/test_section_config.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,15 @@
2020
<label>Test Field</label>
2121
<config_path>test_section/test_group/test_field</config_path>
2222
</field>
23-
<field id="test_field_use_config" translate="label comment" showInDefault="1" showInWebsite="1" showInStore="1" type="text" sortOrder="20">
23+
<field id="test_field_use_config_module_1" translate="label comment" showInDefault="1" showInWebsite="1" showInStore="1" type="text" sortOrder="20">
2424
<label>Test Field</label>
2525
<config_path>test_config_section/test_group_config_node/test_field_value</config_path>
26+
<if_module_enabled>Magento_Config</if_module_enabled>
27+
</field>
28+
<field id="test_field_use_config_module_0" translate="label comment" showInDefault="1" showInWebsite="1" showInStore="1" type="text" sortOrder="20">
29+
<label>Test Field</label>
30+
<config_path>test_config_section/test_group_config_node/test_field_value</config_path>
31+
<if_module_enabled>Test_Module</if_module_enabled>
2632
</field>
2733
</group>
2834
</section>

0 commit comments

Comments
 (0)