ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
GroupInputTest Class Reference
+ Inheritance diagram for GroupInputTest:
+ Collaboration diagram for GroupInputTest:

Public Member Functions

 setUp ()
 
 testWithDisabledDisablesChildren ()
 
 testWithRequiredRequiresChildren ()
 
 testGroupMayOnlyHaveInputChildren ()
 
 testGroupForwardsValuesOnWithValue ()
 
 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 406 of file GroupInputTest.php.

406 : void
407 {
408 $bl = 'some byline';
409 $f = $this->getFieldFactory();
410 $group = $f->group([], "LABEL", $bl);
411 $this->assertEquals($bl, $group->getByline());
412 }

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 324 of file GroupInputTest.php.

324 : void
325 {
326 $this->assertNotSame($this->child1, $this->child2);
327
328 $input_data = $this->createMock(InputData::class);
329
330 $this->child1
331 ->method("withInput")
332 ->willReturn($this->child2);
333 $this->child1
334 ->method("getContent")
335 ->willReturn($this->data_factory->error(""));
336 $this->child2
337 ->method("withInput")
338 ->willReturn($this->child1);
339 $this->child2
340 ->method("getContent")
341 ->willReturn($this->data_factory->ok("two"));
342
343 $i18n = "THERE IS SOME ERROR IN THIS GROUP";
344 $this->language
345 ->expects($this->once())
346 ->method("txt")
347 ->with("ui_error_in_group")
348 ->willReturn($i18n);
349
350 $new_group = $this->group
351 ->withInput($input_data);
352
353 $this->assertTrue($new_group->getContent()->isError());
354 $this->assertEquals($i18n, $new_group->getContent()->error());
355 }

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

+ Here is the call graph for this function:

◆ testGroupForwardsValuesOnGetValue()

GroupInputTest::testGroupForwardsValuesOnGetValue ( )

Definition at line 219 of file GroupInputTest.php.

219 : void
220 {
221 $this->assertNotSame($this->child1, $this->child2);
222
223 $this->child1
224 ->expects($this->once())
225 ->method("getValue")
226 ->with()
227 ->willReturn("one");
228 $this->child2
229 ->expects($this->once())
230 ->method("getValue")
231 ->with()
232 ->willReturn("two");
233
234 $vals = $this->group->getValue();
235
236 $this->assertEquals(["one", "two"], $vals);
237 }

◆ 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 212 of file GroupInputTest.php.

212 : void
213 {
214 $this->expectException(InvalidArgumentException::class);
215
216 $this->group->withValue([1]);
217 }

◆ testGroupOnlyDoesNoAcceptNonArrayValue()

GroupInputTest::testGroupOnlyDoesNoAcceptNonArrayValue ( )

Definition at line 205 of file GroupInputTest.php.

205 : void
206 {
207 $this->expectException(InvalidArgumentException::class);
208
209 $this->group->withValue(1);
210 }

◆ testGroupRendering()

GroupInputTest::testGroupRendering ( )

Definition at line 374 of file GroupInputTest.php.

374 : void
375 {
376 $f = $this->getFieldFactory();
377 $inputs = [
378 $f->text("input1", "in 1"),
379 $f->text("input2", "in 2")
380 ];
381 $label = 'group label';
382 $group = $f->group($inputs, $label);
383
384 $expected = <<<EOT
385 <fieldset class="c-input" data-il-ui-component="text-field-input" data-il-ui-input-name="">
386 <label for="id_1">input1</label>
387 <div class="c-input__field">
388 <input id="id_1" type="text" class="c-field-text" />
389 </div>
390 <div class="c-input__help-byline">in 1</div>
391 </fieldset>
392 <fieldset class="c-input" data-il-ui-component="text-field-input" data-il-ui-input-name="">
393 <label for="id_2">input2</label>
394 <div class="c-input__field">
395 <input id="id_2" type="text" class="c-field-text" />
396 </div>
397 <div class="c-input__help-byline">in 2</div>
398 </fieldset>
399EOT;
400 $actual = $this->brutallyTrimHTML($this->getDefaultRenderer()->render($group));
401 $expected = $this->brutallyTrimHTML($expected);
402 $this->assertEquals($expected, $actual);
403 }

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 414 of file GroupInputTest.php.

414 : void
415 {
416 $f = $this->getFieldFactory();
417 $inputs = [
418 $f->text(""),
419 $f->text("")
420 ];
421 $group = $f->group($inputs, '');
422 $this->assertFalse($group->isRequired());
423 }

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 425 of file GroupInputTest.php.

