ILIAS  release_8 Revision v8.23
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 ()
 
 getFieldFactory ()
 
 testGroupRendering ()
 
 testBylineProperty ()
 
 testGroupWithoutRequiredField ()
 
 testGroupWithRequiredField ()
 
- Public Member Functions inherited from ILIAS_UI_TestBase
 setUp ()
 
 tearDown ()
 
 getUIFactory ()
 
 getTemplateFactory ()
 
 getResourceRegistry ()
 
 getLanguage ()
 
 getJavaScriptBinding ()
 
 getRefinery ()
 
 getImagePathResolver ()
 
 getDataFactory ()
 
 getDefaultRenderer (JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
 
 getDecoratedRenderer (Renderer $default)
 
 normalizeHTML (string $html)
 
 assertHTMLEquals (string $expected_html_as_string, string $html_as_string)
 

Protected Attributes

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

Additional Inherited Members

- Protected Member Functions inherited from ILIAS_UI_TestBase
 brutallyTrimHTML (string $html)
 A more radical version of normalizeHTML. More...
 
 brutallyTrimSignals (string $html)
 A naive replacement of all il_signal-ids with dots to ease comparisons of rendered output. More...
 

Detailed Description

Definition at line 41 of file GroupInputTest.php.

Member Function Documentation

◆ getFieldFactory()

GroupInputTest::getFieldFactory ( )

Definition at line 368 of file GroupInputTest.php.

References ILIAS\UI\Implementation\Component\Input\getLanguage().

368  : FieldFactory
369  {
370  return new FieldFactory(
371  $this->createMock(\ILIAS\UI\Implementation\Component\Input\UploadLimitResolver::class),
373  new Data\Factory(),
374  $this->getRefinery(),
375  $this->getLanguage()
376  );
377  }
Class Factory.
Class ChatMainBarProvider .
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:

◆ setUp()

GroupInputTest::setUp ( )

Definition at line 62 of file GroupInputTest.php.

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

62  : void
63  {
64  $this->child1 = $this->createMock(Input1::class);
65  $this->child2 = $this->createMock(Input2::class);
66  $this->data_factory = new Data\Factory();
67  $this->language = $this->createMock(ilLanguage::class);
68  $this->refinery = new Refinery($this->data_factory, $this->language);
69 
70  $this->group = new Group(
71  $this->data_factory,
72  $this->refinery,
73  $this->language,
74  [$this->child1, $this->child2],
75  "LABEL",
76  "BYLINE"
77  );
78  }
+ Here is the call graph for this function:

◆ testBylineProperty()

GroupInputTest::testBylineProperty ( )

Definition at line 411 of file GroupInputTest.php.

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

411  : void
412  {
413  $bl = 'some byline';
414  $f = $this->getFieldFactory();
415  $group = $f->group([], "LABEL", $bl);
416  $this->assertEquals($bl, $group->getByline());
417  }
getByline()
Get the byline of the input.
+ Here is the call graph for this function:

◆ testErrorIsI18NOnError()

GroupInputTest::testErrorIsI18NOnError ( )

Definition at line 320 of file GroupInputTest.php.

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

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

◆ testGroupForwardsValuesOnGetValue()

GroupInputTest::testGroupForwardsValuesOnGetValue ( )

Definition at line 215 of file GroupInputTest.php.

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

◆ testGroupForwardsValuesOnWithValue()

GroupInputTest::testGroupForwardsValuesOnWithValue ( )

Definition at line 138 of file GroupInputTest.php.

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

◆ testGroupMayOnlyHaveInputChildren()

GroupInputTest::testGroupMayOnlyHaveInputChildren ( )

Definition at line 124 of file GroupInputTest.php.

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

124  : void
125  {
126  $this->expectException(InvalidArgumentException::class);
127 
128  $this->group = new Group(
129  $this->data_factory,
130  $this->refinery,
131  $this->language,
132  ["foo", "bar"],
133  "LABEL",
134  "BYLINE"
135  );
136  }
+ Here is the call graph for this function:

◆ testGroupOnlyDoesNoAcceptArrayValuesWithWrongLength()

GroupInputTest::testGroupOnlyDoesNoAcceptArrayValuesWithWrongLength ( )

Definition at line 208 of file GroupInputTest.php.

208  : void
209  {
210  $this->expectException(InvalidArgumentException::class);
211 
212  $this->group->withValue([1]);
213  }

◆ testGroupOnlyDoesNoAcceptNonArrayValue()

GroupInputTest::testGroupOnlyDoesNoAcceptNonArrayValue ( )

Definition at line 201 of file GroupInputTest.php.

201  : void
202  {
203  $this->expectException(InvalidArgumentException::class);
204 
205  $this->group->withValue(1);
206  }

◆ testGroupRendering()

GroupInputTest::testGroupRendering ( )

Definition at line 379 of file GroupInputTest.php.

References Vendor\Package\$f, ILIAS\UI\Implementation\Component\Input\$inputs, and ILIAS\UI\Implementation\Component\Input\Field\FormInput\$label.

379  : void
380  {
381  $f = $this->getFieldFactory();
382  $inputs = [
383  $f->text("input1", "in 1"),
384  $f->text("input2", "in 2")
385  ];
386  $label = 'group label';
387  $group = $f->group($inputs, $label);
388 
389  $expected = <<<EOT
390  <div class="form-group row">
391  <label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">input1</label>
392  <div class="col-sm-8 col-md-9 col-lg-10">
393  <input id="id_1" type="text" name="" class="form-control form-control-sm" />
394  <div class="help-block">in 1</div>
395  </div>
396  </div>
397  <div class="form-group row">
398  <label for="id_2" class="control-label col-sm-4 col-md-3 col-lg-2">input2</label>
399  <div class="col-sm-8 col-md-9 col-lg-10">
400  <input id="id_2" type="text" name="" class="form-control form-control-sm" />
401  <div class="help-block">in 2</div>
402  </div>
403  </div>
404 EOT;
405  $actual = $this->brutallyTrimHTML($this->getDefaultRenderer()->render($group));
406  $expected = $this->brutallyTrimHTML($expected);
407  $this->assertEquals($expected, $actual);
408  }
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
brutallyTrimHTML(string $html)
A more radical version of normalizeHTML.
Definition: Base.php:444

◆ testGroupWithoutRequiredField()

GroupInputTest::testGroupWithoutRequiredField ( )

Definition at line 419 of file GroupInputTest.php.

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

419  : void
420  {
421  $f = $this->getFieldFactory();
422  $inputs = [
423  $f->text(""),
424  $f->text("")
425  ];
426  $group = $f->group($inputs, '');
427  $this->assertFalse($group->isRequired());
428  }
+ Here is the call graph for this function:

◆ testGroupWithRequiredField()

GroupInputTest::testGroupWithRequiredField ( )

Definition at line 430 of file GroupInputTest.php.

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

430  : void
431  {
432  $f = $this->getFieldFactory();
433  $inputs = [
434  $f->text(""),
435  $f->text("")->withRequired(true)
436  ];
437  $group = $f->group($inputs, '');
438  $this->assertTrue($group->isRequired());
439  }
+ Here is the call graph for this function:

◆ testWithDisabledDisablesChildren()

GroupInputTest::testWithDisabledDisablesChildren ( )

Definition at line 80 of file GroupInputTest.php.

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

◆ testWithInputCallsChildrenAndAppliesOperations()

GroupInputTest::testWithInputCallsChildrenAndAppliesOperations ( )

Definition at line 235 of file GroupInputTest.php.

References ILIAS\Repository\refinery().

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

◆ testWithInputDoesNotApplyOperationsOnError()

GroupInputTest::testWithInputDoesNotApplyOperationsOnError ( )

Definition at line 276 of file GroupInputTest.php.

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

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

◆ testWithoutChildren()

GroupInputTest::testWithoutChildren ( )

Definition at line 353 of file GroupInputTest.php.

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

353  : void
354  {
355  $group = new Group(
356  $this->data_factory,
357  $this->refinery,
358  $this->language,
359  [],
360  "LABEL",
361  "BYLINE"
362  );
363  $content = $group->getContent();
364  $this->assertInstanceOf(Ok::class, $content);
365  $this->assertCount(0, $content->value());
366  }
getContent()
Get the current content of the input.
Definition: Group.php:133
+ Here is the call graph for this function:

◆ testWithRequiredRequiresChildren()

GroupInputTest::testWithRequiredRequiresChildren ( )

Definition at line 102 of file GroupInputTest.php.

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

◆ testWithValuePreservesKeys()

GroupInputTest::testWithValuePreservesKeys ( )

Definition at line 170 of file GroupInputTest.php.

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

170  : void
171  {
172  $this->assertNotSame($this->child1, $this->child2);
173 
174  $this->group = new Group(
175  $this->data_factory,
176  $this->refinery,
177  $this->language,
178  ["child1" => $this->child1, "child2" => $this->child2],
179  "LABEL",
180  "BYLINE"
181  );
182 
183  $this->child1
184  ->method("withValue")
185  ->willReturn($this->child2);
186  $this->child1
187  ->method("isClientSideValueOk")
188  ->willReturn(true);
189  $this->child2
190  ->method("withValue")
191  ->willReturn($this->child1);
192  $this->child2
193  ->method("isClientSideValueOk")
194  ->willReturn(true);
195 
196  $new_group = $this->group->withValue(["child1" => 1,"child2" => 2]);
197 
198  $this->assertEquals(["child1" => $this->child2, "child2" => $this->child1], $new_group->getInputs());
199  }
+ Here is the call graph for this function:

Field Documentation

◆ $child1

GroupInputTest::$child1
protected

Definition at line 46 of file GroupInputTest.php.

◆ $child2

GroupInputTest::$child2
protected

Definition at line 51 of file GroupInputTest.php.

◆ $data_factory

Data Factory GroupInputTest::$data_factory
protected

Definition at line 53 of file GroupInputTest.php.

◆ $group

Group GroupInputTest::$group
protected

Definition at line 60 of file GroupInputTest.php.

◆ $language

GroupInputTest::$language
protected

Definition at line 58 of file GroupInputTest.php.

◆ $refinery

Refinery GroupInputTest::$refinery
protected

Definition at line 59 of file GroupInputTest.php.


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