-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathplugin-activate.feature
More file actions
227 lines (202 loc) · 6.91 KB
/
plugin-activate.feature
File metadata and controls
227 lines (202 loc) · 6.91 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
Feature: Activate WordPress plugins
Background:
Given a WP install
Scenario: Activate a plugin that's already installed
When I run `wp plugin activate akismet`
Then STDOUT should be:
"""
Plugin 'akismet' activated.
Success: Activated 1 of 1 plugins.
"""
And the return code should be 0
Scenario: Attempt to activate a plugin that's not installed
When I try `wp plugin activate debug-bar`
Then STDERR should be:
"""
Warning: The 'debug-bar' plugin could not be found.
Error: No plugins activated.
"""
And the return code should be 1
When I try `wp plugin activate akismet debug-bar`
Then STDERR should be:
"""
Warning: The 'debug-bar' plugin could not be found.
Error: Only activated 1 of 2 plugins.
"""
And STDOUT should be:
"""
Plugin 'akismet' activated.
"""
And the return code should be 1
Scenario: Activate all when one plugin is hidden by "all_plugins" filter
Given I run `wp plugin install site-secrets https://github.com/wp-cli/sample-plugin/archive/refs/heads/master.zip`
And a wp-content/mu-plugins/hide-us-plugin.php file:
"""
<?php
/**
* Plugin Name: Hide Site Secrets on Production
* Description: Hides the Site Secrets plugin on production sites
* Author: WP-CLI tests
*/
add_filter( 'all_plugins', function( $all_plugins ) {
unset( $all_plugins['site-secrets/site-secrets.php'] );
return $all_plugins;
} );
"""
When I run `wp plugin activate --all`
Then STDOUT should contain:
"""
Plugin 'akismet' activated.
"""
And STDOUT should contain:
"""
Plugin 'sample-plugin' activated.
"""
And STDOUT should not contain:
"""
Plugin 'site-secrets' activated.
"""
@require-php-7
Scenario: Activating a plugin with no network wide option passes down correct types
Given a wp-content/plugins/example-plugin.php file:
"""
<?php
// Plugin Name: Example Plugin
function example_plugin_activate( bool $network_wide = false ) {
// Doesn't matter what we do here, we just need a function definition to check the type
return;
}
register_activation_hook( __FILE__, 'example_plugin_activate' );
"""
When I run `wp plugin activate example-plugin`
Then STDOUT should be:
"""
Plugin 'example-plugin' activated.
Success: Activated 1 of 1 plugins.
"""
And STDERR should be empty
Scenario: Not giving a slug on activate should throw an error unless --all given
When I try `wp plugin activate`
Then the return code should be 1
And STDERR should be:
"""
Error: Please specify one or more plugins, or use --all.
"""
And STDOUT should be empty
# But don't give an error if no plugins and --all given for BC.
Given I run `wp plugin path`
And save STDOUT as {PLUGIN_DIR}
And an empty {PLUGIN_DIR} directory
When I run `wp plugin activate --all`
Then STDOUT should be:
"""
Success: No plugins activated.
"""
@require-wp-5.2
Scenario: Activating a plugin that does not meet PHP minimum throws a warning
Given a wp-content/plugins/high-requirements.php file:
"""
<?php
/**
* Plugin Name: High PHP Requirements
* Description: This is meant to not activate because PHP version is too low.
* Author: WP-CLI tests
* Requires PHP: 99.99
*/
"""
And I run `wp plugin deactivate --all`
And I run `wp cli info | grep "PHP version" | awk '{print $3}'`
And save STDOUT as {PHP_VERSION}
When I try `wp plugin activate high-requirements`
Then STDERR should contain:
"""
Failed to activate plugin. Current PHP version ({PHP_VERSION}) does not meet minimum requirements for High PHP Requirements. The plugin requires PHP 99.99.
"""
And STDOUT should not contain:
"""
1 out of 1
"""
And STDOUT should not contain:
"""
Success:
"""
Scenario: Adding --exclude with plugin activate --all should exclude the plugins specified via --exclude
When I try `wp plugin activate --all --exclude=hello,hello-dolly`
Then STDOUT should be:
"""
Plugin 'akismet' activated.
Success: Activated 1 of 1 plugins.
"""
And the return code should be 0
Scenario: Excluding a missing plugin should not throw an error
Given a WP install
And I run `wp plugin activate --all --exclude=missing-plugin`
Then STDERR should be empty
And STDOUT should contain:
"""
Success:
"""
And the return code should be 0
Scenario: Activating a plugin that generates unexpected output shows the output in debug mode
Given a wp-content/plugins/output-plugin.php file:
"""
<?php
/**
* Plugin Name: Output Plugin
* Description: This plugin generates unexpected output during activation
* Author: WP-CLI tests
*/
echo "Unexpected output from plugin activation";
"""
When I try `wp plugin activate output-plugin --debug`
Then STDERR should contain:
"""
Warning: Failed to activate plugin. The plugin generated unexpected output.
"""
And STDERR should contain:
"""
Debug (plugin): Unexpected output: Unexpected output from plugin activation
"""
And the return code should be 1
Scenario: Force activate an already active plugin to re-run activation hooks
Given a wp-content/plugins/force-test.php file:
"""
<?php
/**
* Plugin Name: Force Test Plugin
* Description: Test plugin for force activation
* Author: WP-CLI tests
*/
register_activation_hook( __FILE__, function() {
@file_put_contents( WP_CONTENT_DIR . '/activation-test.txt', 'Activation hook was run' );
});
"""
When I run `wp plugin activate force-test`
Then STDOUT should contain:
"""
Plugin 'force-test' activated.
"""
And the return code should be 0
And the wp-content/activation-test.txt file should exist
# Remove the file to test if it gets recreated with --force
When I run `rm wp-content/activation-test.txt`
# Try activating without --force (should skip)
And I try `wp plugin activate force-test`
Then STDERR should contain:
"""
Warning: Plugin 'force-test' is already active.
"""
And STDOUT should be:
"""
Success: Plugin already activated.
"""
And the return code should be 0
And the wp-content/activation-test.txt file should not exist
# Now try with --force (should re-run activation hooks)
When I run `wp plugin activate force-test --force`
Then STDOUT should contain:
"""
Plugin 'force-test' activated.
"""
And the return code should be 0
And the wp-content/activation-test.txt file should exist