<?php
/**
 * Test file to verify Keycloak login setup
 * Access: /admin/keycloak-login-test.php
 */

// Test 1: Check if file is being executed
echo "1. File is being executed\n";

// Test 2: Check if vendor/autoload.php exists
$vendorPath = dirname(__DIR__) . '/vendor/autoload.php';
echo "2. Vendor path: $vendorPath\n";
echo "   Exists: " . (file_exists($vendorPath) ? "YES" : "NO") . "\n";

// Test 3: Check if we can load Composer autoload
if (file_exists($vendorPath)) {
    require_once $vendorPath;
    echo "3. Composer autoload loaded: YES\n";
    
    // Test 4: Check if OpenIDConnectClient class exists
    if (class_exists('Jumbojett\OpenIDConnectClient')) {
        echo "4. OpenIDConnectClient class found: YES\n";
    } else {
        echo "4. OpenIDConnectClient class found: NO\n";
    }
} else {
    echo "3. Composer autoload loaded: NO (file not found)\n";
}

// Test 5: Check if env.php exists
$envPath = dirname(__DIR__) . '/env.php';
echo "5. Env path: $envPath\n";
echo "   Exists: " . (file_exists($envPath) ? "YES" : "NO") . "\n";

// Test 6: Check if system/core/startup.php exists
$startupPath = dirname(__DIR__) . '/system/core/startup.php';
echo "6. Startup path: $startupPath\n";
echo "   Exists: " . (file_exists($startupPath) ? "YES" : "NO") . "\n";

// Test 7: Check PHP version
echo "7. PHP Version: " . PHP_VERSION . "\n";

// Test 8: Check if session can be started
if (session_status() === PHP_SESSION_NONE) {
    session_start();
    echo "8. Session started: YES\n";
} else {
    echo "8. Session status: " . (session_status() === PHP_SESSION_ACTIVE ? "ACTIVE" : "DISABLED") . "\n";
}

// Test 9: Check current directory
echo "9. Current directory: " . __DIR__ . "\n";
echo "   Root directory: " . dirname(__DIR__) . "\n";

// Test 10: Check if keycloak-login.php exists
$keycloakLoginPath = __DIR__ . '/keycloak-login.php';
echo "10. Keycloak login path: $keycloakLoginPath\n";
echo "    Exists: " . (file_exists($keycloakLoginPath) ? "YES" : "NO") . "\n";

if (file_exists($keycloakLoginPath)) {
    echo "    Size: " . filesize($keycloakLoginPath) . " bytes\n";
    echo "    Readable: " . (is_readable($keycloakLoginPath) ? "YES" : "NO") . "\n";
    
    // Check for syntax errors
    $output = [];
    $return = 0;
    exec("php -l " . escapeshellarg($keycloakLoginPath) . " 2>&1", $output, $return);
    echo "    Syntax check: " . ($return === 0 ? "OK" : "ERROR") . "\n";
    if ($return !== 0) {
        echo "    Error: " . implode("\n", $output) . "\n";
    }
}

echo "\n=== Test Complete ===\n";
echo "If all tests pass, try accessing: /admin/keycloak-login.php\n";
