1111// Load the PHPUnit Polyfills for cross-version compatibility.
1212require_once dirname ( __DIR__ ) . '/vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php ' ;
1313
14- // Make sure the tests directory is in the include path .
15- if ( ! defined ( 'WP_CONTENT_DIR ' ) ) {
16- define ( 'WP_CONTENT_DIR ' , dirname ( __DIR__ ) . '/tests/wp-content ' );
14+ // Set up WordPress test environment constants .
15+ if ( ! defined ( 'WP_TESTS_DIR ' ) ) {
16+ define ( 'WP_TESTS_DIR ' , getenv ( ' WP_TESTS_DIR ' ) ?: '/tmp/wordpress-tests-lib ' );
1717}
1818
19- if ( ! defined ( 'WP_PLUGIN_DIR ' ) ) {
20- define ( 'WP_PLUGIN_DIR ' , WP_CONTENT_DIR . '/plugins ' );
19+ // Ensure WordPress tests configuration exists.
20+ if ( ! file_exists ( WP_TESTS_DIR . '/includes/bootstrap.php ' ) ) {
21+ echo "Error: WordPress tests framework not found at " . WP_TESTS_DIR . PHP_EOL ;
22+ echo "Please check your WP_TESTS_DIR environment variable " . PHP_EOL ;
23+ exit ( 1 );
2124}
2225
23- // Define a test plugin directory name.
24- if ( ! defined ( 'TEST_PLUGIN_DIR ' ) ) {
25- define ( 'TEST_PLUGIN_DIR ' , dirname ( __DIR__ ) );
26+ // Ensure PHPMailer is available - try to locate it from WordPress core if needed.
27+ if ( ! file_exists ( WP_TESTS_DIR . '/includes/class-wp-phpmailer.php ' ) ) {
28+ if ( file_exists ( '/tmp/wordpress/wp-includes/class-phpmailer.php ' ) ) {
29+ @mkdir ( WP_TESTS_DIR . '/includes ' , 0777 , true );
30+ copy ( '/tmp/wordpress/wp-includes/class-phpmailer.php ' , WP_TESTS_DIR . '/includes/class-wp-phpmailer.php ' );
31+ echo "Notice: Copied PHPMailer class to test environment " . PHP_EOL ;
32+ }
2633}
2734
2835// Manually load the plugin being tested.
@@ -31,14 +38,5 @@ function _manually_load_plugin() {
3138}
3239
3340// Start up the WP testing environment.
34- // Ideally, this would be automatically handled by the integration test action.
35- // If WP_TESTS_DIR is defined, we'll use it, otherwise we'll set up a basic mock.
36- if ( defined ( 'WP_TESTS_DIR ' ) && file_exists ( WP_TESTS_DIR . '/includes/bootstrap.php ' ) ) {
37- require WP_TESTS_DIR . '/includes/bootstrap.php ' ;
38- tests_add_filter ( 'muplugins_loaded ' , '_manually_load_plugin ' );
39- } else {
40- // Simple mock class if WP test suite isn't available
41- class WP_UnitTestCase extends \Yoast \PHPUnitPolyfills \TestCases \TestCase {
42- // Include test helper methods here
43- }
44- }
41+ require WP_TESTS_DIR . '/includes/bootstrap.php ' ;
42+ tests_add_filter ( 'muplugins_loaded ' , '_manually_load_plugin ' );
0 commit comments