Skip to content

Commit a77921a

Browse files
added test coverage; refactor
1 parent c7b5a73 commit a77921a

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

app/code/Magento/Config/Model/Config/PathValidator.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Magento\Config\Model\Config;
88

9+
use Magento\Config\Model\Config\Structure\Element\Field;
910
use Magento\Framework\Exception\ValidatorException;
1011

1112
/**
@@ -41,10 +42,10 @@ public function __construct(Structure $structure)
4142
public function validate($path)
4243
{
4344
$element = $this->structure->getElementByConfigPath($path);
44-
if ($element->getConfigPath()) {
45+
if ($element instanceof Field && $element->getConfigPath()) {
4546
$path = $element->getConfigPath();
4647
}
47-
48+
4849
$allPaths = $this->structure->getFieldPaths();
4950

5051
if (!array_key_exists($path, $allPaths)) {

dev/tests/integration/testsuite/Magento/Config/Console/Command/ConfigSetCommandTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Config\Console\Command;
88

99
use Magento\Config\Model\Config\Backend\Admin\Custom;
10+
use Magento\Config\Model\Config\PathValidator;
1011
use Magento\Config\Model\Config\Structure\Converter;
1112
use Magento\Config\Model\Config\Structure\Data as StructureData;
1213
use Magento\Directory\Model\Currency;
@@ -444,6 +445,15 @@ public function configSetValidDataProvider()
444445
];
445446
}
446447

448+
/**
449+
* Test validate path when field has custom config_path
450+
*/
451+
public function testValidatePathWithCustomConfigPath(): void
452+
{
453+
$pathValidator = $this->objectManager->get(PathValidator::class);
454+
$this->assertTrue($pathValidator->validate('general/group/subgroup/second_field'));
455+
}
456+
447457
/**
448458
* Set configuration and check this value from DB with success message this command should display
449459
*

dev/tests/integration/testsuite/Magento/Config/_files/system.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
<field id="field" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="0">
1414
<label>Label</label>
1515
</field>
16+
<field id="second_field" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="0">
17+
<label>Label Second</label>
18+
<config_path>custom/config_path/second_field</config_path>
19+
</field>
1620
</group>
1721
</group>
1822
</section>

0 commit comments

Comments
 (0)