Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / vendor / drush / drush / isolation / tests / ConfigLocatorTest.php
1 <?php
2 namespace Drush\Config;
3
4 use PHPUnit\Framework\TestCase;
5
6 /**
7  * Test the config loader. Also exercises the EnvironmentConfigLoader.
8  */
9 class ConfigLocatorTest extends TestCase
10 {
11     use \Drush\FixtureFactory;
12
13     /**
14      * Test a config locator initialized only with data from the fixture's environment
15      */
16     function testOnlyEnvironmentData()
17     {
18         $configLocator = new ConfigLocator('TEST_');
19         $configLocator->addEnvironment($this->environment());
20         $config = $configLocator->config();
21         $this->assertEquals($this->homeDir(), $config->get('env.cwd'));
22     }
23
24     /**
25      * Test a comprehensive load of all default fixture data.
26      */
27     function testLoadAll()
28     {
29         $configLocator = $this->createConfigLocator();
30
31         $sources = $configLocator->sources();
32         //$this->assertEquals('environment', $sources['env']['cwd']);
33         $this->assertEquals($this->fixturesDir() . '/etc/drush/drush.yml', $sources['test']['system']);
34         $this->assertEquals($this->fixturesDir() . '/etc/drush/drushVARIANT.yml', $sources['test']['variant']);
35         $this->assertEquals($this->fixturesDir() . '/home/.drush/drush.yml', $sources['test']['home']);
36         $this->assertEquals($this->fixturesDir() . '/sites/d8/drush/drush.yml', $sources['test']['site']);
37         $this->assertEquals($this->environment()->drushBasePath() . '/drush.yml', $sources['drush']['php']['minimum-version']);
38
39         $config = $configLocator->config();
40
41         $this->assertEquals($this->homeDir(), $config->get('env.cwd'));
42         $this->assertEquals('A system-wide setting', $config->get('test.system'));
43         $this->assertEquals('A user-specific setting', $config->get('test.home'));
44         $this->assertEquals('A site-specific setting', $config->get('test.site'));
45         $this->assertTrue($config->has('drush.php.minimum-version'));
46     }
47
48     /**
49      * Test loading default fixture data in 'local' mode. This prevents Drush
50      * from loading any configuration file in any "global" location. In this
51      * context, "global" means anything that is not site-local, including the
52      * configuration file in the user's home directory, etc.
53      */
54     function testLocalMode()
55     {
56         $configLocator = $this->createConfigLocator(true);
57
58         /*
59         $sources = $configLocator->sources();
60         //$this->assertEquals('environment', $sources['env']['cwd']);
61         $this->assertArrayNotHasKey('system', $sources['test']);
62         $this->assertArrayNotHasKey('home', $sources['test']);
63         $this->assertEquals($this->siteDir() . '/drush/drush.yml', $sources['test']['site']);
64         */
65
66         $config = $configLocator->config();
67         $this->assertEquals($this->homeDir(), $config->get('env.cwd'));
68         $this->assertFalse($config->has('test.system'));
69         $this->assertFalse($config->has('test.home'));
70         $this->assertEquals('A site-specific setting', $config->get('test.site'));
71     }
72
73     function testAliasPaths()
74     {
75         $configLocator = $this->createConfigLocator();
76         $aliasPaths = $configLocator->getSiteAliasPaths(['/home/user/aliases'], $this->environment());
77         $aliasPaths = array_map(
78             function ($item) {
79                 return str_replace(dirname(__DIR__) . '/', '', $item);
80             },
81             $aliasPaths
82         );
83         sort($aliasPaths);
84
85         $expected = '/home/user/aliases,fixtures/sites/d8/drush/sites';
86         $this->assertEquals($expected, implode(',', $aliasPaths));
87     }
88
89     /**
90      * Create a config locator from All The Sources, for use in multiple tests.
91      */
92     protected function createConfigLocator($isLocal = false, $configPath = '')
93     {
94         $configLocator = new ConfigLocator('TEST_', 'VARIANT');
95         $configLocator->collectSources();
96         $configLocator->setLocal($isLocal);
97         $configLocator->addUserConfig([$configPath], $this->environment()->systemConfigPath(), $this->environment()->userConfigPath());
98         $configLocator->addDrushConfig($this->environment()->drushBasePath());
99
100         // Make our environment settings available as configuration items
101         $configLocator->addEnvironment($this->environment());
102
103         $configLocator->addSitewideConfig($this->siteDir());
104
105         return $configLocator;
106     }
107 }