Yaffs site version 1.1
[yaffs-website] / vendor / drush / drush / tests / coreTest.php
1 <?php
2
3 namespace Unish;
4
5 /**
6  * Tests for core commands.
7  *
8  * @group commands
9  */
10 class coreCase extends CommandUnishTestCase {
11
12   function setUp() {
13     if (!$this->getSites()) {
14       $this->setUpDrupal(1, TRUE);
15     }
16   }
17
18   /**
19    * Test to see if rsync @site:%files calculates the %files path correctly.
20    * This tests the non-optimized code path in drush_sitealias_resolve_path_references.
21    */
22   function testRsyncPercentFiles() {
23     $root = $this->webroot();
24     $site = key($this->getSites());
25     $options = array(
26       'root' => $root,
27       'uri' => key($this->getSites()),
28       'simulate' => NULL,
29       'include-conf' => NULL,
30       'include-vcs' => NULL,
31       'yes' => NULL,
32     );
33     $this->drush('core-rsync', array("@$site:%files", "/tmp"), $options, NULL, NULL, self::EXIT_SUCCESS, '2>&1;');
34     $output = $this->getOutput();
35     $level = $this->log_level();
36     $pattern = in_array($level, array('verbose', 'debug')) ? "Calling system(rsync -e 'ssh ' -akzv --stats --progress --yes %s /tmp);" : "Calling system(rsync -e 'ssh ' -akz --yes %s /tmp);";
37     $expected = sprintf($pattern, UNISH_SANDBOX . "/web/sites/$site/files");
38     $this->assertEquals($expected, $output);
39   }
40
41   /**
42    * Test to see if the optimized code path in drush_sitealias_resolve_path_references
43    * that avoids a call to backend invoke when evaluating %files works.
44    */
45   function testPercentFilesOptimization() {
46     $root = $this->webroot();
47     $site = key($this->getSites());
48     $options = array(
49       'root' => $root,
50       'uri' => key($this->getSites()),
51       'simulate' => NULL,
52       'include-conf' => NULL,
53       'include-vcs' => NULL,
54       'yes' => NULL,
55       'strict' => 0, // invoke from script: do not verify options
56     );
57     $php = '$a=drush_sitealias_get_record("@' . $site . '"); drush_sitealias_resolve_path_references($a, "%files"); print_r($a["path-aliases"]["%files"]);';
58     $this->drush('ev', array($php), $options);
59     $output = $this->getOutput();
60     $expected = "sites/dev/files";
61     $this->assertEquals($expected, $output);
62   }
63
64   /**
65    * Test standalone php-script scripts. Assure that script args and options work.
66    */
67   public function testStandaloneScript() {
68     if ($this->is_windows()) {
69       $this->markTestSkipped('Standalone scripts not currently available on Windows.');
70     }
71
72     $this->drush('version', array('drush_version'), array('pipe' => NULL));
73     $standard = $this->getOutput();
74
75     // Write out a hellounish.script into the sandbox. The correct /path/to/drush
76     // is in the shebang line.
77     $filename = 'hellounish.script';
78     $data = '#!/usr/bin/env [PATH-TO-DRUSH]
79
80 $arg = drush_shift();
81 drush_invoke("version", $arg);
82 ';
83     $data = str_replace('[PATH-TO-DRUSH]', UNISH_DRUSH, $data);
84     $script = UNISH_SANDBOX . '/' . $filename;
85     file_put_contents($script, $data);
86     chmod($script, 0755);
87     $this->execute("$script drush_version --pipe");
88     $standalone = $this->getOutput();
89     $this->assertEquals($standard, $standalone);
90   }
91
92   function testDrupalDirectory() {
93     $root = $this->webroot();
94     $sitewide = $this->drupalSitewideDirectory();
95     $options = array(
96       'root' => $root,
97       'uri' => key($this->getSites()),
98       'yes' => NULL,
99       'skip' => NULL,
100       'cache' => NULL,
101       'strict' => 0, // invoke from script: do not verify options
102     );
103     $this->drush('drupal-directory', array('%files'), $options);
104     $output = $this->getOutput();
105     $this->assertEquals($root . '/sites/dev/files', $output);
106
107     $this->drush('drupal-directory', array('%modules'), $options);
108     $output = $this->getOutput();
109     $this->assertEquals($root . $sitewide . '/modules', $output);
110
111     $this->drush('pm-download', array('devel'), $options);
112     $this->drush('pm-enable', array('devel'), $options);
113     $this->drush('pm-download', array('empty_theme'), $options);
114
115     $this->drush('drupal-directory', array('devel'), $options);
116     $output = $this->getOutput();
117     $this->assertEquals(realpath($root  . $sitewide . '/modules/devel'), $output);
118
119     $this->drush('drupal-directory', array('empty_theme'), $options);
120     $output = $this->getOutput();
121     $this->assertEquals(realpath($root  . $sitewide . '/themes/empty_theme'), $output);
122   }
123
124   function testCoreRequirements() {
125     $root = $this->webroot();
126     $options = array(
127       'root' => $root,
128       'uri' => key($this->getSites()),
129       'pipe' => NULL,
130       'ignore' => 'cron,http requests,update,update_core,trusted_host_patterns', // no network access when running in tests, so ignore these
131       'strict' => 0, // invoke from script: do not verify options
132     );
133     // Drupal 6 has reached EOL, so we will always get errors for 'update_contrib';
134     // therefore, we ignore it for this release.
135     if (UNISH_DRUPAL_MAJOR_VERSION < 7) {
136       $options['ignore'] .= ',update_contrib';
137     }
138     // Verify that there are no severity 2 items in the status report
139     $this->drush('core-requirements', array(), $options + array('severity' => '2'));
140     $output = $this->getOutput();
141     $this->assertEquals('', $output);
142
143     $this->drush('core-requirements', array(), $options);
144     $loaded = $this->getOutputFromJSON();
145     // Pick a subset that are valid for D6/D7/D8.
146     $expected = array(
147       // 'install_profile' => -1,
148       // 'node_access' => -1,
149       'php' => -1,
150       // 'php_extensions' => -1,
151       'php_memory_limit' => -1,
152       'php_register_globals' => -1,
153       'settings.php' => -1,
154     );
155     foreach ($expected as $key => $value) {
156       if (isset($loaded->$key)) {
157         $this->assertEquals($value, $loaded->$key->sid);
158       }
159     }
160   }
161 }