ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilTermsOfServiceDocumentHtmlPurifierTest.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4use org\bovigo\vfs;
5
11{
15 private function isVsfStreamInstalled() : bool
16 {
17 return class_exists('org\bovigo\vfs\vfsStreamWrapper');
18 }
19
23 private function skipIfvfsStreamNotSupported()
24 {
25 if (!$this->isVsfStreamInstalled()) {
26 $this->markTestSkipped('Skipped test, vfsStream (http://vfs.bovigo.org) required');
27 }
28 }
29
33 public function documentTextProvider() : array
34 {
35 return [
36 [
37 '<h1><b>This</b> <i>is</i> <u>a</u> <em>Headline</em>!</h1><p>And a<br>paragraph.</p>',
38 '<h1><b>This</b> <i>is</i> <span style="text-decoration:underline;">a</span> <em>Headline</em>!</h1><p>And a<br />paragraph.</p>',
39 ],
40 [
41 '<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>',
42 '<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>',
43 ],
44 [
45 '<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>',
46 '<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>',
47 ],
48 [
49 '<pre>Text</pre><blockquote><cite><sup>Q</sup>uote</cite></blockquote>',
50 '<pre>Text</pre><blockquote><p><cite><sup>Q</sup>uote</cite></p></blockquote>',
51 ]
52 ];
53 }
54
61 public function testPurifyingWorksAsExpected(string $text, string $expected)
62 {
64
65 vfs\vfsStreamWrapper::register();
66 $root = vfs\vfsStreamWrapper::setRoot(new vfs\vfsStreamDirectory('root'));
67 $cacheDirectory = vfs\vfsStream::newDirectory('HTMLPurifier')->at($root);
68 $cacheDirectory->chmod(0777);
69
70 $purifier = new \ilTermsOfServiceDocumentHtmlPurifier(
71 [
72 "a", "blockquote", "br", "cite", "code", "dd", "div", "dl", "dt", "em", "h1", "h2", "h3", "h4", "h5",
73 "h6", "hr", "img", "li", "ol", "p", "pre", "span", "strong", "sub", "sup", "u", "ul"
74 ],
75 vfs\vfsStream::url('root/HTMLPurifier')
76 );
77 $this->assertEquals($expected, $purifier->purify($text));
78 }
79}
An exception for terminatinating execution or to throw for unit testing.
Class ilTermsOfServiceCriterionBaseTest.
Class ilTermsOfServiceDocumentHtmlPurifierTest.
testPurifyingWorksAsExpected(string $text, string $expected)
@dataProvider documentTextProvider
$root
Definition: sabredav.php:45
$text
Definition: errorreport.php:18