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

Public Member Functions

 setUp ()
 
 testWithDisabledDisablesChildren ()
 
 testWithRequiredRequiresChildren ()
 
 testGroupMayOnlyHaveInputChildren ()
 
 testGroupForwardsValuesOnWithValue ()
 
 testGroupForwardsNullWithoutValidationOnWithValue ()
 
 testWithValuePreservesKeys ()
 
 testGroupOnlyDoesNoAcceptNonArrayValue ()
 
 testGroupOnlyDoesNoAcceptArrayValuesWithWrongLength ()
 
 testGroupForwardsValuesOnGetValue ()
 
 testWithInputCallsChildrenAndAppliesOperations ()
 
 testWithInputDoesNotApplyOperationsOnError ()
 
 testErrorIsI18NOnError ()
 
 testWithoutChildren ()
 
 testGroupRendering ()
 
 testBylineProperty ()
 
 testGroupWithoutRequiredField ()
 
 testGroupWithRequiredField ()
 

Protected Attributes

 $child1
 
 $child2
 
Data Factory $data_factory
 
 $language
 
Refinery $refinery
 
Group $group
 

Detailed Description

Definition at line 43 of file GroupInputTest.php.

Member Function Documentation

◆ setUp()

GroupInputTest::setUp ( )

Definition at line 66 of file GroupInputTest.php.

66 : void
67 {
68 $this->child1 = $this->createMock(Input1::class);
69 $this->child2 = $this->createMock(Input2::class);
70 $this->data_factory = new Data\Factory();
71 $this->language = $this->createMock(ILIAS\Language\Language::class);
72 $this->refinery = new Refinery($this->data_factory, $this->language);
73
74 $this->group = new Group(
75 $this->data_factory,
76 $this->refinery,
77 $this->language,
78 [$this->child1, $this->child2],
79 "LABEL",
80 "BYLINE"
81 );
82 }
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.

References ILIAS\ILIASObject\Creation\Group, ILIAS\UI\examples\Symbol\Glyph\Language\language(), and ILIAS\Repository\refinery().

+ Here is the call graph for this function:

◆ testBylineProperty()

GroupInputTest::testBylineProperty ( )

Definition at line 435 of file GroupInputTest.php.

435 : void
436 {
437 $bl = 'some byline';
438 $f = $this->getFieldFactory();
439 $group = $f->group([], "LABEL", $bl);
440 $this->assertEquals($bl, $group->getByline());
441 }

References Vendor\Package\$f, $group, and ILIAS\UI\Component\Input\Container\Form\FormInput\getByline().

+ Here is the call graph for this function:

◆ testErrorIsI18NOnError()

GroupInputTest::testErrorIsI18NOnError ( )

Definition at line 353 of file GroupInputTest.php.

353 : void
354 {
355 $this->assertNotSame($this->child1, $this->child2);
356
357 $input_data = $this->createMock(InputData::class);
358
359 $this->child1
360 ->method("withInput")
361 ->willReturn($this->child2);
362 $this->child1
363 ->method("getContent")
364 ->willReturn($this->data_factory->error(""));
365 $this->child2
366 ->method("withInput")
367 ->willReturn($this->child1);
368 $this->child2
369 ->method("getContent")
370 ->willReturn($this->data_factory->ok("two"));
371
372 $i18n = "THERE IS SOME ERROR IN THIS GROUP";
373 $this->language
374 ->expects($this->once())
375 ->method("txt")
376 ->with("ui_error_in_group")
377 ->willReturn($i18n);
378
379 $new_group = $this->group
380 ->withInput($input_data);
381
382 $this->assertTrue($new_group->getContent()->isError());
383 $this->assertEquals($i18n, $new_group->getContent()->error());
384 }

References ILIAS\UI\examples\Symbol\Glyph\Language\language().

+ Here is the call graph for this function:

◆ testGroupForwardsNullWithoutValidationOnWithValue()

GroupInputTest::testGroupForwardsNullWithoutValidationOnWithValue ( )

Definition at line 174 of file GroupInputTest.php.

174 : void
175 {
176 $this->child1
177 ->expects($this->once())
178 ->method("withValue")
179 ->with(1)
180 ->willReturn($this->child2);
181 $this->child1
182 ->expects($this->once())
183 ->method("isClientSideValueOk")
184 ->with(1)
185 ->willReturn(true);
186 $this->child2
187 ->expects($this->once())
188 ->method("withValue")
189 ->with(null)
190 ->willReturn($this->child1);
191 $this->child2
192 ->expects($this->never())
193 ->method("isClientSideValueOk")
194 ->with(null)
195 ->willReturn(true);
196
197 $new_group = $this->group->withValue([1, null]);
198
199 $this->assertEquals([$this->child2, $this->child1], $new_group->getInputs());
200 $this->assertNotSame($this->group, $new_group);
201 }

◆ testGroupForwardsValuesOnGetValue()

GroupInputTest::testGroupForwardsValuesOnGetValue ( )

Definition at line 248 of file GroupInputTest.php.

248 : void
249 {
250 $this->assertNotSame($this->child1, $this->child2);
251
252 $this->child1
253 ->expects($this->once())
254 ->method("getValue")
255 ->with()
256 ->willReturn("one");
257 $this->child2
258 ->expects($this->once())
259 ->method("getValue")
260 ->with()
261 ->willReturn("two");
262
263 $vals = $this->group->getValue();
264
265 $this->assertEquals(["one", "two"], $vals);
266 }

◆ testGroupForwardsValuesOnWithValue()

GroupInputTest::testGroupForwardsValuesOnWithValue ( )

Definition at line 142 of file GroupInputTest.php.

142 : void
143 {
144 $this->assertNotSame($this->child1, $this->child2);
145
146 $this->child1
147 ->expects($this->once())
148 ->method("withValue")
149 ->with(1)
150 ->willReturn($this->child2);
151 $this->child1
152 ->expects($this->once())
153 ->method("isClientSideValueOk")
154 ->with(1)
155 ->willReturn(true);
156 $this->child2
157 ->expects($this->once())
158 ->method("withValue")
159 ->with(2)
160 ->willReturn($this->child1);
161 $this->child2
162 ->expects($this->once())
163 ->method("isClientSideValueOk")
164 ->with(2)
165 ->willReturn(true);
166
167 $new_group = $this->group->withValue([1,2]);
168
169 $this->assertEquals([$this->child2, $this->child1], $new_group->getInputs());
170 $this->assertInstanceOf(Group::class, $new_group);
171 $this->assertNotSame($this->group, $new_group);
172 }

◆ testGroupMayOnlyHaveInputChildren()

GroupInputTest::testGroupMayOnlyHaveInputChildren ( )

Definition at line 128 of file GroupInputTest.php.

128 : void
129 {
130 $this->expectException(InvalidArgumentException::class);
131
132 $this->group = new Group(
133 $this->data_factory,
134 $this->refinery,
135 $this->language,
136 ["foo", "bar"],
137 "LABEL",
138 "BYLINE"
139 );
140 }

References ILIAS\ILIASObject\Creation\Group, ILIAS\UI\examples\Symbol\Glyph\Language\language(), and ILIAS\Repository\refinery().

+ Here is the call graph for this function:

◆ testGroupOnlyDoesNoAcceptArrayValuesWithWrongLength()

GroupInputTest::testGroupOnlyDoesNoAcceptArrayValuesWithWrongLength ( )

Definition at line 241 of file GroupInputTest.php.

241 : void
242 {
243 $this->expectException(InvalidArgumentException::class);
244
245 $this->group->withValue([1]);
246 }

◆ testGroupOnlyDoesNoAcceptNonArrayValue()

GroupInputTest::testGroupOnlyDoesNoAcceptNonArrayValue ( )

Definition at line 234 of file GroupInputTest.php.

234 : void
235 {
236 $this->expectException(InvalidArgumentException::class);
237
238 $this->group->withValue(1);
239 }

◆ testGroupRendering()

GroupInputTest::testGroupRendering ( )

Definition at line 403 of file GroupInputTest.php.

403 : void
404 {
405 $f = $this->getFieldFactory();
406 $inputs = [
407 $f->text("input1", "in 1"),
408 $f->text("input2", "in 2")
409 ];
410 $label = 'group label';
411 $group = $f->group($inputs, $label);
412
413 $expected = <<<EOT
414 <fieldset class="c-input" data-il-ui-component="text-field-input" data-il-ui-input-name="">
415 <label for="id_1">input1</label>
416 <div class="c-input__field">
417 <input id="id_1" type="text" class="c-field-text" />
418 </div>
419 <div class="c-input__help-byline">in 1</div>
420 </fieldset>
421 <fieldset class="c-input" data-il-ui-component="text-field-input" data-il-ui-input-name="">
422 <label for="id_2">input2</label>
423 <div class="c-input__field">
424 <input id="id_2" type="text" class="c-field-text" />
425 </div>
426 <div class="c-input__help-byline">in 2</div>
427 </fieldset>
428EOT;
429 $actual = $this->brutallyTrimHTML($this->getDefaultRenderer()->render($group));
430 $expected = $this->brutallyTrimHTML($expected);
431 $this->assertEquals($expected, $actual);
432 }

References Vendor\Package\$f, $group, ILIAS\UI\Implementation\Component\Input\$inputs, and ILIAS\Repository\ui().

+ Here is the call graph for this function:

◆ testGroupWithoutRequiredField()

GroupInputTest::testGroupWithoutRequiredField ( )

Definition at line 443 of file GroupInputTest.php.

443 : void
444 {
445 $f = $this->getFieldFactory();
446 $inputs = [
447 $f->text(""),
448 $f->text("")
449 ];
450 $group = $f->group($inputs, '');
451 $this->assertFalse($group->isRequired());
452 }

References Vendor\Package\$f, $group, ILIAS\UI\Implementation\Component\Input\$inputs, and ILIAS\UI\Implementation\Component\Input\Field\Group\isRequired().

+ Here is the call graph for this function:

◆ testGroupWithRequiredField()

GroupInputTest::testGroupWithRequiredField ( )

Definition at line 454 of file GroupInputTest.php.

454 : void
455 {
456 $f = $this->getFieldFactory();
457 $inputs = [
458 $f->text(""),
459 $f->text("")->withRequired(true)
460 ];
461 $group = $f->group($inputs, '');
462 $this->assertTrue($group->isRequired());
463 }

References Vendor\Package\$f, $group, ILIAS\UI\Implementation\Component\Input\$inputs, and ILIAS\UI\Implementation\Component\Input\Field\Group\isRequired().

+ Here is the call graph for this function:

◆ testWithDisabledDisablesChildren()

GroupInputTest::testWithDisabledDisablesChildren ( )

Definition at line 84 of file GroupInputTest.php.

84 : void
85 {
86 $this->assertNotSame($this->child1, $this->child2);
87
88 $this->child1
89 ->expects($this->once())
90 ->method("withDisabled")
91 ->with(true)
92 ->willReturn($this->child2);
93 $this->child2
94 ->expects($this->once())
95 ->method("withDisabled")
96 ->with(true)
97 ->willReturn($this->child1);
98
99 $new_group = $this->group->withDisabled(true);
100
101 $this->assertEquals([$this->child2, $this->child1], $new_group->getInputs());
102 $this->assertInstanceOf(Group::class, $new_group);
103 $this->assertNotSame($this->group, $new_group);
104 }

◆ testWithInputCallsChildrenAndAppliesOperations()

GroupInputTest::testWithInputCallsChildrenAndAppliesOperations ( )

Definition at line 268 of file GroupInputTest.php.

268 : void
269 {
270 $this->assertNotSame($this->child1, $this->child2);
271
272 $input_data = $this->createMock(InputData::class);
273
274 $this->child1
275 ->expects($this->once())
276 ->method("withInput")
277 ->with($input_data)
278 ->willReturn($this->child2);
279 $this->child1
280 ->expects($this->once())
281 ->method("getContent")
282 ->willReturn($this->data_factory->ok("one"));
283 $this->child2
284 ->expects($this->once())
285 ->method("withInput")
286 ->with($input_data)
287 ->willReturn($this->child1);
288 $this->child2
289 ->expects($this->once())
290 ->method("getContent")
291 ->willReturn($this->data_factory->ok("two"));
292
293 $called = false;
294 $new_group = $this->group
295 ->withAdditionalTransformation($this->refinery->custom()->transformation(function ($v) use (&$called): string {
296 $called = true;
297 $this->assertEquals(["two", "one"], $v);
298 return "result";
299 }))
300 ->withInput($input_data);
301
302 $this->assertTrue($called);
303 $this->assertEquals([$this->child2, $this->child1], $new_group->getInputs());
304 $this->assertInstanceOf(Group::class, $new_group);
305 $this->assertNotSame($this->group, $new_group);
306 $this->assertEquals($this->data_factory->ok("result"), $new_group->getContent());
307 }

References ILIAS\Repository\refinery().

+ Here is the call graph for this function:

◆ testWithInputDoesNotApplyOperationsOnError()

GroupInputTest::testWithInputDoesNotApplyOperationsOnError ( )

Definition at line 309 of file GroupInputTest.php.

309 : void
310 {
311 $this->assertNotSame($this->child1, $this->child2);
312
313 $input_data = $this->createMock(InputData::class);
314
315 $this->child1
316 ->expects($this->once())
317 ->method("withInput")
318 ->with($input_data)
319 ->willReturn($this->child2);
320 $this->child1
321 ->expects($this->once())
322 ->method("getContent")
323 ->willReturn($this->data_factory->error(""));
324 $this->child2
325 ->expects($this->once())
326 ->method("withInput")
327 ->with($input_data)
328 ->willReturn($this->child1);
329 $this->child2
330 ->expects($this->once())
331 ->method("getContent")
332 ->willReturn($this->data_factory->ok("two"));
333
334 $i18n = "THERE IS SOME ERROR IN THIS GROUP";
335 $this->language
336 ->expects($this->once())
337 ->method("txt")
338 ->with("ui_error_in_group")
339 ->willReturn($i18n);
340
341 $new_group = $this->group
342 ->withAdditionalTransformation($this->refinery->custom()->transformation(function (): void {
343 $this->fail("This should not happen.");
344 }))
345 ->withInput($input_data);
346
347 $this->assertEquals([$this->child2, $this->child1], $new_group->getInputs());
348 $this->assertInstanceOf(Group::class, $new_group);
349 $this->assertNotSame($this->group, $new_group);
350 $this->assertTrue($new_group->getContent()->isError());
351 }

References ILIAS\UI\examples\Symbol\Glyph\Language\language(), and ILIAS\Repository\refinery().

+ Here is the call graph for this function:

◆ testWithoutChildren()

GroupInputTest::testWithoutChildren ( )

Definition at line 386 of file GroupInputTest.php.

386 : void
387 {
388 $group = new Group(
389 $this->data_factory,
390 $this->refinery,
391 $this->language,
392 [],
393 "LABEL",
394 "BYLINE"
395 );
396 $content = $group->getContent();
397 $this->assertInstanceOf(Ok::class, $content);
398 $this->assertCount(0, $content->value());
399 }
getContent()
Get the current content of the input.
Definition: Group.php:129

References $group, ILIAS\UI\Implementation\Component\Input\Field\Group\getContent(), ILIAS\ILIASObject\Creation\Group, ILIAS\UI\examples\Symbol\Glyph\Language\language(), and ILIAS\Repository\refinery().

+ Here is the call graph for this function:

◆ testWithRequiredRequiresChildren()

GroupInputTest::testWithRequiredRequiresChildren ( )

Definition at line 106 of file GroupInputTest.php.

106 : void
107 {
108 $this->assertNotSame($this->child1, $this->child2);
109
110 $this->child1
111 ->expects($this->once())
112 ->method("withRequired")
113 ->with(true)
114 ->willReturn($this->child2);
115 $this->child2
116 ->expects($this->once())
117 ->method("withRequired")
118 ->with(true)
119 ->willReturn($this->child1);
120
121 $new_group = $this->group->withRequired(true);
122
123 $this->assertEquals([$this->child2, $this->child1], $new_group->getInputs());
124 $this->assertInstanceOf(Group::class, $new_group);
125 $this->assertNotSame($this->group, $new_group);
126 }

◆ testWithValuePreservesKeys()

GroupInputTest::testWithValuePreservesKeys ( )

Definition at line 203 of file GroupInputTest.php.

203 : void
204 {
205 $this->assertNotSame($this->child1, $this->child2);
206
207 $this->group = new Group(
208 $this->data_factory,
209 $this->refinery,
210 $this->language,
211 ["child1" => $this->child1, "child2" => $this->child2],
212 "LABEL",
213 "BYLINE"
214 );
215
216 $this->child1
217 ->method("withValue")
218 ->willReturn($this->child2);
219 $this->child1
220 ->method("isClientSideValueOk")
221 ->willReturn(true);
222 $this->child2
223 ->method("withValue")
224 ->willReturn($this->child1);
225 $this->child2
226 ->method("isClientSideValueOk")
227 ->willReturn(true);
228
229 $new_group = $this->group->withValue(["child1" => 1,"child2" => 2]);
230
231 $this->assertEquals(["child1" => $this->child2, "child2" => $this->child1], $new_group->getInputs());
232 }

References ILIAS\ILIASObject\Creation\Group, ILIAS\UI\examples\Symbol\Glyph\Language\language(), and ILIAS\Repository\refinery().

+ Here is the call graph for this function:

Field Documentation

◆ $child1

GroupInputTest::$child1
protected

Definition at line 50 of file GroupInputTest.php.

◆ $child2

GroupInputTest::$child2
protected

Definition at line 55 of file GroupInputTest.php.

◆ $data_factory

Data Factory GroupInputTest::$data_factory
protected

Definition at line 57 of file GroupInputTest.php.

◆ $group

◆ $language

GroupInputTest::$language
protected

Definition at line 62 of file GroupInputTest.php.

◆ $refinery

Refinery GroupInputTest::$refinery
protected

Definition at line 63 of file GroupInputTest.php.


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