ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
TextareaTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once(__DIR__ . "/../../../../../../../vendor/composer/vendor/autoload.php");
22require_once(__DIR__ . "/../../../Base.php");
23require_once(__DIR__ . "/InputTest.php");
24require_once(__DIR__ . "/CommonFieldRendering.php");
25
29use ILIAS\Data;
30use ILIAS\Refinery\Factory as Refinery;
31
33{
34 use CommonFieldRendering;
35
37
38 public function setUp(): void
39 {
40 $this->name_source = new DefNamesource();
41 }
42
43 public function testImplementsFactoryInterface(): void
44 {
45 $f = $this->getFieldFactory();
46 $textarea = $f->textarea("label", "byline");
47 $this->assertInstanceOf(\ILIAS\UI\Component\Input\Container\Form\FormInput::class, $textarea);
48 $this->assertInstanceOf(Field\Textarea::class, $textarea);
49 }
50
52 {
53 $f = $this->getFieldFactory();
54 $textarea = $f->textarea("label");
55 $this->assertInstanceOf(\ILIAS\UI\Component\Input\Container\Form\FormInput::class, $textarea);
56 $this->assertInstanceOf(Field\Textarea::class, $textarea);
57 }
58
59 public function testWithMinLimit(): void
60 {
61 $f = $this->getFieldFactory();
62 $limit = 5;
63 $textarea = $f->textarea('label')->withMinLimit($limit);
64 $this->assertInstanceOf(\ILIAS\UI\Component\Input\Container\Form\FormInput::class, $textarea);
65 $this->assertInstanceOf(Field\Textarea::class, $textarea);
66 $this->assertEquals($textarea->getMinLimit(), $limit);
67 }
68
69 public function testWithMaxLimit(): void
70 {
71 $f = $this->getFieldFactory();
72 $limit = 15;
73 $textarea = $f->textarea('label')->withMaxLimit($limit);
74 $this->assertInstanceOf(\ILIAS\UI\Component\Input\Container\Form\FormInput::class, $textarea);
75 $this->assertInstanceOf(Field\Textarea::class, $textarea);
76 $this->assertEquals($textarea->getMaxLimit(), $limit);
77 }
78
79 public function testIsLimited(): void
80 {
81 $f = $this->getFieldFactory();
82
83 // with min limit
84 $textarea = $f->textarea('label')->withMinLimit(5);
85 $this->assertTrue($textarea->isLimited());
86
87 // with max limit
88 $textarea = $f->textarea('label')->withMaxLimit(5);
89 $this->assertTrue($textarea->isLimited());
90
91 // with min-max limit
92 $textarea = $f->textarea('label')->withMinLimit(5)->withMaxLimit(20);
93 $this->assertTrue($textarea->isLimited());
94
95 // without limit
96 $textarea = $f->textarea('label');
97 $this->assertFalse($textarea->isLimited());
98 }
99
100 public function testGetMinLimit(): void
101 {
102 $f = $this->getFieldFactory();
103 $limit = 5;
104 $textarea = $f->textarea('label')->withMinLimit($limit);
105 $this->assertEquals($textarea->getMinLimit(), $limit);
106 }
107
108 public function testGetMaxLimit(): void
109 {
110 $f = $this->getFieldFactory();
111 $limit = 15;
112 $textarea = $f->textarea('label')->withMaxLimit($limit);
113 $this->assertEquals($textarea->getMaxLimit(), $limit);
114 }
115
116 // RENDERER
117 public function testRenderer(): void
118 {
119 $f = $this->getFieldFactory();
120 $label = "label";
121 $byline = "byline";
122 $textarea = $f->textarea($label, $byline)->withNameFrom($this->name_source);
123 $expected = $this->getFormWrappedHtml(
124 'textarea-field-input',
125 $label,
126 '
127 <textarea id="id_1" class="c-field-textarea" name="name_0"></textarea>
128 ',
129 $byline,
130 'id_1',
131 'id_2',
132 );
133 $this->assertEquals($expected, $this->render($textarea));
134 }
135
136 public function testCommonRendering(): void
137 {
138 $f = $this->getFieldFactory();
139 $label = "label";
140 $textarea = $f->textarea($label)->withNameFrom($this->name_source);
141
142 $this->testWithError($textarea);
143 $this->testWithNoByline($textarea);
144 $this->testWithRequired($textarea);
145 $this->testWithDisabled($textarea);
146 $this->testWithAdditionalOnloadCodeRendersId($textarea);
147 }
148
149 public function testRendererWithMinLimit(): void
150 {
151 $f = $this->getFieldFactory();
152 $label = "label";
153 $min = 5;
154 $byline = "This is just a byline Min: " . $min;
155 $textarea = $f->textarea($label, $byline)->withMinLimit($min)->withNameFrom($this->name_source);
156 $expected = $this->getFormWrappedHtml(
157 'textarea-field-input',
158 $label,
159 '
160 <textarea id="id_1" class="c-field-textarea" name="name_0" minlength="5"></textarea>
161 ',
162 $byline,
163 'id_1',
164 'id_2'
165 );
166 $this->assertEquals($expected, $this->render($textarea));
167 }
168
169 public function testRendererWithMaxLimit(): void
170 {
171 $f = $this->getFieldFactory();
172 $label = "label";
173 $max = 20;
174 $byline = "This is just a byline Max: " . $max;
175 $textarea = $f->textarea($label, $byline)->withMaxLimit($max)->withNameFrom($this->name_source);
176 $expected = $this->getFormWrappedHtml(
177 'textarea-field-input',
178 $label,
179 '
180 <textarea id="id_1" class="c-field-textarea" name="name_0" maxlength="20"></textarea>
181 <div class="ui-input-textarea-remainder"> ui_chars_remaining<span data-action="remainder">20</span></div>
182 ',
183 $byline,
184 'id_1',
185 'id_2'
186 );
187 $this->assertEquals($expected, $this->render($textarea));
188 }
189
190 public function testRendererWithMinAndMaxLimit(): void
191 {
192 $f = $this->getFieldFactory();
193 $r = $this->getDefaultRenderer();
194 $name = "name_0";
195 $id = "id_1";
196 $label = "label";
197 $min = 5;
198 $max = 20;
199 $byline = "This is just a byline Min: " . $min . " Max: " . $max;
200 $textarea = $f->textarea($label, $byline)->withMinLimit($min)->withMaxLimit($max)->withNameFrom(
201 $this->name_source
202 );
203
204 $expected = $this->brutallyTrimHTML("
205 <textarea id=\"$id\" class=\"c-field-textarea\" name=\"$name\" minlength=\"5\" maxlength=\"20\"></textarea>
206 <div class=\"ui-input-textarea-remainder\"> ui_chars_remaining <span data-action=\"remainder\">$max</span> </div>
207 ");
208 $this->assertStringContainsString($expected, $this->render($textarea));
209 }
210
211 public function testRendererCounterWithValue(): void
212 {
213 $f = $this->getFieldFactory();
214 $id = 'id_1';
215 $label = "label";
216 $byline = "byline";
217 $name = "name_0";
218 $value = "Lorem ipsum dolor sit";
219 $textarea = $f->textarea($label, $byline)->withValue($value)->withNameFrom($this->name_source);
220
221 $expected = $this->brutallyTrimHTML("
222 <div class=\"c-input__field\">
223 <textarea id=\"$id\" class=\"c-field-textarea\" name=\"$name\">$value</textarea>
224 </div>
225 ");
226 $this->assertStringContainsString($expected, $this->render($textarea));
227 }
228
229 public function testStripsTags(): void
230 {
231 $f = $this->getFieldFactory();
232 $name = "name_0";
233 $text = $f->textarea("")
234 ->withNameFrom($this->name_source)
235 ->withInput(new DefInputData([$name => "<script>alert()</script>"]));
236
237 $content = $text->getContent();
238 $this->assertEquals("alert()", $content->value());
239 }
240
241 public function testWithoutStripsTags(): void
242 {
243 $f = $this->getFieldFactory();
244 $name = "name_0";
245 $text = $f->textarea("")
246 ->withNameFrom($this->name_source)
247 ->withoutStripTags()
248 ->withInput(new DefInputData([$name => "<script>alert()</script>"]));
249
250 $content = $text->getContent();
251 $this->assertEquals("<script>alert()</script>", $content->value());
252 }
253}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Builds data types.
Definition: Factory.php:36
Definition: UI.php:24
Provides common functionality for UI tests.
Definition: Base.php:337
testRendererWithMinLimit()
testImplementsFactoryInterface_without_byline()
DefNamesource $name_source
testRendererWithMaxLimit()
testRendererCounterWithValue()
testRendererWithMinAndMaxLimit()
testImplementsFactoryInterface()
This describes commonalities between all inputs.
Definition: Input.php:47
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Checkbox.php:21
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.