handler=$handler; }
}
}
namespace {
require $argv[1]??__DIR__.'/DuneAccount.php';
$app=new class {
public $response;public $authenticationHooks=0;
public function __construct(){ $this->response=new \yii\web\Response(); }
public function on($event,$handler):void { if($event!==\yii\base\Application::EVENT_BEFORE_REQUEST||!is_callable($handler))throw new \RuntimeException('Authentication hook changed');$this->authenticationHooks++; }
};
(new \frontend\components\DuneAccount())->bootstrap($app);
if($app->authenticationHooks!==1)throw new \RuntimeException('Authentication hook missing');
$cases=[
['/catalog/dune-shop',200,'html','
Shop',true],
['/catalog/product?products_id=1',200,'html','Product',true],
['/catalog/shopping-cart',200,'html','Cart',true],
['/catalog/checkout',200,'html','Checkout',true],
['/catalog/dune-shop',200,'html','','cache',[],''],
['/catalog/dune-shop',200,'html','','cache',[],''],
['/catalog/dune-shop',200,'html','',false],
['/catalog/dune-shop/sales-feed',200,'json','{"items":[]}',false],
['/catalog/account',303,'html','Redirect',false],
['/catalog/product',500,'html','Error',false],
['/catalog/dune-shop',200,'html','',true,['HTTP_SEC_FETCH_DEST'=>'iframe']],
['/catalog/product',200,'html','',false,['HTTP_X_REQUESTED_WITH'=>'XMLHttpRequest']],
['/catalog/product',200,'html','',false,['HTTP_SEC_FETCH_DEST'=>'empty']],
['/catalog/download',200,'raw','Raw download',false],
['/admin/',200,'html','Admin',false],
['/dune-login.php',200,'html','Identity handoff',false],
];
foreach($cases as $case){
[$path,$status,$format,$content,$decorate]=$case;
unset($_SERVER['HTTP_X_REQUESTED_WITH'],$_SERVER['HTTP_SEC_FETCH_DEST']);foreach($case[5]??[] as $header=>$value)$_SERVER[$header]=$value;
$_SERVER['REQUEST_URI']=$path;$r=$app->response;$r->statusCode=$status;$r->format=$format;$r->content=$content;
($r->handler)((object)['sender'=>$r]);
if($decorate==='cache'){if($r->content!==$case[6])throw new \RuntimeException('Existing bridge was duplicated or cache version retained');}
elseif($decorate){if(substr_count($r->content,'src="/oscommerce-inner.js?v=realm-design-1"')!==1||!str_contains($r->content,' defer>'))throw new \RuntimeException('Missing single presentation bridge: '.$path);}
elseif($r->content!==$content)throw new \RuntimeException('Non-page response changed: '.$path);
if($r->statusCode!==$status||$r->format!==$format)throw new \RuntimeException('Response contract changed');
}
echo count($cases)." native response cases passed; authentication hook retained\n";
}