<?php
/**
 * PHPUnit bootstrap file for staging environment
 */

// Composer autoloader
require_once dirname(__DIR__) . '/vendor/autoload.php';

// Define test environment constants if not already defined
if (!defined('WP_TESTS_PHPUNIT')) {
    define('WP_TESTS_PHPUNIT', true);
}

if (!defined('WP_TESTS_CONFIG_FILE_PATH')) {
    define('WP_TESTS_CONFIG_FILE_PATH', dirname(__DIR__) . '/vendor/wp-phpunit/wp-phpunit/wp-tests-config-sample.php');
}

// Define test database settings
define('DB_NAME', 'wordpress_test');
define('DB_USER', 'uberrxmprk');
define('DB_PASSWORD', '');
define('DB_HOST', 'localhost');
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');

// Load the WordPress test suite bootstrap
require_once dirname(__DIR__) . '/vendor/wp-phpunit/wp-phpunit/includes/functions.php';
require_once dirname(__DIR__) . '/vendor/wp-phpunit/wp-phpunit/includes/bootstrap.php';

// Load our plugin
tests_add_filter('muplugins_loaded', function() {
    require dirname(__DIR__) . '/hvac-role-manager.php';
});

// Ensure clean test environment
tests_add_filter('setup_theme', function() {
    // Remove all roles to start clean
    global $wp_roles;
    foreach ($wp_roles->role_names as $role => $name) {
        if (!in_array($role, ['administrator'])) {
            remove_role($role);
        }
    }
});