ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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 ()
 
 getHelpTextRetriever ()
 
 getUploadLimitResolver ()
 
 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 42 of file GroupInputTest.php.

Member Function Documentation

◆ getFieldFactory()

GroupInputTest::getFieldFactory ( )

Definition at line 369 of file GroupInputTest.php.

References getLanguage().

369  : FieldFactory
370  {
371  return new FieldFactory(
372  $this->createMock(\ILIAS\UI\Implementation\Component\Input\UploadLimitResolver::class),
374  new Data\Factory(),
375  $this->getRefinery(),
376  $this->getLanguage()
377  );
378  }
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 63 of file GroupInputTest.php.

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

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

◆ testBylineProperty()

GroupInputTest::testBylineProperty ( )

Definition at line 412 of file GroupInputTest.php.

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

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

◆ testErrorIsI18NOnError()

GroupInputTest::testErrorIsI18NOnError ( )

Definition at line 321 of file GroupInputTest.php.

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

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

◆ testGroupForwardsValuesOnGetValue()

GroupInputTest::testGroupForwardsValuesOnGetValue ( )

Definition at line 216 of file GroupInputTest.php.

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

◆ testGroupForwardsValuesOnWithValue()

GroupInputTest::testGroupForwardsValuesOnWithValue ( )

Definition at line 139 of file GroupInputTest.php.

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

◆ testGroupMayOnlyHaveInputChildren()

GroupInputTest::testGroupMayOnlyHaveInputChildren ( )

Definition at line 125 of file GroupInputTest.php.

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

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

◆ testGroupOnlyDoesNoAcceptArrayValuesWithWrongLength()

GroupInputTest::testGroupOnlyDoesNoAcceptArrayValuesWithWrongLength ( )

Definition at line 209 of file GroupInputTest.php.

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

◆ testGroupOnlyDoesNoAcceptNonArrayValue()

GroupInputTest::testGroupOnlyDoesNoAcceptNonArrayValue ( )

Definition at line 202 of file GroupInputTest.php.

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

◆ testGroupRendering()

GroupInputTest::testGroupRendering ( )

Definition at line 380 of file GroupInputTest.php.

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

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

◆ testGroupWithoutRequiredField()

GroupInputTest::testGroupWithoutRequiredField ( )

Definition at line 420 of file GroupInputTest.php.

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

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

◆ testGroupWithRequiredField()

GroupInputTest::testGroupWithRequiredField ( )

Definition at line 431 of file GroupInputTest.php.

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

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

◆ testWithDisabledDisablesChildren()

GroupInputTest::testWithDisabledDisablesChildren ( )

Definition at line 81 of file GroupInputTest.php.

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

◆ testWithInputCallsChildrenAndAppliesOperations()

GroupInputTest::testWithInputCallsChildrenAndAppliesOperations ( )

Definition at line 236 of file GroupInputTest.php.

References ILIAS\Repository\refinery().

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

◆ testWithInputDoesNotApplyOperationsOnError()

GroupInputTest::testWithInputDoesNotApplyOperationsOnError ( )

Definition at line 277 of file GroupInputTest.php.

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

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

◆ testWithoutChildren()

GroupInputTest::testWithoutChildren ( )

Definition at line 354 of file GroupInputTest.php.

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

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

◆ testWithRequiredRequiresChildren()

GroupInputTest::testWithRequiredRequiresChildren ( )

Definition at line 103 of file GroupInputTest.php.

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

◆ testWithValuePreservesKeys()

GroupInputTest::testWithValuePreservesKeys ( )

Definition at line 171 of file GroupInputTest.php.

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

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

Field Documentation

◆ $child1

GroupInputTest::$child1
protected

Definition at line 47 of file GroupInputTest.php.

◆ $child2

GroupInputTest::$child2
protected

Definition at line 52 of file GroupInputTest.php.

◆ $data_factory

Data Factory GroupInputTest::$data_factory
protected

Definition at line 54 of file GroupInputTest.php.

◆ $group

Group GroupInputTest::$group
protected

Definition at line 61 of file GroupInputTest.php.

◆ $language

GroupInputTest::$language
protected

Definition at line 59 of file GroupInputTest.php.

◆ $refinery

Refinery GroupInputTest::$refinery
protected

Definition at line 60 of file GroupInputTest.php.


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