ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 ()
 
- Public Member Functions inherited from ILIAS_UI_TestBase
 setUp ()
 
 tearDown ()
 
 getUIFactory ()
 
 getTemplateFactory ()
 
 getResourceRegistry ()
 
 getLanguage ()
 
 getJavaScriptBinding ()
 
 getRefinery ()
 
 getDefaultRenderer (JavaScriptBinding $js_binding=null)
 
 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 21 of file GroupInputTest.php.

Member Function Documentation

◆ setUp()

GroupInputTest::setUp ( )

Reimplemented from ILIAS_UI_TestBase.

Definition at line 28 of file GroupInputTest.php.

28 : void
29 {
30 $this->child1 = $this->createMock(Input1::class);
31 $this->child2 = $this->createMock(Input2::class);
32 $this->data_factory = new Data\Factory;
33 $this->language = $this->createMock(\ilLanguage::class);
34 $this->refinery = new \ILIAS\Refinery\Factory($this->data_factory, $this->language);
35
36 $this->group = new Group(
37 $this->data_factory,
38 $this->refinery,
39 $this->language,
40 [$this->child1, $this->child2],
41 "LABEL",
42 "BYLINE"
43 );
44 }
This implements the group input.
Definition: Group.php:20
language()
Definition: language.php:2

References language().

+ Here is the call graph for this function:

◆ testErrorIsI18NOnError()

GroupInputTest::testErrorIsI18NOnError ( )

Definition at line 287 of file GroupInputTest.php.

288 {
289 $this->assertNotSame($this->child1, $this->child2);
290
291 $input_data = $this->createMock(InputData::class);
292
293 $this->child1
294 ->method("withInput")
295 ->willReturn($this->child2);
296 $this->child1
297 ->method("getContent")
298 ->willReturn($this->data_factory->error(""));
299 $this->child2
300 ->method("withInput")
301 ->willReturn($this->child1);
302 $this->child2
303 ->method("getContent")
304 ->willReturn($this->data_factory->ok("two"));
305
306 $i18n = "THERE IS SOME ERROR IN THIS GROUP";
307 $this->language
308 ->expects($this->once())
309 ->method("txt")
310 ->with("ui_error_in_group")
311 ->willReturn($i18n);
312
313 $new_group = $this->group
314 ->withInput($input_data);
315
316 $this->assertTrue($new_group->getContent()->isError());
317 $this->assertEquals($i18n, $new_group->getContent()->error());
318 }

References language().

+ Here is the call graph for this function:

◆ testGroupForwardsValuesOnGetValue()

GroupInputTest::testGroupForwardsValuesOnGetValue ( )

Definition at line 182 of file GroupInputTest.php.

183 {
184 $this->assertNotSame($this->child1, $this->child2);
185
186 $this->child1
187 ->expects($this->once())
188 ->method("getValue")
189 ->with()
190 ->willReturn("one");
191 $this->child2
192 ->expects($this->once())
193 ->method("getValue")
194 ->with()
195 ->willReturn("two");
196
197 $vals = $this->group->getValue();
198
199 $this->assertEquals(["one", "two"], $vals);
200 }

◆ testGroupForwardsValuesOnWithValue()

GroupInputTest::testGroupForwardsValuesOnWithValue ( )

Definition at line 104 of file GroupInputTest.php.

105 {
106 $this->assertNotSame($this->child1, $this->child2);
107
108 $this->child1
109 ->expects($this->once())
110 ->method("withValue")
111 ->with(1)
112 ->willReturn($this->child2);
113 $this->child1
114 ->expects($this->once())
115 ->method("isClientSideValueOk")
116 ->with(1)
117 ->willReturn(true);
118 $this->child2
119 ->expects($this->once())
120 ->method("withValue")
121 ->with(2)
122 ->willReturn($this->child1);
123 $this->child2
124 ->expects($this->once())
125 ->method("isClientSideValueOk")
126 ->with(2)
127 ->willReturn(true);
128
129 $new_group = $this->group->withValue([1,2]);
130
131 $this->assertEquals([$this->child2, $this->child1], $new_group->getInputs());
132 $this->assertInstanceOf(Group::class, $new_group);
133 $this->assertNotSame($this->group, $new_group);
134 }

◆ testGroupMayOnlyHaveInputChildren()

GroupInputTest::testGroupMayOnlyHaveInputChildren ( )

Definition at line 90 of file GroupInputTest.php.

91 {
92 $this->expectException(\InvalidArgumentException::class);
93
94 $this->group = new Group(
95 $this->data_factory,
96 $this->refinery,
97 $this->language,
98 ["foo", "bar"],
99 "LABEL",
100 "BYLINE"
101 );
102 }

References language().

+ Here is the call graph for this function:

◆ testGroupOnlyDoesNoAcceptArrayValuesWithWrongLength()

GroupInputTest::testGroupOnlyDoesNoAcceptArrayValuesWithWrongLength ( )

Definition at line 175 of file GroupInputTest.php.

176 {
177 $this->expectException(\InvalidArgumentException::class);
178
179 $new_group = $this->group->withValue([1]);
180 }

◆ testGroupOnlyDoesNoAcceptNonArrayValue()

GroupInputTest::testGroupOnlyDoesNoAcceptNonArrayValue ( )

Definition at line 168 of file GroupInputTest.php.

169 {
170 $this->expectException(\InvalidArgumentException::class);
171
172 $new_group = $this->group->withValue(1);
173 }

◆ testWithDisabledDisablesChildren()

GroupInputTest::testWithDisabledDisablesChildren ( )

Definition at line 46 of file GroupInputTest.php.

47 {
48 $this->assertNotSame($this->child1, $this->child2);
49
50 $this->child1
51 ->expects($this->once())
52 ->method("withDisabled")
53 ->with(true)
54 ->willReturn($this->child2);
55 $this->child2
56 ->expects($this->once())
57 ->method("withDisabled")
58 ->with(true)
59 ->willReturn($this->child1);
60
61 $new_group = $this->group->withDisabled(true);
62
63 $this->assertEquals([$this->child2, $this->child1], $new_group->getInputs());
64 $this->assertInstanceOf(Group::class, $new_group);
65 $this->assertNotSame($this->group, $new_group);
66 }

◆ testWithInputCallsChildrenAndAppliesOperations()

GroupInputTest::testWithInputCallsChildrenAndAppliesOperations ( )

Definition at line 202 of file GroupInputTest.php.

203 {
204 $this->assertNotSame($this->child1, $this->child2);
205
206 $input_data = $this->createMock(InputData::class);
207
208 $this->child1
209 ->expects($this->once())
210 ->method("withInput")
211 ->with($input_data)
212 ->willReturn($this->child2);
213 $this->child1
214 ->expects($this->once())
215 ->method("getContent")
216 ->willReturn($this->data_factory->ok("one"));
217 $this->child2
218 ->expects($this->once())
219 ->method("withInput")
220 ->with($input_data)
221 ->willReturn($this->child1);
222 $this->child2
223 ->expects($this->once())
224 ->method("getContent")
225 ->willReturn($this->data_factory->ok("two"));
226
227 $called = false;
228 $new_group = $this->group
229 ->withAdditionalTransformation($this->refinery->custom()->transformation(function ($v) use (&$called) {
230 $called = true;
231 $this->assertEquals(["two", "one"], $v);
232 return "result";
233 }))
234 ->withInput($input_data);
235
236 $this->assertTrue($called);
237 $this->assertEquals([$this->child2, $this->child1], $new_group->getInputs());
238 $this->assertInstanceOf(Group::class, $new_group);
239 $this->assertNotSame($this->group, $new_group);
240 $this->assertEquals($this->data_factory->ok("result"), $new_group->getContent());
241 }

◆ testWithInputDoesNotApplyOperationsOnError()

