<?php
require_once __DIR__ . '/app/functions.php';
$passed=0;$failed=0;
function q23(string $name, bool $ok): void { global $passed,$failed; if($ok){$passed++;echo "PASS | $name\n";}else{$failed++;echo "FAIL | $name\n";} }
$userF=['id'=>10,'is_system_admin'=>0,'role_codes'=>['USERF']];
$userDs=['id'=>20,'is_system_admin'=>0,'role_codes'=>['USERDS']];
$assigned=['id'=>30,'is_system_admin'=>0,'role_codes'=>['USERF']];
$ictF=['id'=>40,'is_system_admin'=>0,'role_codes'=>['USERF','ICTF']];
$ticket=['id'=>99,'user_id'=>10,'assigned_to'=>30,'responsible_role_code'=>'ICTF'];
q23('Direktno zaduženi korisnik može da upravlja tiketom', can_manage_ticket($ticket,$assigned));
q23('Odgovorna ICTF rola može da upravlja tiketom', can_manage_ticket($ticket,$ictF));
q23('Običan USERF koji nije zadužen nema manage pravo', !can_manage_ticket($ticket,$userF));
q23('Običan USERDS koji nije zadužen nema manage pravo', !can_manage_ticket($ticket,$userDs));
$css=file_get_contents(__DIR__.'/assets/css/style.css');
$view=file_get_contents(__DIR__.'/ticket_view.php');
q23('Timeline koristi overflow-y auto', preg_match('/\.ticket-evidence-card \.ticket-events-timeline\s*\{[^}]*overflow-y:\s*auto/s',$css)===1);
q23('Timeline koristi align-content start', preg_match('/\.ticket-evidence-card \.ticket-events-timeline\s*\{[^}]*align-content:\s*start/s',$css)===1);
q23('Event list nije ograničen na 20 zapisa', strpos($view,'ORDER BY e.created_at DESC, e.id DESC LIMIT 20')===false);
q23('Event redosled je newest-first', strpos($view,'ORDER BY e.created_at DESC, e.id DESC')!==false);
echo "RESULT $passed/".($passed+$failed)." PASS\n"; exit($failed?1:0);
