ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilHtmlPurifierCompositeTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
28 {
29  private const TO_PURIFY = [
30  'phpunit1',
31  'phpunit2',
32  'phpunit3',
33  ];
34 
36  {
37  return new class () implements ilHtmlPurifierInterface {
38  public function purify(string $html): string
39  {
40  return $html . '.';
41  }
42 
43  public function purifyArray(array $htmlCollection): array
44  {
45  foreach ($htmlCollection as &$html) {
46  $html .= '.';
47  }
48 
49  return $htmlCollection;
50  }
51  };
52  }
53 
55  {
56  $purifier = new ilHtmlPurifierComposite();
57 
58  $p1 = $this->getFakePurifier();
59  $p2 = clone $p1;
60  $p3 = clone $p1;
61 
62  $purifier->addPurifier($p1);
63  $purifier->addPurifier($p1);
64  $purifier->addPurifier($p2);
65  $purifier->addPurifier($p3);
66 
67  $this->assertSame('phpunit...', $purifier->purify('phpunit'));
68 
69  $purifier->removePurifier($p2);
70 
71  $this->assertSame('phpunit..', $purifier->purify('phpunit'));
72  }
73 
75  {
76  $purifier = new ilHtmlPurifierComposite();
77 
78  $p1 = $this->getFakePurifier();
79  $p2 = clone $p1;
80  $p3 = clone $p1;
81 
82  $purifier->addPurifier($p1);
83  $purifier->addPurifier($p1);
84  $purifier->addPurifier($p2);
85  $purifier->addPurifier($p3);
86 
87  $this->assertSame(array_map(static function (string $html): string {
88  return $html . '...';
89  }, self::TO_PURIFY), $purifier->purifyArray(self::TO_PURIFY));
90 
91  $purifier->removePurifier($p2);
92 
93  $this->assertSame(array_map(static function (string $html): string {
94  return $html . '..';
95  }, self::TO_PURIFY), $purifier->purifyArray(self::TO_PURIFY));
96  }
97 
101  public static function invalidHtmlDataTypeProvider(): array
102  {
103  return [
104  'integer' => [5],
105  'float' => [0.1],
106  'null' => [null],
107  'array' => [[]],
108  'object' => [new stdClass()],
109  'bool' => [false],
110  'resource' => [fopen('php://memory', 'rb')],
111  ];
112  }
113 
118  {
119  $this->expectException(InvalidArgumentException::class);
120 
121  $purifier = new ilHtmlPurifierComposite();
122  $purifier->purifyArray([$element]);
123  }
124 }
Composite for nesting multiple purifiers.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
Interface for html sanitizing functionality.
testExceptionIsRaisedIfNonStringElementsArePassedForHtmlBatchProcessing($element)
invalidHtmlDataTypeProvider
Class ilHtmlPurifierCompositeTest.