Files
FDMTech/tests/run.php
T

50 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
// Minimalny smoke test renderera (tryb demo, bez bazy).
// Uruchomienie: php tests/run.php (lub: composer test)
$failures = 0;
$check = static function (string $name, bool $ok) use (&$failures): void {
echo ($ok ? "OK " : "FAIL ") . $name . PHP_EOL;
if (!$ok) {
$failures++;
}
};
$root = dirname(__DIR__);
putenv('APP_DEMO=true');
$_SERVER['APP_DEMO'] = 'true';
$fetch = static function (string $path, string $method = 'GET', array $post = []) use ($root): array {
$cmd = 'APP_DEMO=true php -r ' . escapeshellarg(
'$_SERVER["REQUEST_METHOD"]=' . var_export($method, true) . ';'
. '$_SERVER["REQUEST_URI"]=' . var_export($path, true) . ';'
. '$_GET=[];$_POST=' . var_export($post, true) . ';'
. 'chdir(' . var_export($root . '/public', true) . ');'
. 'http_response_code(200);ob_start();require ' . var_export($root . '/public/index.php', true) . ';'
. '$b=ob_get_clean();echo "STATUS:".http_response_code()."\n".$b;'
);
$out = shell_exec($cmd) ?? '';
[$head, $body] = explode("\n", $out, 2) + ['', ''];
return [(int) trim(str_replace('STATUS:', '', $head)), $body];
};
[$code, $home] = $fetch('/');
$check('GET / zwraca 200 w demo', $code === 200);
$check('jeden <main> i jedno #cms-content', substr_count($home, '<main') === 1 && substr_count($home, 'cms-content') >= 1);
$check('demo ma noindex', str_contains($home, 'noindex'));
$check('brak adresu panelu w HTML', !str_contains($home, 'sensory.fdmtech.pl'));
$check('brak roszczeń środowiskowych', !preg_match('/temperatura|wilgotno|ciśnienie/i', $home));
[$code, $contact] = $fetch('/kontakt');
$check('GET /kontakt zwraca 200 w demo', $code === 200);
$check('formularz ma CSRF i honeypot', str_contains($contact, '_csrf') && str_contains($contact, 'name="website"'));
[$code] = $fetch('/nie-istnieje');
$check('nieznany slug zwraca 404', $code === 404);
[$code] = $fetch('/inquiries', 'POST', ['name' => 'X', 'email' => 'x@y.pl', 'message' => 'm', 'consent' => '1']);
$check('POST w demo zwraca 503 (brak fikcyjnego sukcesu)', $code === 503);
exit($failures === 0 ? 0 : 1);