forked from wp-cli/wp-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflags.feature
More file actions
297 lines (253 loc) · 7.16 KB
/
Copy pathflags.feature
File metadata and controls
297 lines (253 loc) · 7.16 KB
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
Feature: Global flags
Scenario: Setting the URL
Given a WP installation
When I run `wp --url=localhost:8001 eval 'echo json_encode( $_SERVER );'`
Then STDOUT should be JSON containing:
"""
{
"HTTP_HOST": "localhost:8001",
"SERVER_NAME": "localhost",
"SERVER_PORT": "8001"
}
"""
Scenario: Setting the URL on multisite
Given a WP multisite installation
And I run `wp site create --slug=foo`
When I run `wp --url=example.com/foo option get home`
Then STDOUT should be:
"""
http://example.com/foo
"""
@require-wp-3.9
Scenario: Invalid URL
Given a WP multisite installation
When I try `wp post list --url=invalid.example.com`
Then STDERR should be:
"""
Error: Site 'invalid.example.com' not found. Verify `--url=<url>` matches an existing site.
"""
Scenario: Quiet run
Given a WP installation
When I try `wp non-existing-command --quiet`
Then the return code should be 1
And STDERR should be:
"""
Error: 'non-existing-command' is not a registered wp command. See 'wp help' for available commands.
"""
Scenario: Debug run
Given a WP installation
When I try `wp eval 'echo CONST_WITHOUT_QUOTES;'`
Then STDOUT should be:
"""
CONST_WITHOUT_QUOTES
"""
And STDERR should contain:
"""
Use of undefined constant CONST_WITHOUT_QUOTES
"""
And the return code should be 0
When I try `wp eval 'echo CONST_WITHOUT_QUOTES;' --debug`
Then the return code should be 0
And STDOUT should be:
"""
CONST_WITHOUT_QUOTES
"""
And STDERR should contain:
"""
Use of undefined constant CONST_WITHOUT_QUOTES
"""
Scenario: Setting the WP user
Given a WP installation
When I run `wp eval 'echo (int) is_user_logged_in();'`
Then STDOUT should be:
"""
0
"""
When I run `wp --user=admin eval 'echo wp_get_current_user()->user_login;'`
Then STDOUT should be:
"""
admin
"""
When I run `wp [email protected] eval 'echo wp_get_current_user()->user_login;'`
Then STDOUT should be:
"""
admin
"""
When I try `wp --user=non-existing-user eval 'echo wp_get_current_user()->user_login;'`
Then the return code should be 1
And STDERR should be:
"""
Error: Invalid user ID, email or login: 'non-existing-user'
"""
Scenario: Using a custom logger
Given an empty directory
And a custom-logger.php file:
"""
<?php
class Dummy_Logger {
function __call( $method, $args ) {
echo "log: called '$method' method";
}
}
WP_CLI::set_logger( new Dummy_Logger );
"""
When I try `wp --require=custom-logger.php is-installed`
Then STDOUT should contain:
"""
log: called 'error' method
"""
And STDERR should be empty
And the return code should be 1
Scenario: Using --require
Given an empty directory
And a custom-cmd.php file:
"""
<?php
/**
* @when before_wp_load
*/
class Test_Command extends WP_CLI_Command {
function req( $args, $assoc_args ) {
WP_CLI::line( $args[0] );
}
}
WP_CLI::add_command( 'test', 'Test_Command' );
"""
And a foo.php file:
"""
<?php echo basename(__FILE__) . "\n";
"""
And a bar.php file:
"""
<?php echo basename(__FILE__) . "\n";
"""
And a wp-cli.yml file:
"""
require:
- foo.php
- bar.php
"""
And a wp-cli2.yml file:
"""
require: custom-cmd.php
"""
When I run `wp --require=custom-cmd.php test req 'This is a custom command.'`
Then STDOUT should be:
"""
foo.php
bar.php
This is a custom command.
"""
When I run `WP_CLI_CONFIG_PATH=wp-cli2.yml wp test req 'This is a custom command.'`
Then STDOUT should contain:
"""
This is a custom command.
"""
Scenario: Using --require with globs
Given an empty directory
And a foober/foo.php file:
"""
<?php echo basename(__FILE__) . "\n";
"""
And a foober/bar.php file:
"""
<?php echo basename(__FILE__) . "\n";
"""
And a doobie/doo.php file:
"""
<?php echo basename(__FILE__) . "\n";
"""
And a wp-cli.yml file:
"""
require: foober/*.php
"""
When I run `wp`
Then STDOUT should contain:
"""
bar.php
foo.php
"""
When I run `wp --require=doobie/*.php`
Then STDOUT should contain:
"""
doo.php
"""
Scenario: Enabling/disabling color
Given a WP installation
When I try `wp --no-color non-existent-command`
Then STDERR should be:
"""
Error: 'non-existent-command' is not a registered wp command. See 'wp help' for available commands.
"""
When I try `wp --color non-existent-command`
Then STDERR should contain:
"""
[31;1mError:
"""
Scenario: Use `WP_CLI_STRICT_ARGS_MODE` to distinguish between global and local args
Given an empty directory
And a cmd.php file:
"""
<?php
/**
* @when before_wp_load
*
* [--url=<url>]
* : URL passed to the callback.
*/
$cmd_test = function( $args, $assoc_args ) {
$url = WP_CLI::get_runner()->config['url'] ? ' ' . WP_CLI::get_runner()->config['url'] : '';
WP_CLI::log( 'global:' . $url );
$url = isset( $assoc_args['url'] ) ? ' ' . $assoc_args['url'] : '';
WP_CLI::log( 'local:' . $url );
};
WP_CLI::add_command( 'cmd-test', $cmd_test );
"""
And a wp-cli.yml file:
"""
require:
- cmd.php
"""
When I run `wp cmd-test --url=foo.dev`
Then STDOUT should be:
"""
global: foo.dev
local:
"""
When I run `WP_CLI_STRICT_ARGS_MODE=1 wp cmd-test --url=foo.dev`
Then STDOUT should be:
"""
global:
local: foo.dev
"""
When I run `WP_CLI_STRICT_ARGS_MODE=1 wp --url=bar.dev cmd-test --url=foo.dev`
Then STDOUT should be:
"""
global: bar.dev
local: foo.dev
"""
Scenario: Using --http=<url> requires wp-cli/restful
Given an empty directory
When I try `wp --http=foo.dev`
Then STDERR should be:
"""
Error: RESTful WP-CLI needs to be installed. Try 'wp package install wp-cli/restful'.
"""
Scenario: Strict args mode should be passed on to ssh
When I try `WP_CLI_STRICT_ARGS_MODE=1 wp --debug --ssh=/ --version`
Then STDERR should contain:
"""
Running SSH command: ssh -q '' -T 'WP_CLI_STRICT_ARGS_MODE=1 wp
"""
Scenario: SSH flag should support changing directories
When I try `wp --debug --ssh=wordpress:/my/path --version`
Then STDERR should contain:
"""
Running SSH command: ssh -q 'wordpress' -T 'cd '\''/my/path'\''; wp
"""
Scenario: SSH flag should support Docker
When I try `wp --debug --ssh=docker:user@wordpress --version`
Then STDERR should contain:
"""
Running SSH command: docker exec --user 'user' 'wordpress' sh -c
"""