upskill-event-manager/wordpress-dev/tests/bootstrap.php
bengizmo cdef12ee80 feat(events): Implement fallback logic and UI for Create/Modify Event page
- Refactored fallback submission logic in `class-event-handler.php` to remove `wp_die`/`exit` calls and use redirects for error handling, enabling proper unit testing.
- Implemented meta-data saving (dates, venue, organizer) in the fallback logic using `update_post_meta`.
- Updated unit tests (`test-event-management.php`) to remove `markTestIncomplete` calls related to handler errors and uncommented meta assertions. Unit tests for fallback logic now pass.
- Added Instructions section and Return to Dashboard button to the event form shortcode (`display_event_form_shortcode`).
- Applied basic theme styling classes (`ast-container`, `notice`, `ast-button`) to the event form.
- Updated `docs/implementation_plan.md` to reflect completion of tasks 4.1-4.5 and set focus to Task 5.

Refs: Task 4.1, 4.2, 4.3, 4.4, 4.5
2025-04-01 11:46:24 -03:00

85 lines
3.6 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 our plugin
require ABSPATH . 'wp-content/plugins/hvac-community-events/hvac-community-events.php';
}
// Use plugins_loaded hook which runs after mu-plugins and regular plugins are loaded
tests_add_filter( 'plugins_loaded', '_manually_load_plugin_and_dependencies', 1 );
// 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/' );