Skip to content
Snippets Groups Projects
Commit 2e250427 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

add test script to chek redirect

parent 72ee5697
Branches
No related tags found
1 merge request!57512 php83 update
<?php
/**
* TEST
* Verify if a redirect works
*/
require_once '../public_html/classes/redirect.class.php';
// ------------------------------------------------------------------------
// CONFIG
// ------------------------------------------------------------------------
$aTests=[
'www.example.com - static entry' => [
'host'=>'www.example.com',
'request'=>'/mail',
'target'=>'https://www.example.com/webmail',
'code'=>301,
],
'www.example.com - regex' => [
'host'=>'www.example.com',
'request'=>'/somethingold',
'target'=>'https://www.example.com/',
'code'=>307,
],
];
// ------------------------------------------------------------------------
// INIT
// ------------------------------------------------------------------------
$oR=new redirect();
$oR->setDebug(isset($_GET['debugredirect']) && $_GET['debugredirect'] ? true : false);
echo "\n";
echo "##################### TEST REDIRECT #####################\n";
echo "\n";
// ------------------------------------------------------------------------
// LOOP :: Redirects
// ------------------------------------------------------------------------
foreach ($aTests as $sTestName => $aTest) {
echo "==========| $sTestName |==> ".$aTest['host']." - ".$aTest['request']." \n";
// echo "To check\n";
// print_r($aTest);
// set data
$oR->setHost($aTest['host']);
$oR->setRequest($aTest['request']);
// verify
$bOk=true;
if ($oR->getRedirectTarget() != $aTest['target']) {
$bOk=false;
echo ">>>> CONFIG FAILED: target returned ".$oR->getRedirectTarget()." - not ".$aTest['target']."\n";
}
if ($oR->getRedirectCode() != $aTest['code']) {
$bOk=false;
echo ">>>> CONFIG FAILED: Redirect code retuned ".$oR->getRedirectCode()." - not ".$aTest['code']."\n";
}
if($bOk) {
echo ">>>> OK: redirects with ".$aTest['code']." to ".$aTest['target']."\n";
} else {
echo "Detected redirect from config\n";
print_r($oR->getRedirect());
echo "\n";
}
echo "\n";
}
echo "DONE\n";
// ------------------------------------------------------------------------
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment