Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / symfony / config / Tests / Definition / Builder / TreeBuilderTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Config\Tests\Definition\Builder;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Config\Definition\Builder\TreeBuilder;
16 use Symfony\Component\Config\Tests\Fixtures\Builder\NodeBuilder as CustomNodeBuilder;
17
18 class TreeBuilderTest extends TestCase
19 {
20     public function testUsingACustomNodeBuilder()
21     {
22         $builder = new TreeBuilder();
23         $root = $builder->root('custom', 'array', new CustomNodeBuilder());
24
25         $nodeBuilder = $root->children();
26
27         $this->assertInstanceOf('Symfony\Component\Config\Tests\Fixtures\Builder\NodeBuilder', $nodeBuilder);
28
29         $nodeBuilder = $nodeBuilder->arrayNode('deeper')->children();
30
31         $this->assertInstanceOf('Symfony\Component\Config\Tests\Fixtures\Builder\NodeBuilder', $nodeBuilder);
32     }
33
34     public function testOverrideABuiltInNodeType()
35     {
36         $builder = new TreeBuilder();
37         $root = $builder->root('override', 'array', new CustomNodeBuilder());
38
39         $definition = $root->children()->variableNode('variable');
40
41         $this->assertInstanceOf('Symfony\Component\Config\Tests\Fixtures\Builder\VariableNodeDefinition', $definition);
42     }
43
44     public function testAddANodeType()
45     {
46         $builder = new TreeBuilder();
47         $root = $builder->root('override', 'array', new CustomNodeBuilder());
48
49         $definition = $root->children()->barNode('variable');
50
51         $this->assertInstanceOf('Symfony\Component\Config\Tests\Fixtures\Builder\BarNodeDefinition', $definition);
52     }
53
54     public function testCreateABuiltInNodeTypeWithACustomNodeBuilder()
55     {
56         $builder = new TreeBuilder();
57         $root = $builder->root('builtin', 'array', new CustomNodeBuilder());
58
59         $definition = $root->children()->booleanNode('boolean');
60
61         $this->assertInstanceOf('Symfony\Component\Config\Definition\Builder\BooleanNodeDefinition', $definition);
62     }
63
64     public function testPrototypedArrayNodeUseTheCustomNodeBuilder()
65     {
66         $builder = new TreeBuilder();
67         $root = $builder->root('override', 'array', new CustomNodeBuilder());
68
69         $root->prototype('bar')->end();
70
71         $this->assertInstanceOf('Symfony\Component\Config\Tests\Fixtures\BarNode', $root->getNode(true)->getPrototype());
72     }
73
74     public function testAnExtendedNodeBuilderGetsPropagatedToTheChildren()
75     {
76         $builder = new TreeBuilder();
77
78         $builder->root('propagation')
79             ->children()
80                 ->setNodeClass('extended', 'Symfony\Component\Config\Definition\Builder\BooleanNodeDefinition')
81                 ->node('foo', 'extended')->end()
82                 ->arrayNode('child')
83                     ->children()
84                         ->node('foo', 'extended')
85                     ->end()
86                 ->end()
87             ->end()
88         ->end();
89
90         $node = $builder->buildTree();
91         $children = $node->getChildren();
92
93         $this->assertInstanceOf('Symfony\Component\Config\Definition\BooleanNode', $children['foo']);
94
95         $childChildren = $children['child']->getChildren();
96
97         $this->assertInstanceOf('Symfony\Component\Config\Definition\BooleanNode', $childChildren['foo']);
98     }
99
100     public function testDefinitionInfoGetsTransferredToNode()
101     {
102         $builder = new TreeBuilder();
103
104         $builder->root('test')->info('root info')
105             ->children()
106                 ->node('child', 'variable')->info('child info')->defaultValue('default')
107             ->end()
108         ->end();
109
110         $tree = $builder->buildTree();
111         $children = $tree->getChildren();
112
113         $this->assertEquals('root info', $tree->getInfo());
114         $this->assertEquals('child info', $children['child']->getInfo());
115     }
116
117     public function testDefinitionExampleGetsTransferredToNode()
118     {
119         $builder = new TreeBuilder();
120
121         $builder->root('test')
122             ->example(array('key' => 'value'))
123             ->children()
124                 ->node('child', 'variable')->info('child info')->defaultValue('default')->example('example')
125             ->end()
126         ->end();
127
128         $tree = $builder->buildTree();
129         $children = $tree->getChildren();
130
131         $this->assertInternalType('array', $tree->getExample());
132         $this->assertEquals('example', $children['child']->getExample());
133     }
134 }