.
*/
declare(strict_types=1);
namespace Fisharebest\Webtrees;
use DOMDocument;
use function str_starts_with;
use const LIBXML_PEDANTIC;
abstract class AbstractViewTest extends TestCase
{
protected const EVIL_VALUE = '';
/**
* Check the view runs without error and generates valid HTML
*
* @param array> $data
*/
protected function doTestView(string $view, array $data): void
{
foreach ($this->cartesian($data) as $datum) {
$html = view($view, $datum);
$this->validateHTML($html);
}
}
/**
* @param array> $input
*
* @return array>
*/
private function cartesian(array $input): array
{
$result = [[]];
foreach ($input as $key => $values) {
$append = [];
foreach ($result as $product) {
foreach ($values as $item) {
$product[$key] = $item;
$append[] = $product;
}
}
$result = $append;
}
return $result;
}
protected function validateHTML(string $html): void
{
if (str_starts_with($html, '')) {
$xml = $html;
} else {
$xml = '' . $html . '';
}
$doc = new DOMDocument();
$doc->validateOnParse = true;
self::assertTrue($doc->loadXML($xml, LIBXML_PEDANTIC), $html);
}
}