<?php
/**
 * PHPUnit bootstrap file for Dragon Cron Manager
 *
 * @package DragonCronManager
 */

// Composer autoloader
$autoloader = dirname( __DIR__ ) . '/vendor/autoload.php';
if ( file_exists( $autoloader ) ) {
	require_once $autoloader;
}

// Get the tests directory
$_tests_dir = getenv( 'WP_TESTS_DIR' );

if ( ! $_tests_dir ) {
	$_tests_dir = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib';
}

// Give access to tests_add_filter() function
if ( file_exists( $_tests_dir . '/includes/functions.php' ) ) {
	require_once $_tests_dir . '/includes/functions.php';

	/**
	 * Manually load the plugin for tests
	 */
	function _manually_load_plugin() {
		require dirname( __DIR__ ) . '/dragon-cron-manager.php';
	}
	tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );

	// Start up the WP testing environment
	require $_tests_dir . '/includes/bootstrap.php';
} else {
	// Fallback: Load WordPress functions we need for standalone testing
	// This allows running basic unit tests without the full WP test suite

	if ( ! defined( 'ABSPATH' ) ) {
		define( 'ABSPATH', '/tmp/' );
	}

	if ( ! defined( 'DAY_IN_SECONDS' ) ) {
		define( 'DAY_IN_SECONDS', 86400 );
	}

	// Load the plugin classes directly for unit testing
	require_once dirname( __DIR__ ) . '/includes/class-cron.php';
	require_once dirname( __DIR__ ) . '/includes/class-logger.php';
}
