ILIAS  release_8 Revision v8.24
ilTermsOfServiceDocumentHtmlPurifierTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use org\bovigo\vfs;
22
28{
29 private function isVsfStreamInstalled(): bool
30 {
31 return class_exists('org\bovigo\vfs\vfsStreamWrapper');
32 }
33
34 private function skipIfvfsStreamNotSupported(): void
35 {
36 if (!$this->isVsfStreamInstalled()) {
37 $this->markTestSkipped('Skipped test, vfsStream (https://github.com/bovigo/vfsStream) required');
38 }
39 }
40
41 public function documentTextProvider(): array
42 {
43 return [
44 'Simple HTML Elements' => [
45 '<h1><b>This</b> <i>is</i> <u>a</u> <em>Headline</em>!</h1><p>And a<br>paragraph.</p>',
46 '<h1><b>This</b> <i>is</i> <span style="text-decoration:underline;">a</span> <em>Headline</em>!</h1><p>And a<br />paragraph.</p>',
47 ],
48 'Simple HTML Elements with an Invalid Tag' => [
49 '<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>',
50 '<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>',
51 ],
52 'Block Elements and Nested Lists' => [
53 '<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>',
54 '<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>',
55 ],
56 'Blockquote' => [
57 '<pre>Text</pre><blockquote><cite><sup>Q</sup>uote</cite></blockquote>',
58 '<pre>Text</pre><blockquote><p><cite><sup>Q</sup>uote</cite></p></blockquote>',
59 ]
60 ];
61 }
62
68 public function testPurifyingWorksAsExpected(string $text, string $expected): void
69 {
71
72 vfs\vfsStreamWrapper::register();
73 $root = vfs\vfsStreamWrapper::setRoot(new vfs\vfsStreamDirectory('root'));
74 $cacheDirectory = vfs\vfsStream::newDirectory('HTMLPurifier')->at($root);
75 $cacheDirectory->chmod(0777);
76
78 [
79 'a',
80 'blockquote',
81 'br',
82 'cite',
83 'code',
84 'dd',
85 'div',
86 'dl',
87 'dt',
88 'em',
89 'h1',
90 'h2',
91 'h3',
92 'h4',
93 'h5',
94 'h6',
95 'hr',
96 'img',
97 'li',
98 'ol',
99 'p',
100 'pre',
101 'span',
102 'strong',
103 'sub',
104 'sup',
105 'u',
106 'ul'
107 ],
108 vfs\vfsStream::url('root/HTMLPurifier')
109 );
110 $this->assertSame($expected, $purifier->purify($text));
111 }
112}
Class ilTermsOfServiceCriterionBaseTest.
Class ilTermsOfServiceDocumentHtmlPurifierTest.
testPurifyingWorksAsExpected(string $text, string $expected)
@dataProvider documentTextProvider