generated from jric11/baseProject
26 lines
2.6 KiB
PHP
26 lines
2.6 KiB
PHP
<?php
|
|
if(PHP_SAPI!=='cli')exit;
|
|
require __DIR__.'/../classes/Base.php';
|
|
$checks=0;
|
|
function verify(bool $value,string $message): void {global $checks;if(!$value)throw new RuntimeException($message);$checks++;}
|
|
function invalid(callable $call,string $message): void {try{$call();}catch(AppException $e){verify(true,$message);return;}verify(false,$message);}
|
|
foreach([0=>0,1=>0,20=>0,21=>20,41=>40] as $count=>$offset){$p=Pagination::calculate($count,20,1,'last');verify($p['offset']===$offset,'Last page offset for '.$count);verify($p['start']===($count?$offset+1:0),'Start count for '.$count);}
|
|
verify(Pagination::calculate(41,20,99)['page']===3,'Page is clamped after records are removed');
|
|
verify(Pagination::calculate(0,20,1,'next')['offset']===0,'Empty next page cannot have a negative offset');
|
|
verify(Pagination::calculate(200,-1,1)['size']===1,'Negative page size is clamped');
|
|
verify(Pagination::calculate(200,99999,1)['size']===100,'Large page size is bounded');
|
|
$_SESSION=[];Pagination::session('users',100,20,'last');$p=Pagination::session('notes',100,20);verify($p['page']===1,'Pagination does not leak between screens');
|
|
foreach(['0','-1','1-2','1 OR 1=1',[],null] as $id)invalid(fn()=>MaintenanceService::id($id),'Invalid record ID is rejected');
|
|
verify(MaintenanceService::id('12')===12,'Positive ID accepted');
|
|
foreach(['false'=>false,'true'=>true,'0'=>false,'1'=>true] as $input=>$expected)verify(MaintenanceService::boolean($input)===$expected,'Boolean is parsed strictly');
|
|
foreach(['false; DROP TABLE users','1 OR SLEEP(1)','',[],null] as $input)invalid(fn()=>MaintenanceService::boolean($input),'Nonboolean input rejected');
|
|
invalid(fn()=>MaintenanceService::usageRule('*function','getSettings'),'Inherited callbacks are not allowed');
|
|
invalid(fn()=>MaintenanceService::usageRule('users','user_password_hash'),'Database identifiers are not accepted as usage rules');
|
|
MaintenanceService::usageRule('*none','');verify(true,'Code-owned no-reference policy accepted');
|
|
foreach(['0'=>0,'1'=>100,'3.14'=>314,'10.1'=>1010,'9999999.99'=>999999999] as $input=>$expected)verify(RosterService::cents((string)$input)===$expected,'Currency parsed without floating point');
|
|
foreach(['-1','1.001','1e2','NaN','01','10000000'] as $input)invalid(fn()=>RosterService::cents($input),'Invalid currency rejected');
|
|
invalid(fn()=>RosterService::date('2026-02-30'),'Invalid calendar date rejected');
|
|
foreach(['=SUM(A1:A2)',' +CMD','@formula',"\tformula",'-123'] as $cell)verify(str_starts_with(RosterReports::csvText($cell),"'"),'CSV formula prefix neutralized');
|
|
verify(RosterReports::csvText('Plain member')==='Plain member','Ordinary CSV text preserved');
|
|
echo $checks." maintenance unit checks passed.\n";
|