<?php
declare(strict_types=1);
require_once __DIR__.'/../shared/lib/transcripts.php';require_once __DIR__.'/../shared/lib/system_settings.php';
function transcript_check($ok){if(!$ok)throw new RuntimeException('Transcript assertion failed');}
$token=bin2hex(random_bytes(32));transcript_check(transcript_token_valid($token));transcript_check(!transcript_token_valid('../bad'));transcript_check(!transcript_token_valid(str_repeat('a',63)));transcript_check(strlen(hash('sha256',$token))===64);
$snapshot=['results'=>[['exam_id'=>1,'revision'=>3],['exam_id'=>2,'revision'=>5]]];$rows=[['exam_id'=>1,'revision'=>3,'published_at'=>'2026-10-17'],['exam_id'=>2,'revision'=>5,'published_at'=>'2026-10-17']];transcript_check(transcript_sources_match($snapshot,$rows));$rows[1]['revision']=6;transcript_check(!transcript_sources_match($snapshot,$rows));$rows[1]['revision']=5;$rows[1]['published_at']=null;transcript_check(!transcript_sources_match($snapshot,$rows));transcript_check(!transcript_sources_match($snapshot,[]));
$data=platform_defaults();$data['public_url']='https://example.org/slps/';transcript_check(platform_validate($data)['public_url']==='https://example.org/slps');foreach(['javascript:alert(1)','https://user:pass@example.org','https://example.org/?token=bad','https://example.org/#bad'] as $bad){$data['public_url']=$bad;try{platform_validate($data);throw new RuntimeException('Invalid public URL accepted');}catch(InvalidArgumentException $e){}}
echo "PASS: unguessable token shape, current/superseded/unpublished result verification and safe public QR URLs.\n";
