Skip to content

Commit 22f703d

Browse files
Copilotswissspidy
andcommitted
Add tests for --force flag with plugin activate and install
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 62abd24 commit 22f703d

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

features/plugin-activate.feature

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,47 @@ Feature: Activate WordPress plugins
177177
Debug (plugin): Unexpected output: Unexpected output from plugin activation
178178
"""
179179
And the return code should be 1
180+
181+
Scenario: Force activate an already active plugin to re-run activation hooks
182+
Given a wp-content/plugins/force-test.php file:
183+
"""
184+
<?php
185+
/**
186+
* Plugin Name: Force Test Plugin
187+
* Description: Test plugin for force activation
188+
* Author: WP-CLI tests
189+
*/
190+
191+
register_activation_hook( __FILE__, function() {
192+
file_put_contents( WP_CONTENT_DIR . '/activation-test.txt', 'Activation hook was run' );
193+
});
194+
"""
195+
196+
When I run `wp plugin activate force-test`
197+
Then STDOUT should contain:
198+
"""
199+
Plugin 'force-test' activated.
200+
"""
201+
And the return code should be 0
202+
And the wp-content/activation-test.txt file should exist
203+
204+
# Remove the file to test if it gets recreated with --force
205+
When I run `rm wp-content/activation-test.txt`
206+
207+
# Try activating without --force (should skip)
208+
When I try `wp plugin activate force-test`
209+
Then STDERR should be:
210+
"""
211+
Warning: Plugin 'force-test' is already active.
212+
Error: No plugins activated.
213+
"""
214+
And the wp-content/activation-test.txt file should not exist
215+
216+
# Now try with --force (should re-run activation hooks)
217+
When I run `wp plugin activate force-test --force`
218+
Then STDOUT should contain:
219+
"""
220+
Plugin 'force-test' activated.
221+
"""
222+
And the return code should be 0
223+
And the wp-content/activation-test.txt file should exist

features/plugin-install.feature

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,59 @@ Feature: Install WordPress plugins
305305
"""
306306
active
307307
"""
308+
309+
Scenario: Force reinstall and activate an already active plugin to re-run activation hooks
310+
Given a WP install
311+
And a wp-content/plugins/install-force-test.php file:
312+
"""
313+
<?php
314+
/**
315+
* Plugin Name: Install Force Test
316+
* Description: Test plugin for force install and activate
317+
* Version: 1.0.0
318+
* Author: WP-CLI tests
319+
*/
320+
321+
register_activation_hook( __FILE__, function() {
322+
file_put_contents( WP_CONTENT_DIR . '/install-activation-test.txt', 'Activation hook was run' );
323+
});
324+
"""
325+
326+
When I run `wp plugin activate install-force-test`
327+
Then STDOUT should contain:
328+
"""
329+
Plugin 'install-force-test' activated.
330+
"""
331+
And the wp-content/install-activation-test.txt file should exist
332+
333+
# Remove the file to test if it gets recreated with --force
334+
When I run `rm wp-content/install-activation-test.txt`
335+
336+
# Try install --activate without --force (should skip activation hooks)
337+
When I run `wp plugin install install-force-test --activate`
338+
Then STDOUT should contain:
339+
"""
340+
Plugin already installed.
341+
"""
342+
And STDOUT should contain:
343+
"""
344+
Activating 'install-force-test'...
345+
"""
346+
And STDERR should contain:
347+
"""
348+
Warning: Plugin 'install-force-test' is already active.
349+
"""
350+
And the wp-content/install-activation-test.txt file should not exist
351+
352+
# Now try install --activate --force (should re-run activation hooks)
353+
When I run `wp plugin install install-force-test --activate --force`
354+
Then STDOUT should contain:
355+
"""
356+
Activating 'install-force-test'...
357+
"""
358+
And STDOUT should contain:
359+
"""
360+
Plugin 'install-force-test' activated.
361+
"""
362+
And the return code should be 0
363+
And the wp-content/install-activation-test.txt file should exist

0 commit comments

Comments
 (0)