diff --git a/projects/plugins/jetpack/tests/php/bootstrap.php b/projects/plugins/jetpack/tests/php/bootstrap.php index be48273fb6c70..5462725146a14 100644 --- a/projects/plugins/jetpack/tests/php/bootstrap.php +++ b/projects/plugins/jetpack/tests/php/bootstrap.php @@ -87,6 +87,11 @@ echo "Disregard Core's -c tests/phpunit/multisite.xml notice below." . PHP_EOL; } +if ( '1' !== getenv( 'JETPACK_TEST_WPCOMSH' ) ) { + echo 'To run tests with the WordPress.com Site Helper plugin activated and Atomic mode enabled,' . PHP_EOL; + echo 'prefix phpunit with JETPACK_TEST_WPCOMSH=1' . PHP_EOL; +} + if ( '1' !== getenv( 'JETPACK_TEST_WOOCOMMERCE' ) ) { echo 'To run Jetpack woocommerce tests, prefix phpunit with JETPACK_TEST_WOOCOMMERCE=1' . PHP_EOL; } else { @@ -104,7 +109,29 @@ function _manually_load_plugin() { if ( '1' === getenv( 'JETPACK_TEST_WPCOMSH' ) ) { define( 'IS_ATOMIC', true ); - require __DIR__ . '/../../../../mu-plugins/wpcomsh/wpcomsh.php'; + if ( getenv( 'GITHUB_ACTIONS' ) ) { + + // Using plugin code installed by .github/files/setup-wordpress-env.sh. + require_once __DIR__ . '/../../../../mu-plugins/wpcomsh/wpcomsh.php'; + require_once __DIR__ . '/../../../../mu-plugins/wpcomsh/vendor/autoload.php'; + } else { + require_once __DIR__ . '/../../../wpcomsh/wpcomsh.php'; + require_once __DIR__ . '/../../../wpcomsh/vendor/autoload.php'; + } + \Automattic\Jetpack\Jetpack_Mu_Wpcom::init(); + + // We can't simulate plugins_loaded because it causes a loop, but we can call load methods. + $reflection = new ReflectionClass( '\Automattic\Jetpack\Jetpack_Mu_Wpcom' ); + foreach ( $reflection->getMethods() as $method ) { + + // Verbum comments calls code that's not available in single site environment. + if ( str_starts_with( $method->name, 'load_' ) ) { + if ( 'load_verbum_comments' === $method->name ) { + continue; + } + $method->invoke( null ); + } + } } require __DIR__ . '/../../jetpack.php'; $jetpack = Jetpack::init(); diff --git a/projects/plugins/jetpack/tests/php/lib/class-wpcom-features.php b/projects/plugins/jetpack/tests/php/lib/class-wpcom-features.php index b602c12962252..b0a5b81f64229 100644 --- a/projects/plugins/jetpack/tests/php/lib/class-wpcom-features.php +++ b/projects/plugins/jetpack/tests/php/lib/class-wpcom-features.php @@ -5,6 +5,10 @@ * @package Jetpack */ +if ( class_exists( 'WPCOM_Features' ) ) { + return; +} + /** * Class WPCOM_Features. */ diff --git a/projects/plugins/jetpack/tests/php/lib/mock-functions.php b/projects/plugins/jetpack/tests/php/lib/mock-functions.php index 0d67d385731c0..0d4ba3031df1f 100644 --- a/projects/plugins/jetpack/tests/php/lib/mock-functions.php +++ b/projects/plugins/jetpack/tests/php/lib/mock-functions.php @@ -21,7 +21,7 @@ function has_blog_sticker( $sticker ) { function wp_cache_is_enabled() {} } -if ( ! function_exists( 'wpcom_site_has_feature' ) && false === getenv( 'WITH_WPCOMSH' ) ) { +if ( ! function_exists( 'wpcom_site_has_feature' ) && false === getenv( 'JETPACK_TEST_WPCOMSH' ) ) { /** * Mock feature support. *