ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
SwitchableGroupInputTest Class Reference
+ Inheritance diagram for SwitchableGroupInputTest:
+ Collaboration diagram for SwitchableGroupInputTest:

Public Member Functions

 setUp ()
 
 testWithDisabledDisablesChildren ()
 
 testWithRequiredDoesNotRequire ()
 
 testSwitchableGroupMayOnlyHaveGroupChildren ()
 
 testSwitchableGroupForwardsValuesOnWithValue ()
 
 testGroupOnlyDoesNoAcceptArrayValuesWithWrongLength ()
 
 testGroupOnlyDoesAcceptKeyOnly ()
 
 testGroupOnlyDoesNotAcceptInvalidKey ()
 
 testGroupForwardsValuesOnGetValue ()
 
 testWithInputCallsChildrenAndAppliesOperations ()
 
 testWithInputDoesNotApplyOperationsOnError ()
 
 testErrorIsI18NOnError ()
 
 testWithInputDoesNotAcceptUnknownKeys ()
 
 testRender ()
 
 testRenderWithValue (SG $sg)
 
 testRenderWithValueByIndex ()
 
 testCommonRendering ()
 

Protected Member Functions

 buildFactory ()
 

Protected Attributes

 $child1
 
 $child2
 
 $nested_child
 
 $lng
 
Data Factory $data_factory
 
Refinery $refinery
 
ILIAS UI Component Input Field Group $switchable_group
 
SwitchableGroup $group
 

Detailed Description

Definition at line 48 of file SwitchableGroupInputTest.php.

Member Function Documentation

◆ buildFactory()

SwitchableGroupInputTest::buildFactory ( )
protected

Definition at line 119 of file SwitchableGroupInputTest.php.

119 : I\Input\Field\Factory
120 {
121 return new I\Input\Field\Factory(
122 $this->createMock(\ILIAS\UI\Implementation\Component\Input\Field\Node\Factory::class),
123 $this->createMock(\ILIAS\UI\Implementation\Component\Input\UploadLimitResolver::class),
124 new SignalGenerator(),
125 $this->data_factory,
126 $this->refinery,
127 $this->lng
128 );
129 }
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.

References ILIAS\Repository\lng(), and ILIAS\Repository\refinery().

Referenced by testRender(), and testRenderWithValueByIndex().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setUp()

SwitchableGroupInputTest::setUp ( )

Definition at line 77 of file SwitchableGroupInputTest.php.

77 : void
78 {
79 $this->nested_child = $this->createMock(I\Input\Field\FormInputInternal::class);
80 $this->child1 = $this->createMock(Group1::class);
81 $this->child2 = $this->createMock(Group2::class);
82 $this->data_factory = new Data\Factory();
83 $this->refinery = new Refinery($this->data_factory, $this->createMock(ILIAS\Language\Language::class));
84 $this->lng = $this->createMock(ILIAS\Language\Language::class);
85
86 $this->nested_child
87 ->method("withNameFrom")
88 ->willReturn($this->nested_child);
89
90 $this->child1
91 ->method("withNameFrom")
92 ->willReturn($this->child1);
93 $this->child1
94 ->method("getInputs")
95 ->willReturn([$this->nested_child]);
96
97 $this->child2
98 ->method("withNameFrom")
99 ->willReturn($this->child2);
100 $this->child2
101 ->method("getInputs")
102 ->willReturn([$this->nested_child]);
103
104 $this->switchable_group = (new SwitchableGroup(
105 $this->data_factory,
106 $this->refinery,
107 $this->lng,
108 ["child1" => $this->child1, "child2" => $this->child2],
109 "LABEL",
110 "BYLINE"
111 ))->withNameFrom(new class () implements NameSource {
112 public function getNewName(): string
113 {
114 return "name0";
115 }
116 });
117 }
Describes a source for input names.
Definition: NameSource.php:27
withNameFrom(NameSource $source, ?string $parent_name=null)
@inheritDoc

References ILIAS\Repository\lng(), ILIAS\Repository\refinery(), and ILIAS\UI\Implementation\Component\Input\ViewControl\withNameFrom().

+ Here is the call graph for this function:

◆ testCommonRendering()

SwitchableGroupInputTest::testCommonRendering ( )

Definition at line 504 of file SwitchableGroupInputTest.php.

