Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / consolidation / config / tests / ConfigGroupTest.php
1 <?php
2 namespace Consolidation\Config\Util;
3
4 use Consolidation\Config\Config;
5
6 class ConfigGroupTest extends \PHPUnit_Framework_TestCase
7 {
8     protected $config;
9
10     protected function setUp()
11     {
12         $data = [
13             // Define some configuration settings for the options for
14             // the commands my:foo and my:bar.
15             'command' => [
16                 'my' => [
17                     // commands.my.options.* apply to all my:* commands.
18                     'options' => [
19                         'path' => '/etc/common',
20                         'priority' => 'normal',
21                     ],
22                     'foo' => [
23                         // commands.my.foo.options.* apply only to the my:foo command.
24                         'options' => [
25                             'name' => 'baz',
26                         ],
27                     ],
28                     'bar' => [
29                         // Similarly, commands.my.bar.options is for the my:bar command.
30                         'options' => [
31                             'priority' => 'high',
32                         ],
33                     ],
34                 ],
35             ],
36             // Define some configuration settings for the configuration
37             // of some task \My\Tasks\Operations\Frobulate.
38             'task' => [
39                 'Operations' => [
40                     // task.Operations.settings apply to all tasks in
41                     // any *.Tass.Operations namespace.
42                     'settings' => [
43                         'dir' => '/base/dir',
44                     ],
45                     'Frobulate' => [
46                         // task.Operations.Frobulate.settings applies only
47                         // the Frobulate task.
48                         'settings' => [
49                             'object' => 'fire truck',
50                         ],
51                     ],
52                 ],
53             ],
54         ];
55
56         $this->config = new Config($data);
57     }
58
59     public function testDotNotation()
60     {
61         // Test the test
62         $this->assertEquals('baz', $this->config->get('command.my.foo.options.name'));
63     }
64
65     public function testFallback()
66     {
67         $fooFallback = new ConfigFallback($this->config, 'my.foo', 'command.', '.options.');
68         $barFallback = new ConfigFallback($this->config, 'my.bar', 'command.', '.options.');
69
70         $this->assertEquals(null, $barFallback->get('name'));
71         $this->assertEquals('baz', $fooFallback->get('name'));
72         $this->assertEquals('high', $barFallback->get('priority'));
73
74         $this->assertEquals('normal', $fooFallback->get('priority'));
75         $this->assertEquals('/etc/common', $barFallback->get('path'));
76         $this->assertEquals('/etc/common', $fooFallback->get('path'));
77     }
78
79     public function testMerge()
80     {
81         $frobulateMerge = new ConfigMerge($this->config, 'Operations.Frobulate', 'task.');
82
83         $settings = $frobulateMerge->get('settings');
84         $this->assertEquals('fire truck', $settings['object']);
85         $this->assertEquals('/base/dir', $settings['dir']);
86         $keys = array_keys($settings);
87         sort($keys);
88         $this->assertEquals('dir,object', implode(',', $keys));
89     }
90 }
91