Add class MD_STD_HTML_TEST for validating HTML outputs
This commit is contained in:
parent
cbc66c4140
commit
40d83ce5b0
36
src/testing/MD_STD_HTML_TEST.php
Normal file
36
src/testing/MD_STD_HTML_TEST.php
Normal 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);
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user