WordPress.org

Make WordPress Core

Opened 13 years ago

Closed 13 years ago

#5210 closed enhancement (fixed)

Refactor plugin (de)activation code for unit testing

Reported by: Quandary Owned by:
Milestone: 2.5 Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: 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 (2)

extract_plugin_activation_logic.diff (3.8 KB) - added by Quandary 13 years ago.
Moves the plugin (de)activation logic from wp-admin/plugins.php to wp-admins/includes/plugin.php
extract_plugin_activation_logic.2.diff (3.8 KB) - added by Quandary 13 years ago.
Moves the plugin (de)activation logic from wp-admin/plugins.php to wp-admins/includes/plugin.php

Download all attachments as: .zip

Change History (7)

#1 @ryan
13 years ago

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

@Quandary
13 years ago

Moves the plugin (de)activation logic from wp-admin/plugins.php to wp-admins/includes/plugin.php

#2 @Quandary
13 years ago

Done. I don't know what the convention is for "error codes"; I just made two up, so someone should probably check that.

#3 @DD32
13 years ago

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.

@Quandary
13 years ago

Moves the plugin (de)activation logic from wp-admin/plugins.php to wp-admins/includes/plugin.php

#4 @Quandary
13 years ago

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.

#5 @ryan
13 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [6259]) activate_plugin(), deactivate_plugins(), and deactivate_all_plugins() from Quandary. fixes #5210

Note: See TracTickets for help on using tickets.