504 : void
505 {
506 $f = $this->getFieldFactory();
507 $label = "label";
508
509 $group1 = $f->group([
510 "field_1" => $f->text("f")
511 ]);
512 $group2 = $f->group([
513 "field_2" => $f->text("f2")
514 ]);
515
516 $sg = $f->switchableGroup(
517 [
518 "g1" => $group1,
519 "g2" => $group2
520 ],
521 $label
522 )->withNameFrom((new DefNamesource()));
523
524 $this->testWithError($sg);
525 $this->testWithNoByline($sg);
526 $this->testWithRequired($sg);
527 $this->testWithDisabled($sg);
528 $this->testWithAdditionalOnloadCodeRendersId($sg);
529 }

References Vendor\Package\$f.

◆ testErrorIsI18NOnError()

SwitchableGroupInputTest::testErrorIsI18NOnError ( )

Definition at line 345 of file SwitchableGroupInputTest.php.

345 : void
346 {
347 $this->assertNotSame($this->child1, $this->child2);
348
349 $input_data = $this->createMock(InputData::class);
350
351 $input_data
352 ->expects($this->once())
353 ->method("getOr")
354 ->with("name0")
355 ->willReturn("child2");
356
357 $this->child2
358 ->method("withInput")
359 ->willReturn($this->child2);
360 $this->child2
361 ->method("getContent")
362 ->willReturn($this->data_factory->error(""));
363
364 $i18n = "THERE IS SOME ERROR IN THIS GROUP";
365 $this->lng
366 ->expects($this->once())
367 ->method("txt")
368 ->with("ui_error_in_group")
369 ->willReturn($i18n);
370
371 $switchable_group = $this->switchable_group
372 ->withInput($input_data);
373
374 $this->assertTrue($switchable_group->getContent()->isError());
375 $this->assertEquals($i18n, $switchable_group->getContent()->error());
376 }
ILIAS UI Component Input Field Group $switchable_group

References $switchable_group, and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ testGroupForwardsValuesOnGetValue()

SwitchableGroupInputTest::testGroupForwardsValuesOnGetValue ( )

Definition at line 228 of file SwitchableGroupInputTest.php.

228 : void
229 {
230 $this->assertNotSame($this->child1, $this->child2);
231
232 $this->child1
233 ->expects($this->once())
234 ->method("getValue")
235 ->with()
236 ->willReturn("one");
237 $this->child2
238 ->expects($this->never())
239 ->method("getValue");
240
241 $vals = $this->switchable_group->withValue("child1")->getValue();
242
243 $this->assertEquals(["child1", "one"], $vals);
244 }

◆ testGroupOnlyDoesAcceptKeyOnly()

SwitchableGroupInputTest::testGroupOnlyDoesAcceptKeyOnly ( )

Definition at line 214 of file SwitchableGroupInputTest.php.

214 : void
215 {
216 $new_group = $this->switchable_group->withValue("child1");
217 $this->assertEquals(["child1" => $this->child1, "child2" => $this->child2], $new_group->getInputs());
218 $this->assertInstanceOf(SwitchableGroup::class, $new_group);
219 $this->assertNotSame($this->switchable_group, $new_group);
220 }

◆ testGroupOnlyDoesNoAcceptArrayValuesWithWrongLength()

SwitchableGroupInputTest::testGroupOnlyDoesNoAcceptArrayValuesWithWrongLength ( )

Definition at line 208 of file SwitchableGroupInputTest.php.

208 : void
209 {
210 $this->expectException(InvalidArgumentException::class);
211 $this->switchable_group->withValue([1, 2, 3]);
212 }

◆ testGroupOnlyDoesNotAcceptInvalidKey()

SwitchableGroupInputTest::testGroupOnlyDoesNotAcceptInvalidKey ( )

Definition at line 222 of file SwitchableGroupInputTest.php.

222 : void
223 {
224 $this->expectException(InvalidArgumentException::class);
225 $this->switchable_group->withValue("child3");
226 }

◆ testRender()

SwitchableGroupInputTest::testRender ( )

Definition at line 410 of file SwitchableGroupInputTest.php.

