ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
ilHtmlPurifierCompositeTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
25 {
26  private const array TO_PURIFY = [
27  'phpunit1',
28  'phpunit2',
29  'phpunit3',
30  ];
31 
33  {
34  return new class () implements ilHtmlPurifierInterface {
35  public function purify(string $html): string
36  {
37  return $html . '.';
38  }
39 
40  public function purifyArray(array $htmlCollection): array
41  {
42  foreach ($htmlCollection as &$html) {
43  $html .= '.';
44  }
45 
46  return $htmlCollection;
47  }
48  };
49  }
50 
52  {
53  $purifier = new ilHtmlPurifierComposite();
54 
55  $p1 = $this->getFakePurifier();
56  $p2 = clone $p1;
57  $p3 = clone $p1;
58 
59  $purifier->addPurifier($p1);
60  $purifier->addPurifier($p1);
61  $purifier->addPurifier($p2);
62  $purifier->addPurifier($p3);
63 
64  $this->assertSame('phpunit...', $purifier->purify('phpunit'));
65 
66  $purifier->removePurifier($p2);
67 
68  $this->assertSame('phpunit..', $purifier->purify('phpunit'));
69  }
70 
72  {
73  $purifier = new ilHtmlPurifierComposite();
74 
75  $p1 = $this->getFakePurifier();
76  $p2 = clone $p1;
77  $p3 = clone $p1;
78 
79  $purifier->addPurifier($p1);
80  $purifier->addPurifier($p1);
81  $purifier->addPurifier($p2);
82  $purifier->addPurifier($p3);
83 
84  $this->assertSame(array_map(static function (string $html): string {
85  return $html . '...';
86  }, self::TO_PURIFY), $purifier->purifyArray(self::TO_PURIFY));
87 
88  $purifier->removePurifier($p2);
89 
90  $this->assertSame(array_map(static function (string $html): string {
91  return $html . '..';
92  }, self::TO_PURIFY), $purifier->purifyArray(self::TO_PURIFY));
93  }
94 
98  public static 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 
111  #[DataProvider('invalidHtmlDataTypeProvider')]
113  {
114  $this->expectException(InvalidArgumentException::class);
115 
116  $purifier = new ilHtmlPurifierComposite();
117  $purifier->purifyArray([$element]);
118  }
119 }
Composite for nesting multiple purifiers.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
Interface for html sanitizing functionality.
testExceptionIsRaisedIfNonStringElementsArePassedForHtmlBatchProcessing($element)