upskill-event-manager/wordpress-dev/tests/bootstrap.php
bengizmo 0bcae8792c fix(tests): Resolve Task 4.7 integration test issues & UMB
- Debugged and resolved failures/skips in integration tests for Task 4.7 (Create/Modify Event Pages). The root cause was incorrect loading and initialization assumptions regarding The Events Calendar Community Events (TEC CE) within the PHPUnit environment.
- Corrected TEC CE loading in `tests/bootstrap.php` by:
    - Fixing the plugin filename (`tribe-community-events.php`).
    - Changing the loading hook from `muplugins_loaded` to `plugins_loaded`.
- Refactored `test-event-management-integration.php`:
    - Moved TEC CE availability checks from `wpSetUpBeforeClass` to `set_up` to avoid premature checks.
    - Removed skip logic based on incorrect assumptions about TEC CE's `$form_handler` property.
- Refactored `class-event-handler.php`:
    - Removed incorrect conditional delegation logic attempting to call a non-existent TEC CE method.
    - Fixed a PHP syntax error (missing closing brace) introduced during previous edits.
- Integration tests for Task 4.7 (`Event_Management_Integration_Test`) now pass successfully.
2025-04-02 07:02:06 -03:00

98 lines
4.2 KiB
PHP

<?php
/**
* PHPUnit bootstrap file for the HVAC Community Events plugin tests.
*/
// Define ABSPATH early if not already defined. Point to WP root in container.
if ( ! defined( 'ABSPATH' ) ) {
define( 'ABSPATH', '/var/www/html/' );
}
// Define the WordPress test directory. Use environment variable or default to Composer vendor path.
$_tests_dir = getenv( 'WP_TESTS_DIR' );
if ( ! $_tests_dir ) {
$_tests_dir = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib'; // Default fallback if vendor path also fails, though less likely now.
}
// Check if the Composer vendor path exists first.
$_vendor_dir = ABSPATH . 'vendor/wp-phpunit/wp-phpunit'; // Use ABSPATH directly
error_log("DEBUG: Checking vendor path: " . $_vendor_dir . '/includes/functions.php'); // ADDED DEBUG
$vendor_exists = file_exists( $_vendor_dir . '/includes/functions.php' );
error_log("DEBUG: Vendor path exists result: " . ($vendor_exists ? 'true' : 'false')); // ADDED DEBUG
if ( $vendor_exists ) {
$_tests_dir = $_vendor_dir;
} else {
error_log("DEBUG: Checking fallback path: " . $_tests_dir . '/includes/functions.php'); // ADDED DEBUG
$fallback_exists = file_exists( $_tests_dir . '/includes/functions.php' );
error_log("DEBUG: Fallback path exists result: " . ($fallback_exists ? 'true' : 'false')); // ADDED DEBUG
if ( ! $fallback_exists ) {
echo "Could not find tests_dir/includes/functions.php, checked $_vendor_dir and $_tests_dir" . PHP_EOL; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
exit( 1 );
}
// If fallback exists, $_tests_dir retains its value (getenv or /tmp)
} // Correctly closing the else block from line 24
// Define the path to the wp-tests-config.php file using ABSPATH.
// This ensures the main bootstrap script finds it in the WP root.
define( 'WP_TESTS_CONFIG_FILE_PATH', ABSPATH . 'wp-tests-config.php' );
// Give access to tests_add_filter() function.
require_once $_tests_dir . '/includes/functions.php';
/**
* Manually load the plugin being tested and its dependencies.
*/
function _manually_load_plugin_and_dependencies() {
// Load The Events Calendar first if it exists
$tec_main_file = ABSPATH . 'wp-content/plugins/the-events-calendar/the-events-calendar.php';
if ( file_exists( $tec_main_file ) ) {
require_once $tec_main_file;
} else {
echo "Warning: The Events Calendar plugin not found at $tec_main_file. Some tests might fail." . PHP_EOL;
}
// Load Event Tickets if it exists (needed for ticket/revenue meta)
$et_main_file = ABSPATH . 'wp-content/plugins/event-tickets/event-tickets.php';
if ( file_exists( $et_main_file ) ) {
require_once $et_main_file;
} else {
echo "Warning: Event Tickets plugin not found at $et_main_file. Some tests might fail." . PHP_EOL;
}
// Load The Events Calendar Community Events if it exists
$tec_ce_main_file = ABSPATH . 'wp-content/plugins/the-events-calendar-community-events/tribe-community-events.php'; // Corrected filename
if ( file_exists( $tec_ce_main_file ) ) {
require_once $tec_ce_main_file;
} else {
echo "Warning: The Events Calendar Community Events plugin not found at $tec_ce_main_file. Integration tests might be skipped." . PHP_EOL;
}
// Load our plugin
require ABSPATH . 'wp-content/plugins/hvac-community-events/hvac-community-events.php';
}
// Use plugins_loaded hook to give dependencies more time to initialize
tests_add_filter( 'plugins_loaded', '_manually_load_plugin_and_dependencies', 1 );
// NOTE: Dependencies will be loaded directly before WP test bootstrap below.
// Define a constant to indicate that tests are running.
// This allows wp-config.php to skip defining DB constants.
define( 'WP_TESTS_RUNNING', true );
// Include the Composer autoloader BEFORE WP test bootstrap
if ( file_exists( ABSPATH . 'vendor/autoload.php' ) ) {
require_once ABSPATH . 'vendor/autoload.php';
} else {
echo 'Composer autoload file not found at ' . ABSPATH . 'vendor/autoload.php' . PHP_EOL;
exit( 1 );
}
// Start up the WP testing environment.
require $_tests_dir . '/includes/bootstrap.php';
// Define plugin constants if needed for tests
// define( 'HVAC_CE_PLUGIN_DIR', dirname( __DIR__ ) . '/wordpress/wp-content/plugins/hvac-community-events/' );