410 : SG
411 {
412 $f = $this->buildFactory();
413 $label = "label";
414 $byline = "byline";
415
416 $group1 = $f->group([
417 "field_1" => $f->text("f", "some field")
418 ]);
419 $group2 = $f->group([
420 "field_2" => $f->text("f2", "some other field")
421 ]);
422
423 $sg = $f->switchableGroup(
424 [
425 "g1" => $group1,
426 "g2" => $group2
427 ],
428 $label,
429 $byline
430 );
431
432 $expected = <<<EOT
433<fieldset class="c-input" data-il-ui-component="switchable-group-field-input" data-il-ui-input-name="" tabindex="0">
434 <label>label</label>
435 <div class="c-input__field">
436 <fieldset class="c-input" data-il-ui-component="group-field-input" data-il-ui-input-name="">
437 <label for="id_1">
438 <input type="radio" id="id_1" value="g1" />
439 <span></span>
440 </label>
441 <div class="c-input__field">
442 <fieldset class="c-input" data-il-ui-component="text-field-input" data-il-ui-input-name=""><label
443 for="id_2">f</label>
444 <div class="c-input__field"><input id="id_2" type="text" class="c-field-text" /></div>
445 <div class="c-input__help-byline">some field</div>
446 </fieldset>
447 </div>
448 </fieldset>
449 <fieldset class="c-input" data-il-ui-component="group-field-input" data-il-ui-input-name="">
450 <label for="id_3">
451 <input type="radio" id="id_3" value="g2" />
452 <span></span>
453 </label>
454 <div class="c-input__field">
455 <fieldset class="c-input" data-il-ui-component="text-field-input" data-il-ui-input-name=""><label
456 for="id_4">f2</label>
457 <div class="c-input__field"><input id="id_4" type="text" class="c-field-text" /></div>
458 <div class="c-input__help-byline">some other field</div>
459 </fieldset>
460 </div>
461 </fieldset>
462 </div>
463 <div class="c-input__help-byline">byline</div>
464</fieldset>
465EOT;
466 $this->assertEquals(
467 $this->brutallyTrimHTML($expected),
468 $this->renderInsideContainer($sg)
469 );
470 return $sg;
471 }

References Vendor\Package\$f, buildFactory(), and ILIAS\Repository\ui().

+ Here is the call graph for this function:

◆ testRenderWithValue()

SwitchableGroupInputTest::testRenderWithValue ( SG  $sg)

Definition at line 474 of file SwitchableGroupInputTest.php.

474 : void
475 {
476 $r = $this->getDefaultRenderer();
477 $html = $this->renderInsideContainer($sg->withValue('g2'));
478 $expected = '<label for="id_3"><input type="radio" id="id_3" value="g2" checked="checked" />';
479 $this->assertStringContainsString($expected, $this->renderInsideContainer($sg->withValue('g2')));
480 }

◆ testRenderWithValueByIndex()

SwitchableGroupInputTest::testRenderWithValueByIndex ( )

Definition at line 482 of file SwitchableGroupInputTest.php.

482 : void
483 {
484 $f = $this->buildFactory();
485 $label = "label";
486 $byline = "byline";
487
488 $group1 = $f->group([
489 "field_1" => $f->text("f", "some field")
490 ]);
491 $group2 = $f->group([
492 "field_2" => $f->text("f2", "some other field")
493 ]);
494 $empty_group_title = 'empty group, the title';
495 $empty_group_byline = 'empty group, the byline';
496 $group3 = $f->group([], $empty_group_title, $empty_group_byline);
497
498 $sg = $f->switchableGroup([$group1, $group2, $group3], $label, $byline);
499
500 $expected = '<label for="id_3"><input type="radio" id="id_3" value="1" checked="checked" />';
501 $this->assertStringContainsString($expected, $this->renderInsideContainer($sg->withValue('1')));
502 }

References Vendor\Package\$f, and buildFactory().

+ Here is the call graph for this function:

◆ testSwitchableGroupForwardsValuesOnWithValue()

SwitchableGroupInputTest::testSwitchableGroupForwardsValuesOnWithValue ( )

Definition at line 185 of file SwitchableGroupInputTest.php.

185 : void
186 {
187 $this->assertNotSame($this->child1, $this->child2);
188
189 $this->child1
190 ->expects($this->never())
191 ->method("withValue");
192 $this->child2
193 ->method('isClientSideValueOk')
194 ->willReturn(true);
195 $this->child2
196 ->expects($this->once())
197 ->method("withValue")
198 ->with([2])
199 ->willReturn($this->child2);
200
201 $new_group = $this->switchable_group->withValue(["child2", [2]]);
202
203 $this->assertEquals(["child1" => $this->child1, "child2" => $this->child2], $new_group->getInputs());
204 $this->assertInstanceOf(SwitchableGroup::class, $new_group);
205 $this->assertNotSame($this->switchable_group, $new_group);
206 }

