ILIAS  trunk Revision v11.0_alpha-1811-gd2d5443e411
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator 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 ()
 
 testCommonRendering ()
 

Protected Attributes

 $child1
 
 $child2
 
Data Factory $data_factory
 
 $language
 
Refinery $refinery
 
ILIAS UI Component Input Field Group $optional_group
 
OptionalGroup $group
 

Detailed Description

Definition at line 40 of file OptionalGroupInputTest.php.

Member Function Documentation

◆ setUp()

OptionalGroupInputTest::setUp ( )

Definition at line 65 of file OptionalGroupInputTest.php.

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

65  : void
66  {
67  $this->child1 = $this->createMock(Input11::class);
68  $this->child2 = $this->createMock(Input12::class);
69  $this->data_factory = new Data\Factory();
70  $this->language = $this->createMock(ILIAS\Language\Language::class);
71  $this->refinery = new ILIAS\Refinery\Factory($this->data_factory, $this->language);
72 
73  $this->child1
74  ->method("withNameFrom")
75  ->willReturn($this->child1);
76  $this->child2
77  ->method("withNameFrom")
78  ->willReturn($this->child2);
79 
80  $this->optional_group = (new OptionalGroup(
81  $this->data_factory,
82  $this->refinery,
83  $this->language,
84  [$this->child1, $this->child2],
85  "LABEL",
86  "BYLINE"
87  ))->withNameFrom(new class () implements NameSource {
88  public function getNewName(): string
89  {
90  return "name0";
91  }
92  });
93  }
Interface Observer Contains several chained tasks and infos about them.
withNameFrom(NameSource $source, ?string $parent_name=null)
language()
description: > Example for rendring a language glyph.
Definition: language.php:41
Describes a source for input names.
Definition: NameSource.php:26
+ Here is the call graph for this function:

◆ testCommonRendering()

OptionalGroupInputTest::testCommonRendering ( )

Definition at line 391 of file OptionalGroupInputTest.php.

References Vendor\Package\$f, and ILIAS\UI\Implementation\Component\Input\Input\withNameFrom().

391  : void
392  {
393  $f = $this->getFieldFactory();
394  $label = "label";
395  $og = $f->optionalGroup(
396  [
397  "field_1" => $f->text("f"),
398  "field_2" => $f->text("f2")
399  ],
400  $label
401  )->withNameFrom((new DefNamesource()));
402 
403  $this->testWithError($og);
404  $this->testWithNoByline($og);
405  $this->testWithRequired($og);
406  $this->testWithDisabled($og);
407  $this->testWithAdditionalOnloadCodeRendersId($og);
408  }
withNameFrom(NameSource $source, ?string $parent_name=null)
+ Here is the call graph for this function:

◆ testGroupAcceptsNullButDoesNotForward()

OptionalGroupInputTest::testGroupAcceptsNullButDoesNotForward ( )

Definition at line 206 of file OptionalGroupInputTest.php.

References null.

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

◆ testGroupForwardsValuesOnGetValue()

OptionalGroupInputTest::testGroupForwardsValuesOnGetValue ( )

Definition at line 231 of file OptionalGroupInputTest.php.

231  : void
232  {
233  $this->assertNotSame($this->child1, $this->child2);
234 
235  $this->child1
236  ->expects($this->once())
237  ->method("getValue")
238  ->with()
239  ->willReturn("one");
240  $this->child2
241  ->expects($this->once())
242  ->method("getValue")
243  ->with()
244  ->willReturn("two");
245 
246  $vals = $this->optional_group->getValue();
247 
248  $this->assertEquals(["one", "two"], $vals);
249  }

◆ testGroupOnlyDoesNoAcceptArrayValuesWithWrongLength()

OptionalGroupInputTest::testGroupOnlyDoesNoAcceptArrayValuesWithWrongLength ( )

Definition at line 200 of file OptionalGroupInputTest.php.

200  : void
201  {
202  $this->expectException(InvalidArgumentException::class);
203  $this->optional_group->withValue([1]);
204  }

◆ testGroupOnlyDoesNoAcceptNonArrayValue()

OptionalGroupInputTest::testGroupOnlyDoesNoAcceptNonArrayValue ( )

Definition at line 194 of file OptionalGroupInputTest.php.

194  : void
195  {
196  $this->expectException(InvalidArgumentException::class);
197  $this->optional_group->withValue(1);
198  }

◆ testOptionalGroupForwardsValuesOnWithValue()

OptionalGroupInputTest::testOptionalGroupForwardsValuesOnWithValue ( )

Definition at line 162 of file OptionalGroupInputTest.php.

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

◆ testOptionalGroupMayOnlyHaveInputChildren()

OptionalGroupInputTest::testOptionalGroupMayOnlyHaveInputChildren ( )

Definition at line 148 of file OptionalGroupInputTest.php.

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

149  {
150  $this->expectException(InvalidArgumentException::class);
151 
152  $this->group = new OptionalGroup(
153  $this->data_factory,
154  $this->refinery,
155  $this->language,
156  ["foo", "bar"],
157  "LABEL",
158  "BYLINE"
159  );
160  }
language()
description: > Example for rendring a language glyph.
Definition: language.php:41
+ Here is the call graph for this function:

◆ testThatOptionalGroupIsNotRequiredBecauseOfItsChildren()

OptionalGroupInputTest::testThatOptionalGroupIsNotRequiredBecauseOfItsChildren ( )

Definition at line 135 of file OptionalGroupInputTest.php.

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

◆ testWithDisabledDisablesChildren()

OptionalGroupInputTest::testWithDisabledDisablesChildren ( )

Definition at line 95 of file OptionalGroupInputTest.php.

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

◆ testWithInputCallsChildrenAndAppliesOperations()

OptionalGroupInputTest::testWithInputCallsChildrenAndAppliesOperations ( )

Definition at line 251 of file OptionalGroupInputTest.php.

References null, and ILIAS\Repository\refinery().

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

◆ testWithInputDoesNotApplyOperationsOnError()

OptionalGroupInputTest::testWithInputDoesNotApplyOperationsOnError ( )

Definition at line 300 of file OptionalGroupInputTest.php.

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

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

◆ testWithInputDoesNotCallChildrenWhenUnchecked()

OptionalGroupInputTest::testWithInputDoesNotCallChildrenWhenUnchecked ( )

Definition at line 350 of file OptionalGroupInputTest.php.

References null, and ILIAS\Repository\refinery().

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

◆ testWithRequiredDoesNotRequire()

OptionalGroupInputTest::testWithRequiredDoesNotRequire ( )

Definition at line 117 of file OptionalGroupInputTest.php.

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

Field Documentation

◆ $child1

OptionalGroupInputTest::$child1
protected

Definition at line 47 of file OptionalGroupInputTest.php.

◆ $child2

OptionalGroupInputTest::$child2
protected

Definition at line 52 of file OptionalGroupInputTest.php.

◆ $data_factory

Data Factory OptionalGroupInputTest::$data_factory
protected

Definition at line 54 of file OptionalGroupInputTest.php.

◆ $group

OptionalGroup OptionalGroupInputTest::$group
protected

Definition at line 63 of file OptionalGroupInputTest.php.

◆ $language

OptionalGroupInputTest::$language
protected

Definition at line 59 of file OptionalGroupInputTest.php.

◆ $optional_group

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

Definition at line 62 of file OptionalGroupInputTest.php.

◆ $refinery

Refinery OptionalGroupInputTest::$refinery
protected

Definition at line 61 of file OptionalGroupInputTest.php.


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