1
0
Fork 0
mirror of https://github.com/buddypress/buddypress.git synced 2026-07-21 20:54:17 +08:00
buddypress/tests/phpunit/includes/loader.php
r-a-y c1a47307d3 Blogs: Conditionally load action and screen functions.
This commit conditionally loads action and screen function code for the
Blogs component, utilizing the `'bp_late_include'` hook introduced in
r11884.

Previously, we loaded these functions at all times, which is unnecessary
when a user is not on a BuddyPress blogs page. Now, we only load this
code when needed.

See #7218.

git-svn-id: https://buddypress.svn.wordpress.org/trunk@11934 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
2018-04-02 18:15:37 +00:00

40 lines
No EOL
1.4 KiB
PHP

<?php
require_once( dirname( __FILE__ ) . '/define-constants.php' );
$multisite = (int) ( defined( 'WP_TESTS_MULTISITE') && WP_TESTS_MULTISITE );
system( WP_PHP_BINARY . ' ' . escapeshellarg( dirname( __FILE__ ) . '/install.php' ) . ' ' . escapeshellarg( WP_TESTS_CONFIG_PATH ) . ' ' . escapeshellarg( WP_TESTS_DIR ) . ' ' . $multisite );
// Bootstrap BP
require dirname( __FILE__ ) . '/../../../src/bp-loader.php';
// Bail from redirects as they throw 'headers already sent' warnings.
tests_add_filter( 'wp_redirect', '__return_false' );
require_once( dirname( __FILE__ ) . '/mock-mailer.php' );
function _bp_mock_mailer( $class ) {
return 'BP_UnitTest_Mailer';
}
tests_add_filter( 'bp_send_email_delivery_class', '_bp_mock_mailer' );
/**
* Load up component action and screen code.
*
* In BuddyPress, this is loaded conditionally, but PHPUnit needs all files
* loaded at the same time to prevent weird load order issues.
*/
$components = array( 'activity', 'blogs', 'friends', 'groups', 'members', 'messages', 'notifications', 'settings', 'xprofile' );
foreach ( $components as $component ) {
add_action( "bp_{$component}_includes", function() use ( $component ) {
$dirs = array(
buddypress()->plugin_dir . 'bp-' . $component . '/actions/',
buddypress()->plugin_dir . 'bp-' . $component . '/screens/',
);
foreach ( $dirs as $dir ) {
foreach ( glob( $dir . "*.php" ) as $file ) {
require $file;
}
}
} );
}