◆ testSwitchableGroupMayOnlyHaveGroupChildren()

SwitchableGroupInputTest::testSwitchableGroupMayOnlyHaveGroupChildren ( )

Definition at line 171 of file SwitchableGroupInputTest.php.

171 : void
172 {
173 $this->expectException(InvalidArgumentException::class);
174
175 $this->group = new SwitchableGroup(
176 $this->data_factory,
177 $this->refinery,
178 $this->lng,
179 [$this->createMock(I\Input\Field\FormInput::class)],
180 "LABEL",
181 "BYLINE"
182 );
183 }

References ILIAS\Repository\lng(), and ILIAS\Repository\refinery().

+ Here is the call graph for this function:

◆ testWithDisabledDisablesChildren()

SwitchableGroupInputTest::testWithDisabledDisablesChildren ( )

Definition at line 131 of file SwitchableGroupInputTest.php.

131 : void
132 {
133 $this->assertNotSame($this->child1, $this->child2);
134
135 $this->child1
136 ->expects($this->once())
137 ->method("withDisabled")
138 ->with(true)
139 ->willReturn($this->child2);
140 $this->child2
141 ->expects($this->once())
142 ->method("withDisabled")
143 ->with(true)
144 ->willReturn($this->child1);
145
146 $new_group = $this->switchable_group->withDisabled(true);
147
148 $this->assertEquals(["child1" => $this->child2, "child2" => $this->child1], $new_group->getInputs());
149 $this->assertInstanceOf(SwitchableGroup::class, $new_group);
150 $this->assertNotSame($this->switchable_group, $new_group);
151 }

◆ testWithInputCallsChildrenAndAppliesOperations()

SwitchableGroupInputTest::testWithInputCallsChildrenAndAppliesOperations ( )

Definition at line 246 of file SwitchableGroupInputTest.php.

246 : void
247 {
248 $this->assertNotSame($this->child1, $this->child2);
249
250 $input_data = $this->createMock(InputData::class);
251
252 $input_data
253 ->expects($this->once())
254 ->method("getOr")
255 ->with("name0")
256 ->willReturn("child1");
257
258 $expected_result = $this->data_factory->ok("one");
259
260 $this->child1
261 ->expects($this->once())
262 ->method("withInput")
263 ->with($input_data)
264 ->willReturn($this->child1);
265 $this->child1
266 ->expects($this->once())
267 ->method("getContent")
268 ->with()
269 ->willReturn($expected_result);
270 $this->nested_child
271 ->expects($this->once())
272 ->method("getContent")
273 ->with()
274 ->willReturn($expected_result);
275 $this->child2
276 ->expects($this->never())
277 ->method("withInput");
278 $this->child2
279 ->expects($this->never())
280 ->method("getContent");
281
282 $called = false;
283 $new_group = $this->switchable_group
284 ->withAdditionalTransformation($this->refinery->custom()->transformation(function ($v) use (&$called): string {
285 $called = true;
286 $this->assertEquals(["child1", ["one"]], $v);
287 return "result";
288 }))
289 ->withInput($input_data);
290
291 $this->assertTrue($called);
292 $this->assertEquals(["child1" => $this->child1, "child2" => $this->child2], $new_group->getInputs());
293 $this->assertInstanceOf(SwitchableGroup::class, $new_group);
294 $this->assertNotSame($this->switchable_group, $new_group);
295 $this->assertEquals($this->data_factory->ok("result"), $new_group->getContent());
296 }

References ILIAS\Repository\refinery().

+ Here is the call graph for this function:

◆ testWithInputDoesNotAcceptUnknownKeys()

SwitchableGroupInputTest::testWithInputDoesNotAcceptUnknownKeys ( )

Definition at line 378 of file SwitchableGroupInputTest.php.

