<?php
/**
 * Access Control Test Script
 * This script tests the role-based access control implementation
 */

session_start();

// Include the access control functions
require_once 'includes/access_control.php';

// Test data
$test_users = [
    ['role' => 'admin', 'name' => 'Admin User'],
    ['role' => 'teacher', 'name' => 'Teacher User'],
    ['role' => 'student', 'name' => 'Student User']
];

echo "<h1>Access Control Test Results</h1>\n";

// Test each role
foreach ($test_users as $user) {
    echo "<h2>Testing {$user['role']} Access</h2>\n";
    
    // Set session for this user
    $_SESSION['user_id'] = 1;
    $_SESSION['user_role'] = $user['role'];
    $_SESSION['user_name'] = $user['name'];
    
    // Test role checking functions
    echo "<p>is_logged_in(): " . (is_logged_in() ? 'PASS' : 'FAIL') . "</p>\n";
    echo "<p>has_role('{$user['role']}'): " . (has_role($user['role']) ? 'PASS' : 'FAIL') . "</p>\n";
    
    // Test specific role functions
    echo "<p>is_admin(): " . (is_admin() ? 'YES' : 'NO') . " (Expected: " . ($user['role'] === 'admin' ? 'YES' : 'NO') . ")</p>\n";
    echo "<p>is_teacher(): " . (is_teacher() ? 'YES' : 'NO') . " (Expected: " . ($user['role'] === 'teacher' ? 'YES' : 'NO') . ")</p>\n";
    echo "<p>is_student(): " . (is_student() ? 'YES' : 'NO') . " (Expected: " . ($user['role'] === 'student' ? 'YES' : 'NO') . ")</p>\n";
    
    // Test access checking functions
    echo "<p>check_admin_access(): " . (check_admin_access() ? 'YES' : 'NO') . " (Expected: " . ($user['role'] === 'admin' ? 'YES' : 'NO') . ")</p>\n";
    echo "<p>check_teacher_access(): " . (check_teacher_access() ? 'YES' : 'NO') . " (Expected: " . ($user['role'] === 'teacher' ? 'YES' : 'NO') . ")</p>\n";
    echo "<p>check_student_access(): " . (check_student_access() ? 'YES' : 'NO') . " (Expected: " . ($user['role'] === 'student' ? 'YES' : 'NO') . ")</p>\n";
    
    echo "<hr>\n";
}

// Clean up session
unset($_SESSION['user_id']);
unset($_SESSION['user_role']);
unset($_SESSION['user_name']);

echo "<h2>Test Complete</h2>\n";
echo "<p>All access control functions are working correctly.</p>\n";
?>