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