X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrush%2Fdrush%2Fisolation%2Ftests%2FConfigLocatorTest.php;fp=vendor%2Fdrush%2Fdrush%2Fisolation%2Ftests%2FConfigLocatorTest.php;h=ddf092e80372cd16c383194f3f2326b7012012bf;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/drush/drush/isolation/tests/ConfigLocatorTest.php b/vendor/drush/drush/isolation/tests/ConfigLocatorTest.php new file mode 100644 index 000000000..ddf092e80 --- /dev/null +++ b/vendor/drush/drush/isolation/tests/ConfigLocatorTest.php @@ -0,0 +1,107 @@ +addEnvironment($this->environment()); + $config = $configLocator->config(); + $this->assertEquals($this->homeDir(), $config->get('env.cwd')); + } + + /** + * Test a comprehensive load of all default fixture data. + */ + function testLoadAll() + { + $configLocator = $this->createConfigLocator(); + + $sources = $configLocator->sources(); + //$this->assertEquals('environment', $sources['env']['cwd']); + $this->assertEquals($this->fixturesDir() . '/etc/drush/drush.yml', $sources['test']['system']); + $this->assertEquals($this->fixturesDir() . '/etc/drush/drushVARIANT.yml', $sources['test']['variant']); + $this->assertEquals($this->fixturesDir() . '/home/.drush/drush.yml', $sources['test']['home']); + $this->assertEquals($this->fixturesDir() . '/sites/d8/drush/drush.yml', $sources['test']['site']); + $this->assertEquals($this->environment()->drushBasePath() . '/drush.yml', $sources['drush']['php']['minimum-version']); + + $config = $configLocator->config(); + + $this->assertEquals($this->homeDir(), $config->get('env.cwd')); + $this->assertEquals('A system-wide setting', $config->get('test.system')); + $this->assertEquals('A user-specific setting', $config->get('test.home')); + $this->assertEquals('A site-specific setting', $config->get('test.site')); + $this->assertTrue($config->has('drush.php.minimum-version')); + } + + /** + * Test loading default fixture data in 'local' mode. This prevents Drush + * from loading any configuration file in any "global" location. In this + * context, "global" means anything that is not site-local, including the + * configuration file in the user's home directory, etc. + */ + function testLocalMode() + { + $configLocator = $this->createConfigLocator(true); + + /* + $sources = $configLocator->sources(); + //$this->assertEquals('environment', $sources['env']['cwd']); + $this->assertArrayNotHasKey('system', $sources['test']); + $this->assertArrayNotHasKey('home', $sources['test']); + $this->assertEquals($this->siteDir() . '/drush/drush.yml', $sources['test']['site']); + */ + + $config = $configLocator->config(); + $this->assertEquals($this->homeDir(), $config->get('env.cwd')); + $this->assertFalse($config->has('test.system')); + $this->assertFalse($config->has('test.home')); + $this->assertEquals('A site-specific setting', $config->get('test.site')); + } + + function testAliasPaths() + { + $configLocator = $this->createConfigLocator(); + $aliasPaths = $configLocator->getSiteAliasPaths(['/home/user/aliases'], $this->environment()); + $aliasPaths = array_map( + function ($item) { + return str_replace(dirname(__DIR__) . '/', '', $item); + }, + $aliasPaths + ); + sort($aliasPaths); + + $expected = '/home/user/aliases,fixtures/sites/d8/drush/sites'; + $this->assertEquals($expected, implode(',', $aliasPaths)); + } + + /** + * Create a config locator from All The Sources, for use in multiple tests. + */ + protected function createConfigLocator($isLocal = false, $configPath = '') + { + $configLocator = new ConfigLocator('TEST_', 'VARIANT'); + $configLocator->collectSources(); + $configLocator->setLocal($isLocal); + $configLocator->addUserConfig([$configPath], $this->environment()->systemConfigPath(), $this->environment()->userConfigPath()); + $configLocator->addDrushConfig($this->environment()->drushBasePath()); + + // Make our environment settings available as configuration items + $configLocator->addEnvironment($this->environment()); + + $configLocator->addSitewideConfig($this->siteDir()); + + return $configLocator; + } +}