Add class MD_STD_HTML_TEST for validating HTML outputs

This commit is contained in:
Joshua Ramon Enslin 2024-07-12 02:31:32 +02:00
parent cbc66c4140
commit 40d83ce5b0
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE

View File

@ -0,0 +1,36 @@
<?PHP
/**
* Test for ensuring that search HTML pages or components are generated correctly.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
*/
declare(strict_types = 1);
use PHPUnit\Framework\TestCase;
/**
* Tests for the manifest.
*/
abstract class MD_STD_HTML_TEST extends TestCase {
/**
* Validates HTML strings.
*
* @param string $input Input string to validate.
*
* @return void
*/
protected static function validateHtmlString(string $input):void {
self::assertNotEmpty($input);
libxml_use_internal_errors(true);
$xml = simplexml_load_string('<!DOCTYPE HTML><abc>' . trim(strtr($input, [' async' => ' ', ' defer' => ' '])) . '</abc>');
if (!empty($errors = libxml_get_errors())) {
throw new Exception("Invalid HTML code detected: " . var_export($errors, true) . PHP_EOL . PHP_EOL . $input);
}
self::assertNotEquals(null, $xml);
}
}