ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
OptionalGroupInputTest Class Reference
+ Inheritance diagram for OptionalGroupInputTest:
+ Collaboration diagram for OptionalGroupInputTest:

Public Member Functions

 setUp ()
 
 testWithDisabledDisablesChildren ()
 
 testWithRequiredDoesNotRequire ()
 
 testThatOptionalGroupIsNotRequiredBecauseOfItsChildren ()
 
 testOptionalGroupMayOnlyHaveInputChildren ()
 
 testOptionalGroupForwardsValuesOnWithValue ()
 
 testGroupOnlyDoesNoAcceptNonArrayValue ()
 
 testGroupOnlyDoesNoAcceptArrayValuesWithWrongLength ()
 
 testGroupAcceptsNullButDoesNotForward ()
 
 testGroupForwardsValuesOnGetValue ()
 
 testWithInputCallsChildrenAndAppliesOperations ()
 
 testWithInputDoesNotApplyOperationsOnError ()
 
 testWithInputDoesNotCallChildrenWhenUnchecked ()
 
- 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
 
ILIAS UI Component Input Field Group $optional_group
 
OptionalGroup $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 39 of file OptionalGroupInputTest.php.

Member Function Documentation

◆ setUp()

OptionalGroupInputTest::setUp ( )

Definition at line 62 of file OptionalGroupInputTest.php.

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

62  : void
63  {
64  $this->child1 = $this->createMock(Input11::class);
65  $this->child2 = $this->createMock(Input12::class);
66  $this->data_factory = new Data\Factory();
67  $this->language = $this->createMock(ilLanguage::class);
68  $this->refinery = new ILIAS\Refinery\Factory($this->data_factory, $this->language);
69 
70  $this->child1
71  ->method("withNameFrom")
72  ->willReturn($this->child1);
73  $this->child2
74  ->method("withNameFrom")
75  ->willReturn($this->child2);
76 
77  $this->optional_group = (new OptionalGroup(
78  $this->data_factory,
79  $this->refinery,
80  $this->language,
81  [$this->child1, $this->child2],
82  "LABEL",
83  "BYLINE"
84  ))->withNameFrom(new class () implements NameSource {
85  public function getNewName(): string
86  {
87  return "name0";
88  }
89  });
90  }
withNameFrom(NameSource $source, ?string $parent_name=null)
Describes a source for input names.
Definition: NameSource.php:26
+ Here is the call graph for this function:

◆ testGroupAcceptsNullButDoesNotForward()

OptionalGroupInputTest::testGroupAcceptsNullButDoesNotForward ( )

Definition at line 203 of file OptionalGroupInputTest.php.

203  : void
204  {
205  $this->assertNotSame($this->child1, $this->child2);
206 
207  $this->child1
208  ->expects($this->never())
209  ->method("withValue");
210  $this->child1
211  ->expects($this->never())
212  ->method("isClientSideValueOk");
213  $this->child2
214  ->expects($this->never())
215  ->method("withValue");
216  $this->child2
217  ->expects($this->never())
218  ->method("isClientSideValueOk");
219 
220  $new_group = $this->optional_group->withValue(null);
221 
222  $this->assertEquals([$this->child1, $this->child2], $new_group->getInputs());
223  $this->assertInstanceOf(OptionalGroup::class, $new_group);
224  $this->assertNotSame($this->optional_group, $new_group);
225  $this->assertEquals(null, $new_group->getValue());
226  }

◆ testGroupForwardsValuesOnGetValue()

OptionalGroupInputTest::testGroupForwardsValuesOnGetValue ( )

Definition at line 228 of file OptionalGroupInputTest.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->once())
239  ->method("getValue")
240  ->with()
241  ->willReturn("two");
242 
243  $vals = $this->optional_group->getValue();
244 
245  $this->assertEquals(["one", "two"], $vals);
246  }

◆ testGroupOnlyDoesNoAcceptArrayValuesWithWrongLength()