378 : void
379 {
380 $this->expectException(InvalidArgumentException::class);
381
382 $input_data = $this->createMock(InputData::class);
383
384 $input_data
385 ->expects($this->once())
386 ->method("getOr")
387 ->with("name0")
388 ->willReturn(123);
389
390 $this->child1
391 ->expects($this->never())
392 ->method("withInput");
393 $this->child1
394 ->expects($this->never())
395 ->method("getContent");
396 $this->child2
397 ->expects($this->never())
398 ->method("withInput");
399 $this->child2
400 ->expects($this->never())
401 ->method("getContent");
402
403 $this->switchable_group
404 ->withAdditionalTransformation($this->refinery->custom()->transformation(function () use (&$called): void {
405 $this->fail("This should not happen.");
406 }))
407 ->withInput($input_data);
408 }

References ILIAS\Repository\refinery().

+ Here is the call graph for this function:

◆ testWithInputDoesNotApplyOperationsOnError()

SwitchableGroupInputTest::testWithInputDoesNotApplyOperationsOnError ( )

Definition at line 298 of file SwitchableGroupInputTest.php.

298 : void
299 {
300 $this->assertNotSame($this->child1, $this->child2);
301
302 $input_data = $this->createMock(InputData::class);
303
304 $input_data
305 ->expects($this->once())
306 ->method("getOr")
307 ->with("name0")
308 ->willReturn("child2");
309
310 $this->child1
311 ->expects($this->never())
312 ->method("withInput");
313 $this->child1
314 ->expects($this->never())
315 ->method("getContent");
316 $this->child2
317 ->expects($this->once())
318 ->method("withInput")
319 ->with($input_data)
320 ->willReturn($this->child2);
321 $this->child2
322 ->expects($this->once())
323 ->method("getContent")
324 ->willReturn($this->data_factory->error(""));
325
326 $i18n = "THERE IS SOME ERROR IN THIS GROUP";
327 $this->lng
328 ->expects($this->once())
329 ->method("txt")
330 ->with("ui_error_in_group")
331 ->willReturn($i18n);
332
333 $new_group = $this->switchable_group
334 ->withAdditionalTransformation($this->refinery->custom()->transformation(function (): void {
335 $this->fail("This should not happen.");
336 }))
337 ->withInput($input_data);
338
339 $this->assertEquals(["child1" => $this->child1, "child2" => $this->child2], $new_group->getInputs());
340 $this->assertInstanceOf(SwitchableGroup::class, $new_group);
341 $this->assertNotSame($this->switchable_group, $new_group);
342 $this->assertTrue($new_group->getContent()->isError());
343 }

References ILIAS\Repository\lng(), and ILIAS\Repository\refinery().

+ Here is the call graph for this function:

◆ testWithRequiredDoesNotRequire()

SwitchableGroupInputTest::testWithRequiredDoesNotRequire ( )

Definition at line 153 of file SwitchableGroupInputTest.php.

153 : void
154 {
155 $this->assertNotSame($this->child1, $this->child2);
156
157 $this->child1
158 ->expects($this->never())
159 ->method("withRequired");
160 $this->child2
161 ->expects($this->never())
162 ->method("withRequired");
163
164 $new_group = $this->switchable_group->withRequired(true);
165
166 $this->assertEquals(["child1" => $this->child1, "child2" => $this->child2], $new_group->getInputs());
167 $this->assertInstanceOf(SwitchableGroup::class, $new_group);
168 $this->assertNotSame($this->switchable_group, $new_group);
169 }

Field Documentation

◆ $child1

SwitchableGroupInputTest::$child1
protected

Definition at line 55 of file SwitchableGroupInputTest.php.

◆ $child2

SwitchableGroupInputTest::$child2
protected

Definition at line 60 of file SwitchableGroupInputTest.php.

◆ $data_factory

Data Factory SwitchableGroupInputTest::$data_factory
protected

Definition at line 72 of file SwitchableGroupInputTest.php.

◆ $group

SwitchableGroup SwitchableGroupInputTest::$group
protected

Definition at line 75 of file SwitchableGroupInputTest.php.

◆ $lng

SwitchableGroupInputTest::$lng
protected

Definition at line 70 of file SwitchableGroupInputTest.php.

◆ $nested_child

SwitchableGroupInputTest::$nested_child
protected

Definition at line 65 of file SwitchableGroupInputTest.php.

◆ $refinery

Refinery SwitchableGroupInputTest::$refinery
protected

Definition at line 73 of file SwitchableGroupInputTest.php.

◆ $switchable_group

ILIAS UI Component Input Field Group SwitchableGroupInputTest::$switchable_group
protected

Definition at line 74 of file SwitchableGroupInputTest.php.

Referenced by testErrorIsI18NOnError().


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