Initial clean version

This commit is contained in:
root
2026-11-11 09:24:28 +01:00
commit ab58b33f9c
156 changed files with 5697 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
<?php
require dirname(__DIR__).'/bootstrap.php';
use App\{DB,Convocations,ConvocationExport,ClubRoles,Regulations};
if(getenv('ESBSC_TEST_DATABASE')!=='1')exit('Base jetable requise');
$n=0;function check32($ok,$label){global $n;if(!$ok)throw new RuntimeException($label);echo 'V32 '.(++$n).' '.$label."\n";}
function rejects32($fn,$label){try{$fn();throw new LogicException('Expected refusal: '.$label);}catch(RuntimeException $e){check32(true,$label);}}
Convocations::migrate();Convocations::migrate();
DB::conn()->beginTransaction();
try{
$actor=(int)DB::value('SELECT id FROM users LIMIT 1');$pid=(int)DB::value("SELECT id FROM players WHERE person_number='V3-TEST'");$week=Convocations::week(date('Y-m-d',strtotime('+14 days')));$sat=date('Y-m-d',strtotime($week.' +5 days'));$sun=date('Y-m-d',strtotime($week.' +6 days'));
check32(Convocations::week($sat)===$week&&Convocations::week($sun)===$week,'Samedi et dimanche : même semaine');
check32(Convocations::week('2027-01-03')==='2026-12-28','Semaine à cheval sur deux années');
$r=Convocations::saveAvailability($pid,$sat,'injured','NOTE PRIVÉE TEST',0,$actor);
check32($r['version']==1&&Convocations::state(Convocations::availability($sun),$pid)['status']==='injured','Disponibilité partagée toutes équipes et deux jours');
rejects32(fn()=>Convocations::saveAvailability($pid,$sat,'available','',0,$actor),'Concurrence : ancienne version refusée');
rejects32(fn()=>Convocations::saveAvailability($pid,$sat,'invalid','',1,$actor),'Statut inconnu refusé');
rejects32(fn()=>Convocations::saveAvailability($pid,'2020-01-01','injured','',0,$actor),'Historique non modifiable');
check32(Convocations::state(Convocations::availability(date('Y-m-d',strtotime($week.' +7 days'))),$pid)['status']==='available','Semaine suivante disponible sans effacer précédent historique');
$oldRevision=DB::revision();Convocations::saveAvailability($pid,$sat,'unavailable','NOTE PRIVÉE TEST',1,$actor);check32(DB::revision()===$oldRevision,'Indisponibilité ne périme pas les contrôles');
$mids=[];foreach(DB::all('SELECT * FROM teams ORDER BY sort_order LIMIT 4') as $i=>$t){
DB::query("INSERT INTO matches(fff_match_id,team_id,match_date,match_time,opponent,competition,home_away,status) VALUES(?,?,?,'15:00:00',?,'TEST V32',?,'scheduled')",['V32-'.$i,$t['id'],$i===0?$sat:$sun,$i===0?'Étoile Sportive de Saint-Sauveur et des Communes Réunies':'Club test '.($i+1),$i%2?'away':'home']);$mid=(int)DB::conn()->lastInsertId();$mids[]=$mid;
DB::query('INSERT INTO squads(match_id,updated_by,validated_revision,validated_at) VALUES(?,?,?,NOW())',[$mid,$actor,DB::revision()]);$sid=(int)DB::conn()->lastInsertId();DB::query('INSERT INTO squad_players(squad_id,player_id) VALUES(?,?)',[$sid,$pid]);Convocations::saveStaff($sid,[$pid]);
}
$s=Convocations::build($sat);check32(count($s['groups'])===4,'Quatre groupes alignés dans la synthèse');check32(!in_array($pid,array_column($s['missing'],'id')),'Convoqué absent des non-convoqués');check32(isset($s['duplicates'][$pid]),'Présence dans plusieurs groupes signalée');
$share=Convocations::share($s,$mids,false,false,$s['fingerprint']);$json=json_encode($share);check32(!str_contains($json,'NOTE PRIV')&&!str_contains($json,'person_number')&&!str_contains($json,'availability')&&!str_contains($json,'licence'),'Export public exclut notes, identifiants et données internes');
check32(!$share['include_staff']&&!$share['legend']&&!$share['groups'][0]['staff'],'Staff et légende absents par défaut');
$one=Convocations::share($s,[$mids[1]],true,true,$s['fingerprint']);check32(count($one['groups'])===1&&count($one['groups'][0]['staff'])===1&&$one['legend'],'Export partiel avec options explicites');
rejects32(fn()=>Convocations::share($s,[999999],false,false,$s['fingerprint']),'Match hors semaine refusé');
rejects32(fn()=>Convocations::share($s,[],false,false,$s['fingerprint']),'Export vide refusé');
rejects32(fn()=>Convocations::share($s,$mids,false,false,'old'),'Ancienne synthèse refusée');
DB::query('UPDATE squads SET validated_revision=NULL WHERE match_id=?',[$mids[0]]);$draft=Convocations::build($week);rejects32(fn()=>Convocations::share($draft,$mids,false,false,$draft['fingerprint']),'Brouillon non exportable');
DB::query('UPDATE squads SET validated_revision=? WHERE match_id=?',[DB::revision(),$mids[0]]);DB::touch();$stale=Convocations::build($week);rejects32(fn()=>Convocations::share($stale,$mids,false,false,$stale['fingerprint']),'Données sportives actualisées : revalidation requise');
$staffPerson=DB::one('SELECT * FROM players WHERE id=?',[$pid]);$index=[$pid=>[['kind'=>'admin']]];check32(!ClubRoles::filter([$staffPerson],$index,'staff',0),'Administratifs masqués par défaut dans Staff');$index[$pid]=[['kind'=>'sport'],['kind'=>'player']];check32(count(ClubRoles::filter([$staffPerson],$index,'staff',0))===1&&count(ClubRoles::filter([$staffPerson],$index,'player',0))===1,'Double rôle visible dans les deux pages');
// Real exporter fixtures: long accented names, all four columns, multi-page, Excel literal formulas.
foreach($share['groups'] as $i=>&$g){$g['players']=array_map(fn($j)=>['DUPONT Émilien','MARTIN Jean-Baptiste','DUPUIS-DESCHAMPS Alexandre','LE GALL François'][$j%4].' '.($j+1),range(0,13+$i));$g['staff']=['Éducateur Exemple'];}unset($g);
$share['include_staff']=true;$share['legend']=true;$out=$argv[1]??sys_get_temp_dir();file_put_contents($out.'/v32-convocations.pdf',ConvocationExport::pdf($share));file_put_contents($out.'/v32-convocations.xlsx',ConvocationExport::xlsx($share));file_put_contents($out.'/v32-share.json',json_encode($share));
$large=$share;foreach($large['groups'] as &$g)$g['players']=array_fill(0,30,'DUPUIS-DESCHAMPS Jean-Baptiste Émilien');unset($g);file_put_contents($out.'/v32-long.pdf',ConvocationExport::pdf($large));
$share['groups'][0]['players'][0]='=HYPERLINK("https://example.invalid","test")';$bytes=ConvocationExport::xlsx($share);$tmp=tempnam(sys_get_temp_dir(),'v32-');file_put_contents($tmp,$bytes);$z=new ZipArchive();$z->open($tmp);$xml=$z->getFromName('xl/worksheets/sheet1.xml');check32(!str_contains($xml,'<f>')&&str_contains($xml,'t="inlineStr"'),'Noms Excel stockés en texte, jamais exécutés comme formules');$z->close();unlink($tmp);
check32(str_starts_with(ConvocationExport::pdf($one),'%PDF-1.4'),'PDF produit pour une seule équipe');
}finally{DB::conn()->rollBack();}
echo "V3.2 OK : $n assertions\n";