ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
TagInputTest Class Reference

Class TagInputTest. More...

+ Inheritance diagram for TagInputTest:
+ Collaboration diagram for TagInputTest:

Public Member Functions

 setUp ()
 
 testImplementsFactoryInterface ()
 
 testRender ()
 
 testCommonRendering ()
 
 testNullValueLeadsToException ()
 
 testUserCreatedNotAllowed ()
 
 testMaxTagsOk ()
 
 testMaxTagsNotOk ()
 
 testMaxTaglengthTagsOk ()
 
 testMaxTaglengthTagsNotOk ()
 
 testUITagInputSpecialChars (string ... $tags)
 @dataProvider getUITagSpecialCharValues More...
 
 testTagWithAutocompleteEndpoint ()
 
 testTagWithAutocompleteEndpointJSAdded ()
 

Static Public Member Functions

static getUITagSpecialCharValues ()
 

Protected Attributes

DefNamesource $name_source
 

Detailed Description

Class TagInputTest.

Author
Fabian Schmid fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch

Definition at line 36 of file TagInputTest.php.

Member Function Documentation

◆ getUITagSpecialCharValues()

static TagInputTest::getUITagSpecialCharValues ( )
static

Definition at line 235 of file TagInputTest.php.

235 : array
236 {
237 return [
238 ['1', '2', '3'],
239 ['++1#*', '[-2]', '{?3}'],
240 ['some\'thing "else"', '&/\\'],
241 ['fünf, sechs', 'sieben, acht'],
242 ];
243 }

◆ setUp()

TagInputTest::setUp ( )

Definition at line 42 of file TagInputTest.php.

42 : void
43 {
44 $this->name_source = new DefNamesource();
45 }

◆ testCommonRendering()

TagInputTest::testCommonRendering ( )

Definition at line 81 of file TagInputTest.php.

81 : void
82 {
83 $f = $this->getFieldFactory();
84 $tag = $f->tag('label', [], null)->withNameFrom($this->name_source);
85
86 $this->testWithError($tag);
87 $this->testWithNoByline($tag);
88 $this->testWithRequired($tag);
89 $this->testWithDisabled($tag);
90 $this->testWithAdditionalOnloadCodeRendersId($tag);
91 }

References Vendor\Package\$f.

◆ testImplementsFactoryInterface()

TagInputTest::testImplementsFactoryInterface ( )

Definition at line 48 of file TagInputTest.php.

48 : void
49 {
50 $f = $this->getFieldFactory();
51
52 $f->tag(
53 "label",
54 ["lorem", "ipsum", "dolor"],
55 "byline"
56 );
57 }

References Vendor\Package\$f.

◆ testMaxTaglengthTagsNotOk()

TagInputTest::testMaxTaglengthTagsNotOk ( )

Definition at line 223 of file TagInputTest.php.

223 : void
224 {
225 $f = $this->getFieldFactory();
226
227 $this->expectException(InvalidArgumentException::class);
228 $f->tag("label", [])->withTagMaxLength(2)->withNameFrom($this->name_source)->withInput(
229 new DefInputData(
230 ["name_0" => "lorem,ipsum,dolor"]
231 )
232 );
233 }

References Vendor\Package\$f.

◆ testMaxTaglengthTagsOk()

TagInputTest::testMaxTaglengthTagsOk ( )

Definition at line 212 of file TagInputTest.php.

212 : void
213 {
214 $f = $this->getFieldFactory();
215
216 $tag = $f->tag("label", [])->withTagMaxLength(10)->withNameFrom($this->name_source)->withInput(
217 new DefInputData(["name_0" => "lorem,ipsum"])
218 );
219 $value = $tag->getContent();
220 $this->assertTrue($value->isOk());
221 }

References Vendor\Package\$f.

◆ testMaxTagsNotOk()

TagInputTest::testMaxTagsNotOk ( )

Definition at line 200 of file TagInputTest.php.

200 : void
201 {
202 $f = $this->getFieldFactory();
203
204 $this->expectException(InvalidArgumentException::class);
205 $f->tag("label", [])->withMaxTags(2)->withNameFrom($this->name_source)->withInput(
206 new DefInputData(
207 ["name_0" => "lorem,ipsum,dolor"]
208 )
209 );
210 }

References Vendor\Package\$f.

◆ testMaxTagsOk()

TagInputTest::testMaxTagsOk ( )

Definition at line 189 of file TagInputTest.php.

189 : void
190 {
191 $f = $this->getFieldFactory();
192
193 $tag = $f->tag("label", [])->withMaxTags(3)->withNameFrom($this->name_source)->withInput(
194 new DefInputData(["name_0" => "lorem,ipsum"])
195 );
196 $value = $tag->getContent();
197 $this->assertTrue($value->isOk());
198 }

References Vendor\Package\$f.

◆ testNullValueLeadsToException()

TagInputTest::testNullValueLeadsToException ( )

Definition at line 146 of file TagInputTest.php.

146 : void
147 {
148 $f = $this->getFieldFactory();
149 $label = "label";
150 $name = "name_0";
151 $tags = ["lorem", "ipsum", "dolor",];
152
153 $tag = $f->tag($label, $tags)->withNameFrom($this->name_source)->withRequired(true);
154 $tag2 = $tag->withInput(new DefInputData([$name => null]));
155 $value2 = $tag2->getContent();
156 $this->assertTrue($value2->isError());
157 }

