19 declare(strict_types=1);
35 vfsStreamWrapper::register();
36 $root = vfsStreamWrapper::setRoot(
new vfsStreamDirectory(
'root'));
37 $cache_directory = vfsStream::newDirectory(
'HTMLPurifier')->at($root);
38 $cache_directory->chmod(0777);
40 $this->assertInstanceOf(HTMLPurifier::class,
new HTMLPurifier([], vfsStream::url(
'root/HTMLPurifier')));
43 #[DataProvider('documents')] 44 public function testPurify(
string $input,
string $expected): void
47 vfsStreamWrapper::register();
48 $root = vfsStreamWrapper::setRoot(
new vfsStreamDirectory(
'root'));
49 $cache_directory = vfsStream::newDirectory(
'HTMLPurifier')->at($root);
50 $cache_directory->chmod(0777);
53 'a',
'blockquote',
'br',
'cite',
'code',
'dd',
'div',
'dl',
'dt',
'em',
'h1',
'h2',
'h3',
'h4',
54 'h5',
'h6',
'hr',
'img',
'li',
'ol',
'p',
'pre',
'span',
'strong',
'sub',
'sup',
'u',
'ul',
55 ], vfsStream::url(
'root/HTMLPurifier'));
57 $this->assertSame($expected, $instance->purify($input));
63 'Simple HTML Elements' => [
64 '<h1><b>This</b> <i>is</i> <u>a</u> <em>Headline</em>!</h1><p>And a<br>paragraph.</p>',
65 '<h1><b>This</b> <i>is</i> <span style="text-decoration:underline;">a</span> <em>Headline</em>!</h1><p>And a<br />paragraph.</p>',
67 'Simple HTML Elements with an Invalid Tag' => [
68 '<h1>This is a <a href="mailto:info@ilias.de">Headline</a>!</h1><p>And a paragraph with an invalid element: ILIAS e.V. <info@ilias.de>.</p>',
69 '<h1>This is a <a href="mailto:info@ilias.de">Headline</a>!</h1><p>And a paragraph with an invalid element: ILIAS e.V. .</p>',
71 'Block Elements and Nested Lists' => [
72 '<div><ul><li>Php</li></ul><hr><ol><li>Unit</li></ol><dl><dt>Test</dt><dd><code>Success or Failure!</code></dd></dl></div>',
73 '<div><ul><li>Php</li></ul><hr /><ol><li>Unit</li></ol><dl><dt>Test</dt><dd><code>Success or Failure!</code></dd></dl></div>',
76 '<pre>Text</pre><blockquote><cite><sup>Q</sup>uote</cite></blockquote>',
77 '<pre>Text</pre><blockquote><p><cite><sup>Q</sup>uote</cite></p></blockquote>',
84 return class_exists(
'org\bovigo\vfs\vfsStreamWrapper');
90 $this->markTestSkipped(
'Skipped test, vfsStream (https://github.com/bovigo/vfsStream) required');
skipIfvfsStreamNotSupported()
testPurify(string $input, string $expected)