8000 bug #25789 Enableable ArrayNodeDefinition is disabled for empty conf… · symfony/symfony@132cec4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 132cec4

Browse files
committed
bug #25789 Enableable ArrayNodeDefinition is disabled for empty configuration (kejwmen)
This PR was squashed before being merged into the 2.7 branch (closes #25789). Discussion ---------- Enableable ArrayNodeDefinition is disabled for empty configuration | Q | A | ------------- | --- | Branch? | 2.7+ | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #25760 | License | MIT Fixes #25760. Currently, documented behavior is not true: https://github.com/symfony/symfony/blob/70c8c2d47bd71861c8205985a17e68cedf828e1f/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php#L207-L208 Commits ------- a6a330d Enableable ArrayNodeDefinition is disabled for empty configuration
2 parents d411301 + a6a330d commit 132cec4

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,9 @@ public function canBeEnabled()
226226
->beforeNormalization()
227227
->ifArray()
228228
->then(function ($v) {
229-
$v['enabled'] = isset($v['enabled']) ? $v['enabled'] : true;
229+
if (!isset($v['enabled'])) {
230+
$v['enabled'] = !empty($v);
231+
}
230232

231233
return $v;
232234
})

src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,20 @@ public function testCanBeDisabled()
207207
$this->assertTrue($this->getField($enabledNode, 'defaultValue'));
208208
}
209209

210+
public function testEnableableNodeIsDisabledForEmptyConfigurationWhenNormalized()
211+
{
212+
$config = array();
213+
214+
$node = new ArrayNodeDefinition('root');
215+
$node->canBeEnabled();
216+
217+
$this->assertEquals(
218+
array('enabled' => false),
219+
$node->getNode()->normalize($config),
220+
'An enableable node is disabled by default'
221+
);
222+
}
223+
210224
public function testIgnoreExtraKeys()
211225
{
212226
$node = new ArrayNodeDefinition('root');
@@ -240,6 +254,7 @@ public function getEnableableNodeFixtures()
240254
array(array('enabled' => true, 'foo' => 'baz'), array(array('foo' => 'baz')), 'any configuration enables an enableable node'),
241255
array(array('enabled' => false, 'foo' => 'baz'), array(array('foo' => 'baz', 'enabled' => false)), 'An enableable node can be disabled'),
242256
array(array('enabled' => false, 'foo' => 'bar'), array(false), 'false disables an enableable node'),
257+
array(array('enabled' => false, 'foo' => 'bar'), array(), 'enableable node is disabled by default'),
243258
);
244259
}
245260

src/Symfony/Component/Config/Tests/Definition/Builder/TreeBuilderTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Config\Tests\Definition\Builder;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Config\Definition\Processor;
1516
use Symfony\Component\Config\Tests\Fixtures\Builder\NodeBuilder as CustomNodeBuilder;
1617
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
1718

@@ -131,4 +132,22 @@ public function testDefinitionExampleGetsTransferredToNode()
131132
$this->assertInternalType('array', $tree->getExample());
132133
$this->assertEquals('example', $children['child']->getExample());
133134
}
135+
136+
public function testRootNodeThatCanBeEnabledIsDisabledByDefault()
137+
{
138+
$builder = new TreeBuilder();
139+
140+
$builder->root('test')
141+
->canBeEnabled();
142+
143+
$tree = $builder->buildTree();
144+
$children = $tree->getChildren();
145+
146+
$this->assertFalse($children['enabled']->getDefaultValue());
147+
148+
$processor = new Processor();
149+
$result = $processor->process($tree, array());
150+
151+
$this->assertEquals(array('enabled' => false), $result);
152+
}
134153
}

0 commit comments

Comments
 (0)
0