37 lines
3.5 KiB
PHP
37 lines
3.5 KiB
PHP
<?php
|
|
require dirname(__DIR__).'/bootstrap.php';
|
|
use App\{Cachets,Regulations};
|
|
$n=0;function check($v,$m){global $n;if(!$v)throw new RuntimeException($m);echo 'OK '.(++$n).' '.$m."\n";}
|
|
function reject($fn,$label){try{$fn();}catch(RuntimeException $e){check(true,$label);return;}throw new RuntimeException($label);}
|
|
$blank=['cachet_code'=>'','cachet_libelle'=>'','cachet_date_de_debut'=>'','cachet_date_de_fin'=>''];
|
|
$mn=['cachet_code'=>'MN','cachet_libelle'=>'MUTATION','cachet_date_de_debut'=>'01/07/2026','cachet_date_de_fin'=>'14/10/2026'];
|
|
$mh=array_replace($mn,['cachet_code'=>'MH','cachet_libelle'=>'MUTATION HORS PERIODE']);
|
|
check(Cachets::parse(['nature_changement_de_club'=>'Mutée'])===null,'Colonne administrative seule ne renseigne rien');
|
|
check(Cachets::parse($blank+['nature_changement_de_club'=>'Mutée'])===[],'Mutée sans cachet : aucun muté');
|
|
$s=Cachets::parse($mn+['nature_changement_de_club'=>'Non mutée']);
|
|
check(Cachets::at($s,'2026-06-30')['mutation']==='none','Avant le début');
|
|
check(Cachets::at($s,'2026-07-01')['mutation']==='normal','Début inclus');
|
|
check(Cachets::at($s,'2026-10-14')['mutation']==='normal','Fin incluse');
|
|
check(Cachets::at($s,'2026-10-15')['mutation']==='none','Fin de cachet sans réimport');
|
|
check(Cachets::at(Cachets::parse($mh),'2026-09-26')['mutation']==='outside','MH hors période');
|
|
$multi=[];foreach($mn as $k=>$v)$multi[$k.'_1']=$v;foreach($mh as $k=>$v)$multi[$k.'_2']=$v;
|
|
check(count(Cachets::parse($multi))===2,'Colonnes de cachets multiples');
|
|
check(Cachets::at(Cachets::parse($multi),'2026-09-26')['mutation']==='outside','MN et MH : un seul joueur hors période');
|
|
$unknown=array_replace($mn,['cachet_code'=>'XX','cachet_libelle'=>'Autre restriction']);
|
|
check(Cachets::at(Cachets::parse($unknown),'2026-09-26')['mutation']==='unknown','Cachet inconnu signalé');
|
|
reject(fn()=>Cachets::parse(['cachet_code'=>'']), 'Colonnes partielles refusées');
|
|
reject(fn()=>Cachets::parse(array_replace($mn,['cachet_libelle'=>'MUTATION HORS PERIODE'])),'Code et libellé contradictoires refusés');
|
|
reject(fn()=>Cachets::parse(array_replace($mn,['cachet_date_de_fin'=>''])),'Fin manquante refusée');
|
|
reject(fn()=>Cachets::parse(array_replace($mn,['cachet_date_de_fin'=>'31/02/2026'])),'Date impossible refusée');
|
|
reject(fn()=>Cachets::parse(array_replace($mn,['cachet_date_de_fin'=>'01/06/2026'])),'Dates inversées refusées');
|
|
$identity=['numero_personne'=>'123','numero_licence'=>'456','nom'=>'TEST','prenom'=>'A','type_licence'=>'Libre'];
|
|
$rows=Cachets::groupRows([['line'=>2,'data'=>$identity+$mn],['line'=>3,'data'=>$identity+$mn],['line'=>4,'data'=>$identity+$mh]]);
|
|
check(count($rows)===1 && count(Cachets::fromRow($rows[0]))===2,'Lignes multiples regroupées et dédoublonnées');
|
|
$bad=Cachets::groupRows([['line'=>2,'data'=>$identity+$mn],['line'=>3,'data'=>array_replace($identity,['numero_personne'=>'999'])+$mh]]);
|
|
reject(fn()=>Cachets::fromRow($bad[0]),'Personnes différentes pour la même licence refusées');
|
|
$l=['season'=>'2026/2027','licence_type'=>'Libre','licence_status'=>'active','qualified_on'=>'2026-07-01','category_ok'=>'yes','mutation'=>'exempt','imported_cachets'=>$s];
|
|
$r=Regulations::individual(['active'=>1],['match_date'=>'2026-09-26'],[$l],['status'=>'available','warnings'=>[]]);
|
|
check($r['mutation']==='normal','Cachet importé prioritaire sur exemption manuelle ancienne');
|
|
$l['season']='2025/2026';check(Regulations::individual(['active'=>1],['match_date'=>'2026-09-26'],[$l],['status'=>'available','warnings'=>[]])['mutation']==='unknown','Pas de cachet de la saison précédente');
|
|
echo "$n tests cachets réussis.\n";
|