Skip to:
Content

BuddyPress.org

Opened 8 years ago

Closed 8 years ago

#7254 closed defect (bug) (fixed)

PHPUnit tests does not call plugin activation hook.

Reported by: djpaul's profile DJPaul Owned by: djpaul's profile djpaul
Milestone: 2.7 Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords:
Cc:

Description

In our PHPUnit bootstrap, we load BuddyPress into the WP env. by including the BuddyPress file directly, hooked to muplugins_loaded. This has worked but we have not noticed that it means that the activate_plugin hooks (etc) that activate_plugins() would usually trigger, aren't called.

BuddyPress hooks to the activation function in bp_activation() to call bp_add_options(), which adds the default values of everything in bp_get_default_options() to the options table.

This has been masked by the mis-behaviour of bp_get_default_options() which currently checks for missing options and adds them to the database, whenever the function's called.

Change History (4)

#1 @DJPaul
8 years ago

I have a fixed, but it's tied up in #7227. I'll see if I can split it.

#2 @djpaul
8 years ago

In 11093:

BuddyPress, Emails: set value of bp-emails-unsubscribe-salt option for new installs.

The initial value was set in bp_get_default_options() and worked because that function adds missing options to the database when it's ran.
For version updates, the new option was already being explictly added elsewhere.

However if a plugin is active and loads before the plugins_loaded hook, and calls add_option() or update_option() (or multisite equivalents), a fatal error is caused by the bp_core_clear_root_options_cache()` function.
This is because wp_generate_password() in used in bp_get_default_options() to set the bp-emails-unsubscribe-salt option, which is only available via wp-includes/pluggable.php. That file is only loaded by WordPress after plugins are loaded.

This change sets the default value in bp_get_default_options(), and then explicitly updates the value to the unsubscribe halts in the existing email installation function.

Fixes #7227
See #7254

Props r-a-y, DJPaul

#3 @djpaul
8 years ago

In 11094:

Core: stop bp_get_default_options() adding missing options to the database.

bp_get_default_options() is used to get default option names and values throughout BuddyPress. If an option is not set in the database when the function is ran, it will add it.
The function is called in lots of places, and it even gets called before the version update handler routine does, from bp_core_set_avatar_constants().
This is not obvious, and causes unpredictable behaviour about when a new option should exist (or not).

This change removes the missing option insertion from bp_get_default_options().
New installs will have all options added by bp_activation(). Version updates will take responsibility to add new options within the existing upgrade routines.

See #7254 and #7227

#4 @djpaul
8 years ago

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

In 11096:

Tests: fix plugin activation in PHPUnit bootstrap.

In the bootstrap, we load BuddyPress into the WordPress by including the BuddyPress file directly, hooked to muplugins_loaded.
This has worked well except the standard plugin activation actions that activate_plugins() would usually trigger, aren't called.
BuddyPress hooks to the activation action in bp_activation() to call bp_add_options(), which adds default options and values to the database.

This change calls the required action manually, fixing the PHPUnit environment set-up, required after r11094.

Fixes #7254

Note: See TracTickets for help on using tickets.