#!/usr/bin/env php
<?php
require_once(__DIR__ . '/../web-files/libs/sitesmith-html-sanitizer.php');

$cases = [
    ['<p>hi</p><script>alert(1)</script>',                ['<script','alert']],
    ['<a href="javascript:void(0)">x</a>',                ['javascript:']],
    ['<a onclick="doBad()" href="/ok">x</a>',             ['onclick']],
    ['<img src="data:text/html;base64,xxx">',             ['data:text/html']],
    ['<iframe src="https://evil.com/x"></iframe>',        ['evil.com']],
    ['<style>body{display:none}</style>',                 ['<style']],
    ['<form action="/x"><input name="p"></form>',         ['<form','<input']],
];
$ok = true;
foreach ($cases as $i => [$in, $bad]) {
    $out = sitesmith_sanitize_html($in);
    foreach ($bad as $b) if (stripos($out, $b) !== false) { $ok = false; fprintf(STDERR, "CASE %d FAIL: %s contains %s -> %s\n", $i, $in, $b, $out); }
}
$positive = [
    ['<p>hello</p>', '<p>hello</p>'],
    ['<a href="https://example.com" target="_blank">x</a>', 'example.com'],
    ['<iframe src="https://www.youtube.com/embed/abc" allowfullscreen></iframe>', 'youtube.com/embed/abc'],
];
foreach ($positive as $i => [$in, $expected]) {
    $out = sitesmith_sanitize_html($in);
    if (stripos($out, $expected) === false) { $ok = false; fprintf(STDERR, "POS %d FAIL: %s -> %s\n", $i, $in, $out); }
}
echo $ok ? "sanitizer OK\n" : "sanitizer FAIL\n";
exit($ok ? 0 : 1);