References Vendor\Package\$f.

◆ testRender()

TagInputTest::testRender ( )

Definition at line 59 of file TagInputTest.php.

59 : void
60 {
61 $f = $this->getFieldFactory();
62 $label = "label";
63 $byline = "byline";
64 $tags = ["lorem", "ipsum", "dolor",];
65 $tag = $f->tag($label, $tags, $byline)->withNameFrom($this->name_source);
66 $expected = $this->getFormWrappedHtml(
67 'tag-field-input',
68 $label,
69 '
70 <div class="c-field-tag__wrapper">
71 <input id="id_1" name="name_0" class="c-field-tag" value=""/>
72 </div>
73 ',
74 $byline,
75 'id_1',
76 'id_2'
77 );
78 $this->assertEquals($expected, $this->render($tag));
79 }

References Vendor\Package\$f.

◆ testTagWithAutocompleteEndpoint()

TagInputTest::testTagWithAutocompleteEndpoint ( )

Definition at line 269 of file TagInputTest.php.

269 : void
270 {
271 $url_builder = new URLBuilder(new Data\URI('http://wwww.ilias.de?ref_id=1'));
272 $token = new URLBuilderToken(['t'], 't');
273 $f = $this->getFieldFactory();
274 $tag = $f->tag('my_tag', []);
275
276 $this->assertEquals(null, $tag->getAsyncAutocompleteEndpoint());
277 $this->assertEquals(null, $tag->getAsyncAutocompleteToken());
278
279 $tag = $tag->withAsyncAutocomplete(
280 $url_builder,
281 $token
282 );
283 $this->assertEquals($url_builder, $tag->getAsyncAutocompleteEndpoint());
284 $this->assertEquals($token, $tag->getAsyncAutocompleteToken());
285 }
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
$token
Definition: xapitoken.php:70

References Vendor\Package\$f, and $token.

◆ testTagWithAutocompleteEndpointJSAdded()

TagInputTest::testTagWithAutocompleteEndpointJSAdded ( )

Definition at line 287 of file TagInputTest.php.

287 : void
288 {
289 $token = $this->createMock(URLBuilderToken::class);
290 $token->expects($this->once())
291 ->method('render');
292 $url_builder = $this->createMock(URLBuilder::class);
293 $url_builder->expects($this->once())
294 ->method('renderObject')
295 ->with([$token]);
296
297 $f = $this->getFieldFactory();
298 $tag = $f->tag('my_tag', [])->withAsyncAutocomplete(
299 $url_builder,
300 $token
301 );
302
303 $renderer = $this->getDefaultRenderer();
304 $renderer->render($tag);
305 }
$renderer

References Vendor\Package\$f, $renderer, and $token.

◆ testUITagInputSpecialChars()

TagInputTest::testUITagInputSpecialChars ( string ...  $tags)

@dataProvider getUITagSpecialCharValues

Definition at line 246 of file TagInputTest.php.

246 : void
247 {
248 $f = $this->getFieldFactory();
249 $name = "name_0";
250 $tag = $f->tag('', $tags)->withNameFrom($this->name_source);
251
252 $encoded_tags = array_map('rawurlencode', $tags);
253
254 $this->assertEquals(
255 $encoded_tags,
256 array_map(
257 fn($o) => $o['value'],
258 $tag->getConfiguration(fn(string $txt) => $txt)->options
259 )
260 );
261
262 $raw_value = implode(',', $encoded_tags);
263 $tag_with_input = $tag->withInput(new DefInputData([$name => $raw_value]));
264 $content = $tag_with_input->getContent();
265 $this->assertTrue($content->isOk());
266 $this->assertEquals($tags, $content->value());
267 }
$txt
Definition: error.php:31

References Vendor\Package\$f, and $txt.

◆ testUserCreatedNotAllowed()

TagInputTest::testUserCreatedNotAllowed ( )

Definition at line 159 of file TagInputTest.php.

159 : void
160 {
161 $this->markTestSkipped("This is supposed to work, but currently does not.");
162
163 $f = $this->getFieldFactory();
164 $tags = ["lorem", "ipsum", "dolor",];
165 $tag = $f->tag("label", $tags)->withUserCreatedTagsAllowed(false)->withNameFrom($this->name_source);
166
167 $tag1 = $tag->withInput(
168 new DefInputData(
169 ["name_0" => "lorem,ipsum"]
170 )
171 );
172 $value1 = $tag1->getContent();
173 $this->assertTrue($value1->isOk());
174 $value = $value1->value();
175 $this->assertEquals(
176 ["lorem", "ipsum"],
177 $value
178 );
179
180 $tag1 = $tag->withInput(
181 new DefInputData(
182 ["name_0" => "conseptetuer,ipsum"]
183 )
184 );
185 $value1 = $tag1->getContent();
186 $this->assertTrue($value1->isError());
187 }

References Vendor\Package\$f.

Field Documentation

◆ $name_source

DefNamesource TagInputTest::$name_source
protected

Definition at line 40 of file TagInputTest.php.


The documentation for this class was generated from the following file: