ILIAS  release_7 Revision v7.30-3-g800a261c036
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 ()
 
 testGroupWithoutRequiredField ()
 
 testGroupWithRequiredField ()
 
- Public Member Functions inherited from ILIAS_UI_TestBase
 setUp ()
 
 tearDown ()
 
 getUIFactory ()
 
 getTemplateFactory ()
 
 getResourceRegistry ()
 
 getLanguage ()
 
 getJavaScriptBinding ()
 
 getRefinery ()
 
 getImagePathResolver ()
 
 getDefaultRenderer (JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
 
 getDecoratedRenderer (Renderer $default)
 
 normalizeHTML ($html)
 
 assertHTMLEquals ($expected_html_as_string, $html_as_string)
 

Private Attributes

 $refinery
 

Additional Inherited Members

- Protected Member Functions inherited from ILIAS_UI_TestBase
 brutallyTrimHTML ($html)
 A more radical version of normalizeHTML. More...
 

Detailed Description

Definition at line 34 of file GroupInputTest.php.

Member Function Documentation

◆ getFieldFactory()

GroupInputTest::getFieldFactory ( )

Definition at line 347 of file GroupInputTest.php.

348 {
349 $factory = new Field\Factory(
351 new Data\Factory(),
352 $this->getRefinery(),
353 $this->getLanguage()
354 );
355 return $factory;
356 }
Builds data types.
Definition: Factory.php:20
$factory
Definition: metadata.php:58

References $factory, ILIAS_UI_TestBase\getLanguage(), and ILIAS_UI_TestBase\getRefinery().

Referenced by testGroupRendering(), testGroupWithoutRequiredField(), and testGroupWithRequiredField().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setUp()

GroupInputTest::setUp ( )

Reimplemented from ILIAS_UI_TestBase.

Definition at line 41 of file GroupInputTest.php.

41 : void
42 {
43 $this->child1 = $this->createMock(Input1::class);
44 $this->child2 = $this->createMock(Input2::class);
45 $this->data_factory = new Data\Factory;
46 $this->language = $this->createMock(\ilLanguage::class);
47 $this->refinery = new \ILIAS\Refinery\Factory($this->data_factory, $this->language);
48
49 $this->group = new Field\Group(
50 $this->data_factory,
51 $this->refinery,
52 $this->language,
53 [$this->child1, $this->child2],
54 "LABEL",
55 "BYLINE"
56 );
57 }
language()
Definition: language.php:2

References language().

+ Here is the call graph for this function:

◆ testErrorIsI18NOnError()

GroupInputTest::testErrorIsI18NOnError ( )

Definition at line 300 of file GroupInputTest.php.

301 {
302 $this->assertNotSame($this->child1, $this->child2);
303
304 $input_data = $this->createMock(InputData::class);
305
306 $this->child1
307 ->method("withInput")
308 ->willReturn($this->child2);
309 $this->child1
310 ->method("getContent")
311 ->willReturn($this->data_factory->error(""));
312 $this->child2
313 ->method("withInput")
314 ->willReturn($this->child1);
315 $this->child2
316 ->method("getContent")
317 ->willReturn($this->data_factory->ok("two"));
318
319 $i18n = "THERE IS SOME ERROR IN THIS GROUP";
320 $this->language
321 ->expects($this->once())
322 ->method("txt")
323 ->with("ui_error_in_group")
324 ->willReturn($i18n);
325
326 $new_group = $this->group
327 ->withInput($input_data);
328
329 $this->assertTrue($new_group->getContent()->isError());
330 $this->assertEquals($i18n, $new_group->getContent()->error());
331 }

References language().

+ Here is the call graph for this function:

◆ testGroupForwardsValuesOnGetValue()

GroupInputTest::testGroupForwardsValuesOnGetValue ( )

Definition at line 195 of file GroupInputTest.php.

196 {
197 $this->assertNotSame($this->child1, $this->child2);
198
199 $this->child1
200 ->expects($this->once())
201 ->method("getValue")
202 ->with()
203 ->willReturn("one");
204 $this->child2
205 ->expects($this->once())
206 ->method("getValue")
207 ->with()
208 ->willReturn("two");
209
210 $vals = $this->group->getValue();
211
212 $this->assertEquals(["one", "two"], $vals);
213 }

◆ testGroupForwardsValuesOnWithValue()

GroupInputTest::testGroupForwardsValuesOnWithValue ( )

Definition at line 117 of file GroupInputTest.php.

118 {
119 $this->assertNotSame($this->child1, $this->child2);
120
121 $this->child1
122 ->expects($this->once())
123 ->method("withValue")
124 ->with(1)
125 ->willReturn($this->child2);
126 $this->child1
127 ->expects($this->once())
128 ->method("isClientSideValueOk")
129 ->with(1)
130 ->willReturn(true);
131 $this->child2
132 ->expects($this->once())
133 ->method("withValue")
134 ->with(2)
135 ->willReturn($this->child1);
136 $this->child2
137 ->expects($this->once())
138 ->method("isClientSideValueOk")
139 ->with(2)
140 ->willReturn(true);
141
142 $new_group = $this->group->withValue([1,2]);
143
144 $this->assertEquals([$this->child2, $this->child1], $new_group->getInputs());
145 $this->assertInstanceOf(Field\Group::class, $new_group);
146 $this->assertNotSame($this->group, $new_group);
147 }

◆ testGroupMayOnlyHaveInputChildren()

GroupInputTest::testGroupMayOnlyHaveInputChildren ( )

Definition at line 103 of file GroupInputTest.php.

104 {
105 $this->expectException(\InvalidArgumentException::class);
106
107 $this->group = new Field\Group(
108 $this->data_factory,
109 $this->refinery,
110 $this->language,
111 ["foo", "bar"],
112 "LABEL",
113 "BYLINE"
114 );
115 }

References language().

+ Here is the call graph for this function:

◆ testGroupOnlyDoesNoAcceptArrayValuesWithWrongLength()

GroupInputTest::testGroupOnlyDoesNoAcceptArrayValuesWithWrongLength ( )

Definition at line 188 of file GroupInputTest.php.

189 {
190 $this->expectException(\InvalidArgumentException::class);
191
192 $new_group = $this->group->withValue([1]);
193 }

◆ testGroupOnlyDoesNoAcceptNonArrayValue()

GroupInputTest::testGroupOnlyDoesNoAcceptNonArrayValue ( )

Definition at line 181 of file GroupInputTest.php.

182 {
183 $this->expectException(\InvalidArgumentException::class);
184
185 $new_group = $this->group->withValue(1);
186 }

◆ testGroupRendering()

GroupInputTest::testGroupRendering ( )

Definition at line 358 of file GroupInputTest.php.

359 {
360 $f = $this->getFieldFactory();
361 $inputs = [
362 $f->text("input1", "in 1"),
363 $f->text("input2", "in 2")
364 ];
365 $label = 'group label';
366 $group = $f->group($inputs, $label);
367
368 $expected = <<<EOT
369 <div class="form-group row">
370 <label for="id_1" class="control-label col-sm-3">input1</label>
371 <div class="col-sm-9">
372 <input id="id_1" type="text" name="" class="form-control form-control-sm" />
373 <div class="help-block">in 1</div>
374 </div>
375 </div>
376 <div class="form-group row">
377 <label for="id_2" class="control-label col-sm-3">input2</label>
378 <div class="col-sm-9">
379 <input id="id_2" type="text" name="" class="form-control form-control-sm" />
380 <div class="help-block">in 2</div>
381 </div>
382 </div>
383EOT;
384 $actual = $this->brutallyTrimHTML($this->getDefaultRenderer()->render($group));
385 $expected = $this->brutallyTrimHTML($expected);
386 $this->assertEquals($expected, $actual);
387 }
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311
brutallyTrimHTML($html)
A more radical version of normalizeHTML.
Definition: Base.php:392

References Vendor\Package\$f, ILIAS_UI_TestBase\brutallyTrimHTML(), ILIAS_UI_TestBase\getDefaultRenderer(), and getFieldFactory().

+ Here is the call graph for this function:

◆ testGroupWithoutRequiredField()

GroupInputTest::testGroupWithoutRequiredField ( )

Definition at line 389 of file GroupInputTest.php.

389 : void
390 {
391 $f = $this->getFieldFactory();
392 $inputs = [
393 $f->text(""),
394 $f->text("")
395 ];
396 $group = $f->group($inputs, '');
397 $this->assertFalse($group->isRequired());
398 }

References Vendor\Package\$f, and getFieldFactory().

+ Here is the call graph for this function:

◆ testGroupWithRequiredField()

GroupInputTest::testGroupWithRequiredField ( )

Definition at line 400 of file GroupInputTest.php.

400 : void
401 {
402 $f = $this->getFieldFactory();
403 $inputs = [
404 $f->text(""),
405 $f->text("")->withRequired(true)
406 ];
407 $group = $f->group($inputs, '');
408 $this->assertTrue($group->isRequired());
409 }

References Vendor\Package\$f, and getFieldFactory().

+ Here is the call graph for this function:

◆ testWithDisabledDisablesChildren()

GroupInputTest::testWithDisabledDisablesChildren ( )

Definition at line 59 of file GroupInputTest.php.

60 {
61 $this->assertNotSame($this->child1, $this->child2);
62
63 $this->child1
64 ->expects($this->once())
65 ->method("withDisabled")
66 ->with(true)
67 ->willReturn($this->child2);
68 $this->child2
69 ->expects($this->once())
70 ->method("withDisabled")
71 ->with(true)
72 ->willReturn($this->child1);
73
74 $new_group = $this->group->withDisabled(true);
75
76 $this->assertEquals([$this->child2, $this->child1], $new_group->getInputs());
77 $this->assertInstanceOf(Field\Group::class, $new_group);
78 $this->assertNotSame($this->group, $new_group);
79 }

◆ testWithInputCallsChildrenAndAppliesOperations()

GroupInputTest::testWithInputCallsChildrenAndAppliesOperations ( )

Definition at line 215 of file GroupInputTest.php.

216 {
217 $this->assertNotSame($this->child1, $this->child2);
218
219 $input_data = $this->createMock(InputData::class);
220
221 $this->child1
222 ->expects($this->once())
223 ->method("withInput")
224 ->with($input_data)
225 ->willReturn($this->child2);
226 $this->child1
227 ->expects($this->once())
228 ->method("getContent")
229 ->willReturn($this->data_factory->ok("one"));
230 $this->child2
231 ->expects($this->once())
232 ->method("withInput")
233 ->with($input_data)
234 ->willReturn($this->child1);
235 $this->child2
236 ->expects($this->once())
237 ->method("getContent")
238 ->willReturn($this->data_factory->ok("two"));
239
240 $called = false;
241 $new_group = $this->group
242 ->withAdditionalTransformation($this->refinery->custom()->transformation(function ($v) use (&$called) {
243 $called = true;
244 $this->assertEquals(["two", "one"], $v);
245 return "result";
246 }))
247 ->withInput($input_data);
248
249 $this->assertTrue($called);
250 $this->assertEquals([$this->child2, $this->child1], $new_group->getInputs());
251 $this->assertInstanceOf(Field\Group::class, $new_group);
252 $this->assertNotSame($this->group, $new_group);
253 $this->assertEquals($this->data_factory->ok("result"), $new_group->getContent());
254 }

◆ testWithInputDoesNotApplyOperationsOnError()

GroupInputTest::testWithInputDoesNotApplyOperationsOnError ( )

Definition at line 256 of file GroupInputTest.php.

257 {
258 $this->assertNotSame($this->child1, $this->child2);
259
260 $input_data = $this->createMock(InputData::class);
261
262 $this->child1
263 ->expects($this->once())
264 ->method("withInput")
265 ->with($input_data)
266 ->willReturn($this->child2);
267 $this->child1
268 ->expects($this->once())
269 ->method("getContent")
270 ->willReturn($this->data_factory->error(""));
271 $this->child2
272 ->expects($this->once())
273 ->method("withInput")
274 ->with($input_data)
275 ->willReturn($this->child1);
276 $this->child2
277 ->expects($this->once())
278 ->method("getContent")
279 ->willReturn($this->data_factory->ok("two"));
280
281 $i18n = "THERE IS SOME ERROR IN THIS GROUP";
282 $this->language
283 ->expects($this->once())
284 ->method("txt")
285 ->with("ui_error_in_group")
286 ->willReturn($i18n);
287
288 $new_group = $this->group
289 ->withAdditionalTransformation($this->refinery->custom()->transformation(function ($v) {
290 $this->assertFalse(true, "This should not happen.");
291 }))
292 ->withInput($input_data);
293
294 $this->assertEquals([$this->child2, $this->child1], $new_group->getInputs());
295 $this->assertInstanceOf(Field\Group::class, $new_group);
296 $this->assertNotSame($this->group, $new_group);
297 $this->assertTrue($new_group->getContent()->isError());
298 }

References language().

+ Here is the call graph for this function:

◆ testWithoutChildren()

GroupInputTest::testWithoutChildren ( )

Definition at line 332 of file GroupInputTest.php.

333 {
334 $group = new Field\Group(
335 $this->data_factory,
336 $this->refinery,
337 $this->language,
338 [],
339 "LABEL",
340 "BYLINE"
341 );
342 $content = $group->getContent();
343 $this->assertInstanceOf(\ILIAS\Data\Result\Ok::class, $content);
344 $this->assertCount(0, $content->value());
345 }
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:12
Class ChatMainBarProvider \MainMenu\Provider.

References language().

+ Here is the call graph for this function:

◆ testWithRequiredRequiresChildren()

GroupInputTest::testWithRequiredRequiresChildren ( )

Definition at line 81 of file GroupInputTest.php.

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

◆ testWithValuePreservesKeys()

GroupInputTest::testWithValuePreservesKeys ( )

Definition at line 149 of file GroupInputTest.php.

150 {
151 $this->assertNotSame($this->child1, $this->child2);
152
153 $this->group = new Field\Group(
154 $this->data_factory,
155 $this->refinery,
156 $this->language,
157 ["child1" => $this->child1, "child2" => $this->child2],
158 "LABEL",
159 "BYLINE"
160 );
161
162 $this->child1
163 ->method("withValue")
164 ->willReturn($this->child2);
165 $this->child1
166 ->method("isClientSideValueOk")
167 ->willReturn(true);
168 $this->child2
169 ->method("withValue")
170 ->willReturn($this->child1);
171 $this->child2
172 ->method("isClientSideValueOk")
173 ->willReturn(true);
174
175 $new_group = $this->group->withValue(["child1" => 1,"child2" => 2]);
176
177 $this->assertEquals(["child1" => $this->child2, "child2" => $this->child1], $new_group->getInputs());
178 }

References language().

+ Here is the call graph for this function:

Field Documentation

◆ $refinery

GroupInputTest::$refinery
private

Definition at line 39 of file GroupInputTest.php.


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