GroupInputTest::testWithInputDoesNotApplyOperationsOnError ( )

Definition at line 243 of file GroupInputTest.php.

244 {
245 $this->assertNotSame($this->child1, $this->child2);
246
247 $input_data = $this->createMock(InputData::class);
248
249 $this->child1
250 ->expects($this->once())
251 ->method("withInput")
252 ->with($input_data)
253 ->willReturn($this->child2);
254 $this->child1
255 ->expects($this->once())
256 ->method("getContent")
257 ->willReturn($this->data_factory->error(""));
258 $this->child2
259 ->expects($this->once())
260 ->method("withInput")
261 ->with($input_data)
262 ->willReturn($this->child1);
263 $this->child2
264 ->expects($this->once())
265 ->method("getContent")
266 ->willReturn($this->data_factory->ok("two"));
267
268 $i18n = "THERE IS SOME ERROR IN THIS GROUP";
269 $this->language
270 ->expects($this->once())
271 ->method("txt")
272 ->with("ui_error_in_group")
273 ->willReturn($i18n);
274
275 $new_group = $this->group
276 ->withAdditionalTransformation($this->refinery->custom()->transformation(function ($v) {
277 $this->assertFalse(true, "This should not happen.");
278 }))
279 ->withInput($input_data);
280
281 $this->assertEquals([$this->child2, $this->child1], $new_group->getInputs());
282 $this->assertInstanceOf(Group::class, $new_group);
283 $this->assertNotSame($this->group, $new_group);
284 $this->assertTrue($new_group->getContent()->isError());
285 }

References language().

+ Here is the call graph for this function:

◆ testWithoutChildren()

GroupInputTest::testWithoutChildren ( )

Definition at line 319 of file GroupInputTest.php.

320 {
321 $group = new Group(
322 $this->data_factory,
323 $this->refinery,
324 $this->language,
325 [],
326 "LABEL",
327 "BYLINE"
328 );
329 $content = $group->getContent();
330 $this->assertInstanceOf(\ILIAS\Data\Result\Ok::class, $content);
331 $this->assertCount(0, $content->value());
332 }
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 68 of file GroupInputTest.php.

69 {
70 $this->assertNotSame($this->child1, $this->child2);
71
72 $this->child1
73 ->expects($this->once())
74 ->method("withRequired")
75 ->with(true)
76 ->willReturn($this->child2);
77 $this->child2
78 ->expects($this->once())
79 ->method("withRequired")
80 ->with(true)
81 ->willReturn($this->child1);
82
83 $new_group = $this->group->withRequired(true);
84
85 $this->assertEquals([$this->child2, $this->child1], $new_group->getInputs());
86 $this->assertInstanceOf(Group::class, $new_group);
87 $this->assertNotSame($this->group, $new_group);
88 }

◆ testWithValuePreservesKeys()

GroupInputTest::testWithValuePreservesKeys ( )

Definition at line 136 of file GroupInputTest.php.

137 {
138 $this->assertNotSame($this->child1, $this->child2);
139
140 $this->group = new Group(
141 $this->data_factory,
142 $this->refinery,
143 $this->language,
144 ["child1" => $this->child1, "child2" => $this->child2],
145 "LABEL",
146 "BYLINE"
147 );
148
149 $this->child1
150 ->method("withValue")
151 ->willReturn($this->child2);
152 $this->child1
153 ->method("isClientSideValueOk")
154 ->willReturn(true);
155 $this->child2
156 ->method("withValue")
157 ->willReturn($this->child1);
158 $this->child2
159 ->method("isClientSideValueOk")
160 ->willReturn(true);
161
162 $new_group = $this->group->withValue(["child1" => 1,"child2" => 2]);
163
164 $this->assertEquals(["child1" => $this->child2, "child2" => $this->child1], $new_group->getInputs());
165 }

References language().

+ Here is the call graph for this function:

Field Documentation

◆ $refinery

GroupInputTest::$refinery
private

Definition at line 26 of file GroupInputTest.php.


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