Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / drush / drush / tests / CoreTest.php
1 <?php
2
3 namespace Unish;
4
5 use Symfony\Component\Yaml\Yaml;
6 use Webmozart\PathUtil\Path;
7
8 /**
9  * Tests for core commands.
10  *
11  * @group commands
12  */
13 class CoreCase extends CommandUnishTestCase
14 {
15
16     public function setUp()
17     {
18         if (!$this->getSites()) {
19             $this->setUpDrupal(2, true);
20         }
21     }
22
23     public function testDrupalDirectory()
24     {
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);
30
31         $this->drush('drupal-directory', ['%modules']);
32         $output = $this->getOutput();
33         $this->assertEquals(Path::join($root, $sitewide . '/modules'), $output);
34
35         $this->drush('pm-enable', ['devel']);
36         $this->drush('theme-enable', ['empty_theme']);
37
38         $this->drush('drupal-directory', ['devel']);
39         $output = $this->getOutput();
40         $this->assertEquals(Path::join($root, '/modules/unish/devel'), $output);
41
42         $this->drush('drupal-directory', ['empty_theme']);
43         $output = $this->getOutput();
44         $this->assertEquals(Path::join($root, '/themes/unish/empty_theme'), $output);
45     }
46
47     public function testCoreRequirements()
48     {
49         $root = $this->webroot();
50         $options = [
51         'pipe' => null,
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
54         ];
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);
59
60         $this->drush('core-requirements', [], $options);
61         $loaded = $this->getOutputFromJSON();
62         // Pick a subset that are valid for D6/D7/D8.
63         $expected = [
64         // 'install_profile' => -1,
65         // 'node_access' => -1,
66         'php' => -1,
67         // 'php_extensions' => -1,
68         'php_memory_limit' => -1,
69         'php_register_globals' => -1,
70         'settings.php' => -1,
71         ];
72         foreach ($expected as $key => $value) {
73             if (isset($loaded->$key)) {
74                 $this->assertEquals($value, $loaded->$key->sid);
75             }
76         }
77     }
78
79     public function testSiteSelectionViaCwd()
80     {
81         $cwd = getcwd();
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.
87             chdir($conf_dir);
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);
94         }
95         chdir($cwd);
96     }
97
98     public function testOptionsUri()
99     {
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 = [
104         'options' => [
105         'uri' => $test_uri,
106         ],
107         ];
108         $options = [
109         'format' => 'json',
110         'uri' => 'OMIT', // A special value which causes --uri to not be specified.
111         ];
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);
117     }
118
119     public function testRecursiveConfigLoading()
120     {
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 = [
129           'drush' => [
130             'paths' => [
131               'config' => [
132                 $a_drush_config_file,
133               ],
134             ],
135           ],
136         ];
137         $a_drush_yml_options = [
138           'drush' => [
139             'paths' => [
140               'config' => [
141                 $b_drush_config_file,
142               ],
143             ],
144           ],
145         ];
146         $b_drush_yml_options = [
147           'drush' => [
148             'paths' => [
149               'config' => [
150                 $a_drush_config_file,
151               ],
152             ],
153           ],
154           'options' => [
155             'uri' => $test_uri,
156           ],
157         ];
158         $command_options = [
159           'format' => 'json',
160           'uri' => 'OMIT', // A special value which causes --uri to not be specified.
161         ];
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);
174     }
175 }