OptionalGroupInputTest::testGroupOnlyDoesNoAcceptArrayValuesWithWrongLength ( )

Definition at line 197 of file OptionalGroupInputTest.php.

197  : void
198  {
199  $this->expectException(InvalidArgumentException::class);
200  $this->optional_group->withValue([1]);
201  }

◆ testGroupOnlyDoesNoAcceptNonArrayValue()

OptionalGroupInputTest::testGroupOnlyDoesNoAcceptNonArrayValue ( )

Definition at line 191 of file OptionalGroupInputTest.php.

191  : void
192  {
193  $this->expectException(InvalidArgumentException::class);
194  $this->optional_group->withValue(1);
195  }

◆ testOptionalGroupForwardsValuesOnWithValue()

OptionalGroupInputTest::testOptionalGroupForwardsValuesOnWithValue ( )

Definition at line 159 of file OptionalGroupInputTest.php.

159  : void
160  {
161  $this->assertNotSame($this->child1, $this->child2);
162 
163  $this->child1
164  ->expects($this->once())
165  ->method("withValue")
166  ->with(1)
167  ->willReturn($this->child2);
168  $this->child1
169  ->expects($this->once())
170  ->method("isClientSideValueOk")
171  ->with(1)
172  ->willReturn(true);
173  $this->child2
174  ->expects($this->once())
175  ->method("withValue")
176  ->with(2)
177  ->willReturn($this->child1);
178  $this->child2
179  ->expects($this->once())
180  ->method("isClientSideValueOk")
181  ->with(2)
182  ->willReturn(true);
183 
184  $new_group = $this->optional_group->withValue([1,2]);
185 
186  $this->assertEquals([$this->child2, $this->child1], $new_group->getInputs());
187  $this->assertInstanceOf(OptionalGroup::class, $new_group);
188  $this->assertNotSame($this->optional_group, $new_group);
189  }

◆ testOptionalGroupMayOnlyHaveInputChildren()

OptionalGroupInputTest::testOptionalGroupMayOnlyHaveInputChildren ( )

Definition at line 145 of file OptionalGroupInputTest.php.

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

146  {
147  $this->expectException(InvalidArgumentException::class);
148 
149  $this->group = new OptionalGroup(
150  $this->data_factory,
151  $this->refinery,
152  $this->language,
153  ["foo", "bar"],
154  "LABEL",
155  "BYLINE"
156  );
157  }
+ Here is the call graph for this function:

◆ testThatOptionalGroupIsNotRequiredBecauseOfItsChildren()

OptionalGroupInputTest::testThatOptionalGroupIsNotRequiredBecauseOfItsChildren ( )

Definition at line 132 of file OptionalGroupInputTest.php.

132  : void
133  {
134  $this->assertNotSame($this->child1, $this->child2);
135  $this->child1->method('isRequired')->willReturn(true);
136  $this->child2->method('isRequired')->willReturn(true);
137 
138  $new_group = $this->optional_group;
139 
140  $this->assertEquals([$this->child1, $this->child2], $new_group->getInputs());
141  $this->assertInstanceOf(OptionalGroup::class, $new_group);
142  $this->assertFalse($new_group->isRequired());
143  }
ILIAS UI Component Input Field Group $optional_group

◆ testWithDisabledDisablesChildren()

OptionalGroupInputTest::testWithDisabledDisablesChildren ( )

Definition at line 92 of file OptionalGroupInputTest.php.

92  : void
93  {
94  $this->assertNotSame($this->child1, $this->child2);
95 
96  $this->child1
97  ->expects($this->once())
98  ->method("withDisabled")
99  ->with(true)
100  ->willReturn($this->child2);
101  $this->child2
102  ->expects($this->once())
103  ->method("withDisabled")
104  ->with(true)
105  ->willReturn($this->child1);
106 
107  $new_group = $this->optional_group->withDisabled(true);
108 
109  $this->assertEquals([$this->child2, $this->child1], $new_group->getInputs());
110  $this->assertInstanceOf(OptionalGroup::class, $new_group);
111  $this->assertNotSame($this->optional_group, $new_group);
112  }

◆ testWithInputCallsChildrenAndAppliesOperations()

OptionalGroupInputTest::testWithInputCallsChildrenAndAppliesOperations ( )

Definition at line 248 of file OptionalGroupInputTest.php.

References ILIAS\Repository\refinery().

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

◆ testWithInputDoesNotApplyOperationsOnError()

OptionalGroupInputTest::testWithInputDoesNotApplyOperationsOnError ( )

Definition at line 297 of file OptionalGroupInputTest.php.

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

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

◆ testWithInputDoesNotCallChildrenWhenUnchecked()

OptionalGroupInputTest::testWithInputDoesNotCallChildrenWhenUnchecked ( )

Definition at line 347 of file OptionalGroupInputTest.php.

References ILIAS\Repository\refinery().

347  : void
348  {
349  $this->assertNotSame($this->child1, $this->child2);
350 
351  $input_data = $this->createMock(InputData::class);
352 
353  $input_data
354  ->expects($this->once())
355  ->method("getOr")
356  ->with("name0", null)
357  ->willReturn(null);
358 
359  $this->child1
360  ->expects($this->never())
361  ->method("withInput");
362  $this->child1
363  ->expects($this->never())
364  ->method("getContent");
365  $this->child2
366  ->expects($this->never())
367  ->method("withInput");
368  $this->child2
369  ->expects($this->never())
370  ->method("getContent");
371 
372  $called = false;
373  $new_group = $this->optional_group
374  ->withAdditionalTransformation($this->refinery->custom()->transformation(function ($v) use (&$called): string {
375  $called = true;
376  $this->assertEquals(null, $v);
377  return "result";
378  }))
379  ->withInput($input_data);
380 
381  $this->assertTrue($called);
382  $this->assertEquals([$this->child1, $this->child2], $new_group->getInputs());
383  $this->assertInstanceOf(OptionalGroup::class, $new_group);
384  $this->assertNotSame($this->optional_group, $new_group);
385  $this->assertEquals($this->data_factory->ok("result"), $new_group->getContent());
386  }
+ Here is the call graph for this function:

◆ testWithRequiredDoesNotRequire()

OptionalGroupInputTest::testWithRequiredDoesNotRequire ( )

Definition at line 114 of file OptionalGroupInputTest.php.

114  : void
115  {
116  $this->assertNotSame($this->child1, $this->child2);
117 
118  $this->child1
119  ->expects($this->never())
120  ->method("withRequired");
121  $this->child2
122  ->expects($this->never())
123  ->method("withRequired");
124 
125  $new_group = $this->optional_group->withRequired(true);
126 
127  $this->assertEquals([$this->child1, $this->child2], $new_group->getInputs());
128  $this->assertInstanceOf(OptionalGroup::class, $new_group);
129  $this->assertNotSame($this->optional_group, $new_group);
130  }

Field Documentation

◆ $child1

OptionalGroupInputTest::$child1
protected

Definition at line 44 of file OptionalGroupInputTest.php.

◆ $child2

OptionalGroupInputTest::$child2
protected

Definition at line 49 of file OptionalGroupInputTest.php.

◆ $data_factory

Data Factory OptionalGroupInputTest::$data_factory
protected

Definition at line 51 of file OptionalGroupInputTest.php.

◆ $group

OptionalGroup OptionalGroupInputTest::$group
protected

Definition at line 60 of file OptionalGroupInputTest.php.

◆ $language

OptionalGroupInputTest::$language
protected

Definition at line 56 of file OptionalGroupInputTest.php.

◆ $optional_group

ILIAS UI Component Input Field Group OptionalGroupInputTest::$optional_group
protected

Definition at line 59 of file OptionalGroupInputTest.php.

◆ $refinery

Refinery OptionalGroupInputTest::$refinery
protected

Definition at line 58 of file OptionalGroupInputTest.php.


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