6 * Tests for core commands.
10 class coreCase extends CommandUnishTestCase {
13 if (!$this->getSites()) {
14 $this->setUpDrupal(1, TRUE);
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.
22 function testRsyncPercentFiles() {
23 $root = $this->webroot();
24 $site = key($this->getSites());
27 'uri' => key($this->getSites()),
29 'include-conf' => NULL,
30 'include-vcs' => NULL,
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);
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.
45 function testPercentFilesOptimization() {
46 $root = $this->webroot();
47 $site = key($this->getSites());
50 'uri' => key($this->getSites()),
52 'include-conf' => NULL,
53 'include-vcs' => NULL,
55 'strict' => 0, // invoke from script: do not verify options
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);
65 * Test standalone php-script scripts. Assure that script args and options work.
67 public function testStandaloneScript() {
68 if ($this->is_windows()) {
69 $this->markTestSkipped('Standalone scripts not currently available on Windows.');
72 $this->drush('version', array('drush_version'), array('pipe' => NULL));
73 $standard = $this->getOutput();
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]
81 drush_invoke("version", $arg);
83 $data = str_replace('[PATH-TO-DRUSH]', UNISH_DRUSH, $data);
84 $script = UNISH_SANDBOX . '/' . $filename;
85 file_put_contents($script, $data);
87 $this->execute("$script drush_version --pipe");
88 $standalone = $this->getOutput();
89 $this->assertEquals($standard, $standalone);
92 function testDrupalDirectory() {
93 $root = $this->webroot();
94 $sitewide = $this->drupalSitewideDirectory();
97 'uri' => key($this->getSites()),
101 'strict' => 0, // invoke from script: do not verify options
103 $this->drush('drupal-directory', array('%files'), $options);
104 $output = $this->getOutput();
105 $this->assertEquals($root . '/sites/dev/files', $output);
107 $this->drush('drupal-directory', array('%modules'), $options);
108 $output = $this->getOutput();
109 $this->assertEquals($root . $sitewide . '/modules', $output);
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);
115 $this->drush('drupal-directory', array('devel'), $options);
116 $output = $this->getOutput();
117 $this->assertEquals(realpath($root . $sitewide . '/modules/devel'), $output);
119 $this->drush('drupal-directory', array('empty_theme'), $options);
120 $output = $this->getOutput();
121 $this->assertEquals(realpath($root . $sitewide . '/themes/empty_theme'), $output);
124 function testCoreRequirements() {
125 $root = $this->webroot();
128 'uri' => key($this->getSites()),
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
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';
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);
143 $this->drush('core-requirements', array(), $options);
144 $loaded = $this->getOutputFromJSON();
145 // Pick a subset that are valid for D6/D7/D8.
147 // 'install_profile' => -1,
148 // 'node_access' => -1,
150 // 'php_extensions' => -1,
151 'php_memory_limit' => -1,
152 'php_register_globals' => -1,
153 'settings.php' => -1,
155 foreach ($expected as $key => $value) {
156 if (isset($loaded->$key)) {
157 $this->assertEquals($value, $loaded->$key->sid);