425 : void
426 {
427 $f = $this->getFieldFactory();
428 $inputs = [
429 $f->text(""),
430 $f->text("")->withRequired(true)
431 ];
432 $group = $f->group($inputs, '');
433 $this->assertTrue($group->isRequired());
434 }

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 239 of file GroupInputTest.php.

239 : void
240 {
241 $this->assertNotSame($this->child1, $this->child2);
242
243 $input_data = $this->createMock(InputData::class);
244
245 $this->child1
246 ->expects($this->once())
247 ->method("withInput")
248 ->with($input_data)
249 ->willReturn($this->child2);
250 $this->child1
251 ->expects($this->once())
252 ->method("getContent")
253 ->willReturn($this->data_factory->ok("one"));
254 $this->child2
255 ->expects($this->once())
256 ->method("withInput")
257 ->with($input_data)
258 ->willReturn($this->child1);
259 $this->child2
260 ->expects($this->once())
261 ->method("getContent")
262 ->willReturn($this->data_factory->ok("two"));
263
264 $called = false;
265 $new_group = $this->group
266 ->withAdditionalTransformation($this->refinery->custom()->transformation(function ($v) use (&$called): string {
267 $called = true;
268 $this->assertEquals(["two", "one"], $v);
269 return "result";
270 }))
271 ->withInput($input_data);
272
273 $this->assertTrue($called);
274 $this->assertEquals([$this->child2, $this->child1], $new_group->getInputs());
275 $this->assertInstanceOf(Group::class, $new_group);
276 $this->assertNotSame($this->group, $new_group);
277 $this->assertEquals($this->data_factory->ok("result"), $new_group->getContent());
278 }

References ILIAS\Repository\refinery().

+ Here is the call graph for this function:

◆ testWithInputDoesNotApplyOperationsOnError()

GroupInputTest::testWithInputDoesNotApplyOperationsOnError ( )

Definition at line 280 of file GroupInputTest.php.

280 : void
281 {
282 $this->assertNotSame($this->child1, $this->child2);
283
284 $input_data = $this->createMock(InputData::class);
285
286 $this->child1
287 ->expects($this->once())
288 ->method("withInput")
289 ->with($input_data)
290 ->willReturn($this->child2);
291 $this->child1
292 ->expects($this->once())
293 ->method("getContent")
294 ->willReturn($this->data_factory->error(""));
295 $this->child2
296 ->expects($this->once())
297 ->method("withInput")
298 ->with($input_data)
299 ->willReturn($this->child1);
300 $this->child2
301 ->expects($this->once())
302 ->method("getContent")
303 ->willReturn($this->data_factory->ok("two"));
304
305 $i18n = "THERE IS SOME ERROR IN THIS GROUP";
306 $this->language
307 ->expects($this->once())
308 ->method("txt")
309 ->with("ui_error_in_group")
310 ->willReturn($i18n);
311
312 $new_group = $this->group
313 ->withAdditionalTransformation($this->refinery->custom()->transformation(function (): void {
314 $this->fail("This should not happen.");
315 }))
316 ->withInput($input_data);
317
318 $this->assertEquals([$this->child2, $this->child1], $new_group->getInputs());
319 $this->assertInstanceOf(Group::class, $new_group);
320 $this->assertNotSame($this->group, $new_group);
321 $this->assertTrue($new_group->getContent()->isError());
322 }

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 357 of file GroupInputTest.php.

357 : void
358 {
359 $group = new Group(
360 $this->data_factory,
361 $this->refinery,
362 $this->language,
363 [],
364 "LABEL",
365 "BYLINE"
366 );
367 $content = $group->getContent();
368 $this->assertInstanceOf(Ok::class, $content);
369 $this->assertCount(0, $content->value());
370 }
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 174 of file GroupInputTest.php.

174 : void
175 {
176 $this->assertNotSame($this->child1, $this->child2);
177
178 $this->group = new Group(
179 $this->data_factory,
180 $this->refinery,
181 $this->language,
182 ["child1" => $this->child1, "child2" => $this->child2],
183 "LABEL",
184 "BYLINE"
185 );
186
187 $this->child1
188 ->method("withValue")
189 ->willReturn($this->child2);
190 $this->child1
191 ->method("isClientSideValueOk")
192 ->willReturn(true);
193 $this->child2
194 ->method("withValue")
195 ->willReturn($this->child1);
196 $this->child2
197 ->method("isClientSideValueOk")
198 ->willReturn(true);
199
200 $new_group = $this->group->withValue(["child1" => 1,"child2" => 2]);
201
202 $this->assertEquals(["child1" => $this->child2, "child2" => $this->child1], $new_group->getInputs());
203 }

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: