ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
SanitizerPlaceholderTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use PHPUnit\Framework\TestCase;
24use ILIAS\Refinery\Factory as Refinery;
25
26class SanitizerPlaceholderTest extends TestCase
27{
28 protected const string HIGHLIGHT_START = '<span class="ilSearchHighlight">';
29 protected const string HIGHLIGHT_END = '</span>';
30 protected const string PLACEHOLDER_START = '[PLACEHOLDER_START]';
31 protected const string PLACEHOLDER_END = '[PLACEHOLDER_END]';
32
34 {
35 return new class () extends SanitizerImpl {
36 public function __construct()
37 {
38 }
39
40 public function sanitize(string $text): string
41 {
42 return $text;
43 }
44 };
45 }
46
47 public static function replacementMapProvider(
48 string $search_start,
49 string $search_end,
50 string $replace_start,
51 string $replace_end
52 ): array {
53 return [
54 ['', ''],
55 ['some text', 'some text'],
56 [
57 $search_start . 'some text' . $search_end,
58 $replace_start . 'some text' . $replace_end
59 ],
60 [
61 'text' . $search_start . 'some text' . $search_end
62 . 'some more text' . $search_start . 'final text' . $search_end,
63 'text' . $replace_start . 'some text' . $replace_end .
64 'some more text' . $replace_start . 'final text' . $replace_end
65 ],
66 ['text' . $search_start . 'some text', 'text' . $search_start . 'some text'],
67 ['text' . $search_end . 'some text', 'text' . $search_end . 'some text'],
68 [
69 $search_start . 'some text' . $search_end . 'text' . $search_end,
70 $replace_start . 'some text' . $replace_end . 'text' . $search_end
71 ],
72 [
73 $search_start . 'text' . $search_start . 'some text' . $search_end,
74 $replace_start . 'text' . $search_start . 'some text' . $replace_end
75 ],
76 [
77 $search_start . 'text' . $search_start . 'some text' . $search_end,
78 $replace_start . 'text' . $search_start . 'some text' . $replace_end
79 ],
80 [
81 $search_start . 'text' . $search_start . 'some text' . $search_end . 'more text' . $search_end,
82 $replace_start . 'text' . $search_start . 'some text' . $replace_end . 'more text' . $search_end
83 ]
84 ];
85 }
86
87 public static function textWithInitialPlaceholdersProvider(): array
88 {
89 return [
90 ['text' . self::PLACEHOLDER_START . 'more', 'textmore'],
91 ['text' . self::PLACEHOLDER_END . 'more', 'textmore'],
92 [
93 'text' . self::PLACEHOLDER_START . self::HIGHLIGHT_START . 'more' . self::HIGHLIGHT_END,
94 'text' . self::PLACEHOLDER_START . 'more' . self::PLACEHOLDER_END
95 ],
96 ];
97 }
98
99 public static function setUpPlaceholdersProvider(): array
100 {
101 return array_merge(
102 self::replacementMapProvider(
103 self::HIGHLIGHT_START,
104 self::HIGHLIGHT_END,
105 self::PLACEHOLDER_START,
106 self::PLACEHOLDER_END
107 ),
108 self::textWithInitialPlaceholdersProvider()
109 );
110 }
111
112 #[\PHPUnit\Framework\Attributes\DataProvider('setUpPlaceholdersProvider')]
113 public function testSetUpPlaceholders(
114 string $input,
115 string $expected_output
116 ): void {
117 $sanitizer = $this->getSanitizerWithoutSanitization();
118 $output = $sanitizer->sanitizeAndSetUpPlaceholders($input);
119 $this->assertSame($expected_output, $output);
120 }
121
122 public static function replacePlaceholdersProvider(): array
123 {
124 return self::replacementMapProvider(
125 self::PLACEHOLDER_START,
126 self::PLACEHOLDER_END,
127 self::HIGHLIGHT_START,
128 self::HIGHLIGHT_END
129 );
130 }
131
132 #[\PHPUnit\Framework\Attributes\DataProvider('replacePlaceholdersProvider')]
133 public function testReplacePlaceholders(
134 string $input,
135 string $expected_output
136 ): void {
137 $sanitizer = $this->getSanitizerWithoutSanitization();
138 $output = $sanitizer->replacePlaceholders($input);
139 $this->assertSame($expected_output, $output);
140 }
141}
Builds data types.
Definition: Factory.php:36
static replacementMapProvider(string $search_start, string $search_end, string $replace_start, string $replace_end)
__construct()
Constructor setup ILIAS global object @access public.
Definition: class.ilias.php:76
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$text
Definition: xapiexit.php:21