5 use Symfony\Component\Yaml\Yaml;
6 use Webmozart\PathUtil\Path;
9 * Tests for core commands.
13 class CoreCase extends CommandUnishTestCase
16 public function setUp()
18 if (!$this->getSites()) {
19 $this->setUpDrupal(2, true);
23 public function testDrupalDirectory()
25 $root = $this->webroot();
26 $sitewide = $this->drupalSitewideDirectory();
27 $this->drush('drupal-directory', ['%files']);
28 $output = $this->getOutput();
29 $this->assertEquals(Path::join($root, '/sites/dev/files'), $output);
31 $this->drush('drupal-directory', ['%modules']);
32 $output = $this->getOutput();
33 $this->assertEquals(Path::join($root, $sitewide . '/modules'), $output);
35 $this->drush('pm-enable', ['devel']);
36 $this->drush('theme-enable', ['empty_theme']);
38 $this->drush('drupal-directory', ['devel']);
39 $output = $this->getOutput();
40 $this->assertEquals(Path::join($root, '/modules/unish/devel'), $output);
42 $this->drush('drupal-directory', ['empty_theme']);
43 $output = $this->getOutput();
44 $this->assertEquals(Path::join($root, '/themes/unish/empty_theme'), $output);
47 public function testCoreRequirements()
49 $root = $this->webroot();
52 'ignore' => 'cron,http requests,update,update_core,trusted_host_patterns', // no network access when running in tests, so ignore these
53 // 'strict' => 0, // invoke from script: do not verify options
55 // Verify that there are no severity 2 items in the status report
56 $this->drush('core-requirements', [], $options + ['severity' => '2']);
57 $output = $this->getOutput();
58 $this->assertEquals('', $output);
60 $this->drush('core-requirements', [], $options);
61 $loaded = $this->getOutputFromJSON();
62 // Pick a subset that are valid for D6/D7/D8.
64 // 'install_profile' => -1,
65 // 'node_access' => -1,
67 // 'php_extensions' => -1,
68 'php_memory_limit' => -1,
69 'php_register_globals' => -1,
72 foreach ($expected as $key => $value) {
73 if (isset($loaded->$key)) {
74 $this->assertEquals($value, $loaded->$key->sid);
79 public function testSiteSelectionViaCwd()
82 $root = $this->webroot();
83 foreach (['dev', 'stage'] as $uri) {
84 $conf_dir = $root . '/sites/' . $uri;
85 // We will chdir to the directory that contains settings.php
86 // and ensure that we can bootstrap the selected site from here.
88 $options['uri'] = 'OMIT'; // A special value which causes --uri to not be specified.
89 $this->drush('core-status', [], $options);
90 $output = $this->getOutput();
91 $output = preg_replace('# *#', ' ', $output);
92 $this->assertContains('Database : Connected', $output);
93 $this->assertContains("Site path : sites/$uri", $output);
98 public function testOptionsUri()
100 // Put a yml file in the drush folder.
101 $drush_config_file = Path::join($this->getSut(), 'drush', 'drush.yml');
102 $test_uri = 'http://test.uri';
103 $options_with_uri = [
110 'uri' => 'OMIT', // A special value which causes --uri to not be specified.
112 file_put_contents($drush_config_file, Yaml::dump($options_with_uri, PHP_INT_MAX, 2));
113 $this->drush('core-status', [], $options);
114 unlink($drush_config_file);
115 $output = $this->getOutputFromJSON();
116 $this->assertEquals($test_uri, $output->uri);
119 public function testRecursiveConfigLoading()
121 // Put a yml file in the drush folder.
122 $drush_config_file = Path::join($this->getSut(), 'drush', 'drush.yml');
123 $a_drush_config_file = Path::join($this->getSut(), 'drush', 'a.drush.yml');
124 $b_drush_config_file = Path::join($this->getSut(), 'drush', 'b.drush.yml');
125 $test_uri = 'http://test.uri';
126 // Set up multiple drush.yml files that include one another to test
127 // potential infinite loop.
128 $drush_yml_options = [
132 $a_drush_config_file,
137 $a_drush_yml_options = [
141 $b_drush_config_file,
146 $b_drush_yml_options = [
150 $a_drush_config_file,
160 'uri' => 'OMIT', // A special value which causes --uri to not be specified.
162 file_put_contents($drush_config_file, Yaml::dump($drush_yml_options, PHP_INT_MAX, 2));
163 file_put_contents($a_drush_config_file, Yaml::dump($a_drush_yml_options, PHP_INT_MAX, 2));
164 file_put_contents($b_drush_config_file, Yaml::dump($b_drush_yml_options, PHP_INT_MAX, 2));
165 $this->drush('core-status', [], $command_options, null, $this->getSut());
166 unlink($drush_config_file);
167 unlink($a_drush_config_file);
168 unlink($b_drush_config_file);
169 $output = $this->getOutputFromJSON();
170 $drush_conf_as_string = print_r($output->{'drush-conf'}, true);
171 $this->assertContains($a_drush_config_file, $output->{'drush-conf'}, "Loaded drush config files are: " . $drush_conf_as_string);
172 $this->assertContains($b_drush_config_file, $output->{'drush-conf'}, "Loaded drush config files are: " . $drush_conf_as_string);
173 $this->assertEquals($test_uri, $output->uri);