Ticket #5210 (closed enhancement: fixed)
Refactor plugin (de)activation code for unit testing
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 2.5 |
| Component: | General | Version: | |
| Severity: | normal | Keywords: | |
| Cc: |
Description
To perform unit tests involving plugin (de)activation, it is currently necessary to either duplicate or indirectly call the logic in wp-admin/plugins.php. The code additionally duplicates itself (there is separate logic for deactivating one and deactivating all plugins). The attached patch moves the activating, deactivating, and deactivating all out into separate functions, which should allow for easier testing.
It may or may not be appropriate to break out the plugin inclusion code in wp-settings.php into its own function. The inclusion action is performed by the original wp-admin/plugins.php code, as well as the refactored code, so it's not strictly necessary with the current setup for the plugin activation code to be called once the plugin has been activated. This patch makes the smaller change, and does not break out the wp-settings.php code.
Attachments
Change History
-
attachment
extract_plugin_activation_logic.diff
added
Moves the plugin (de)activation logic from wp-admin/plugins.php to wp-admins/includes/plugin.php
Done. I don't know what the convention is for "error codes"; I just made two up, so someone should probably check that.
I'm not sure what WordPress's stance on this is.. So someone please correct me if i'm wrong.
rather than setting a variable and returning it at the end, You should be simply returning the WP_Error object at that point in time.
With the current code, it'll create a retval with an error.. but it'll then continue to work on and follow the rest of the code regardless, Whereas before, it simply dies off at that point rather than completing.
-
attachment
extract_plugin_activation_logic.2.diff
added
Moves the plugin (de)activation logic from wp-admin/plugins.php to wp-admins/includes/plugin.php
You are correct, sir. In most circumstances, I try to avoid multiple returns, so that set of code was purely reflex (I make an exception for error handling, so the fix was easy in this case ;). I've updated the patch to match the control flow of the original code.

Instead if issuing wp_die() from the functions, return WP_Error and let the caller die. Other than that, looks good.