forked from drush-ops/drush
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshellAliasTest.php
186 lines (170 loc) · 6.25 KB
/
shellAliasTest.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
namespace Unish;
/**
* Tests for Shell aliases.
*
* @group base
*/
class shellAliasesCase extends CommandUnishTestCase {
/**
* Write a config file that contains the shell-aliases array.
*/
function setUp() {
parent::setUp();
$contents = "
<?php
\$options['shell-aliases'] = array(
'glopts' => 'topic core-global-options',
'pull' => '!git pull',
'echosimple' => '!echo {{@target}}',
'echotest' => '!echo {{@target}} {{%root}} {{%mypath}}',
'compound-command' => '!cd {{%sandbox}} && echo second',
);
";
file_put_contents(UNISH_SANDBOX . '/drushrc.php', trim($contents));
if (!file_exists(UNISH_SANDBOX . '/b')) {
mkdir(UNISH_SANDBOX . '/b');
}
$contents = "
<?php
\$options['shell-aliases'] = array(
'also' => '!echo alternate config file included too',
);
";
file_put_contents(UNISH_SANDBOX . '/b/drushrc.php', trim($contents));
$aliases['myalias'] = array(
'root' => '/path/to/drupal',
'uri' => 'mysite.org',
'#peer' => '@live',
'path-aliases' => array (
'%mypath' => '/srv/data/mypath',
'%sandbox' => UNISH_SANDBOX,
),
);
$contents = $this->unish_file_aliases($aliases);
file_put_contents(UNISH_SANDBOX . '/aliases.drushrc.php', $contents);
}
/**
* Test shell aliases to Drush commands.
*/
public function testShellAliasDrushLocal() {
$options = array(
'config' => UNISH_SANDBOX,
);
$this->drush('glopts', array(), $options);
$output = $this->getOutput();
$this->assertContains('These options are applicable to most drush commands.', $output, 'Successfully executed local shell alias to drush command');
}
/**
* Test shell aliases to Bash commands. Assure we pass along extra arguments
* and options.
*/
public function testShellAliasBashLocal() {
$options = array(
'config' => UNISH_SANDBOX,
'simulate' => NULL,
'rebase' => NULL,
);
$this->drush('pull', array('origin'), $options, NULL, NULL, self::EXIT_SUCCESS, '2>&1');
$output = $this->getOutput();
$this->assertContains('Calling proc_open(git pull origin --rebase);', $output);
}
public function testShellAliasDrushRemote() {
$options = array(
'config' => UNISH_SANDBOX,
'simulate' => NULL,
'ssh-options' => '',
);
$this->drush('glopts', array(), $options, 'user@server/path/to/drupal#sitename');
// $expected might be different on non unix platforms. We shall see.
// n.b. --config is not included in calls to remote systems.
$bash = $this->escapeshellarg('drush --config=drush-sandbox --nocolor --uri=sitename --root=/path/to/drupal core-topic core-global-options 2>&1');
$expected = "Simulating backend invoke: ssh -t user@server $bash 2>&1";
$output = $this->getOutput();
// Remove any coverage arguments. The filename changes, so it's not possible
// to create a string for assertEquals, and the need for both shell escaping
// and regexp escaping different parts of the expected output for
// assertRegexp makes it easier just to remove the argument before checking
// the output.
$output = preg_replace('{--drush-coverage=[^ ]+ }', '', $output);
$output = preg_replace('{--config=[^ ]+ +}', '--config=drush-sandbox ', $output);
$this->assertEquals($expected, $output, 'Expected remote shell alias to a drush command was built');
}
public function testShellAliasBashRemote() {
$options = array(
'config' => UNISH_SANDBOX,
'simulate' => NULL,
'ssh-options' => '',
'rebase' => NULL,
);
$this->drush('pull', array('origin'), $options, 'user@server/path/to/drupal#sitename', NULL, self::EXIT_SUCCESS, '2>&1');
// $expected might be different on non unix platforms. We shall see.
$expected = "Calling proc_open(ssh user@server 'cd /path/to/drupal && git pull origin --rebase');";
$output = $this->getOutput();
$this->assertEquals($expected, $output, 'Expected remote shell alias to a bash command was built');
}
/**
* Test shell aliases with simple replacements -- no alias.
*/
public function testShellAliasSimpleReplacement() {
$options = array(
'config' => UNISH_SANDBOX,
);
$this->drush('echosimple', array(), $options);
// Windows command shell actually prints quotes. See http://drupal.org/node/1452944.
$expected = $this->is_windows() ? '"@none"' : '@none';
$output = $this->getOutput();
$this->assertEquals($expected, $output);
}
/**
* Test shell aliases with complex replacements -- no alias.
*/
public function testShellAliasReplacementNoAlias() {
$options = array(
'config' => UNISH_SANDBOX,
);
// echo test has replacements that are not satisfied, so this is expected to return an error.
$this->drush('echotest', array(), $options, NULL, NULL, self::EXIT_ERROR);
}
/**
* Test shell aliases with replacements -- alias.
*/
public function testShellAliasReplacementWithAlias() {
$options = array(
'config' => UNISH_SANDBOX,
'alias-path' => UNISH_SANDBOX,
);
$this->drush('echotest', array(), $options, '@myalias');
// Windows command shell actually prints quotes. See http://drupal.org/node/1452944.
$expected = $this->is_windows() ? '"@myalias"' : '@myalias';
$expected .= ' /path/to/drupal /srv/data/mypath';
$output = $this->getOutput();
$this->assertEquals($expected, $output);
}
/**
* Test shell aliases with replacements and compound commands.
*/
public function testShellAliasCompoundCommands() {
$options = array(
'config' => UNISH_SANDBOX,
'alias-path' => UNISH_SANDBOX,
);
$this->drush('compound-command', array(), $options, '@myalias');
$expected = 'second';
$output = $this->getOutput();
$this->assertEquals($expected, $output);
}
/**
* Test shell aliases with multiple config files.
*/
public function testShellAliasMultipleConfigFiles() {
$options = array(
'config' => UNISH_SANDBOX . "/b" . PATH_SEPARATOR . UNISH_SANDBOX,
'alias-path' => UNISH_SANDBOX,
);
$this->drush('also', array(), $options);
$expected = "alternate config file included too";
$output = $this->getOutput();
$this->assertEquals($expected, $output);
}
}