ILIAS  release_8 Revision v8.24
ilHtmlPurifierCompositeTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use PHPUnit\Framework\TestCase;
22
27class ilHtmlPurifierCompositeTest extends TestCase
28{
30 {
31 return new class () implements ilHtmlPurifierInterface {
32 public function purify(string $html): string
33 {
34 return $html . '.';
35 }
36
37 public function purifyArray(array $htmlCollection): array
38 {
39 foreach ($htmlCollection as $key => &$html) {
40 $html .= '.';
41 }
42
43 return $htmlCollection;
44 }
45 };
46 }
47
49 {
50 $purifier = new ilHtmlPurifierComposite();
51
52 $p1 = $this->getFakePurifier();
53 $p2 = clone $p1;
54 $p3 = clone $p1;
55
56 $purifier->addPurifier($p1);
57 $purifier->addPurifier($p1);
58 $purifier->addPurifier($p2);
59 $purifier->addPurifier($p3);
60
61 $this->assertSame('phpunit...', $purifier->purify('phpunit'));
62
63 $purifier->removePurifier($p2);
64
65 $this->assertSame('phpunit..', $purifier->purify('phpunit'));
66 }
67
69 {
70 $purifier = new ilHtmlPurifierComposite();
71
72 $p1 = $this->getFakePurifier();
73 $p2 = clone $p1;
74 $p3 = clone $p1;
75
76 $purifier->addPurifier($p1);
77 $purifier->addPurifier($p1);
78 $purifier->addPurifier($p2);
79 $purifier->addPurifier($p3);
80
81 $toPurify = [
82 'phpunit1',
83 'phpunit2',
84 'phpunit3',
85 ];
86
87 $this->assertSame(array_map(static function (string $html): string {
88 return $html . '...';
89 }, $toPurify), $purifier->purifyArray($toPurify));
90
91 $purifier->removePurifier($p2);
92
93 $this->assertSame(array_map(static function (string $html): string {
94 return $html . '..';
95 }, $toPurify), $purifier->purifyArray($toPurify));
96 }
97
98 public function invalidHtmlDataTypeProvider(): array
99 {
100 return [
101 'integer' => [5],
102 'float' => [0.1],
103 'null' => [null],
104 'array' => [[]],
105 'object' => [new stdClass()],
106 'bool' => [false],
107 'resource' => [fopen('php://memory', 'rb')],
108 ];
109 }
110
115 {
116 $this->expectException(InvalidArgumentException::class);
117
118 $purifier = new ilHtmlPurifierComposite();
119 $purifier->purifyArray([$element]);
120 }
121}
Class ilHtmlPurifierCompositeTest.
testExceptionIsRaisedIfNonStringElementsArePassedForHtmlBatchProcessing($element)
@dataProvider invalidHtmlDataTypeProvider
Composite for nesting multiple purifiers.
Interface for html sanitizing functionality.
string $key
Consumer key/client ID value.
Definition: System.php:193