ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ILIAS\Tests\Setup\AgentCollectionTest Class Reference
+ Inheritance diagram for ILIAS\Tests\Setup\AgentCollectionTest:
+ Collaboration diagram for ILIAS\Tests\Setup\AgentCollectionTest:

Public Member Functions

 testHasConfig ()
 
 testGetConfigInput ()
 
 testGetConfigInputUsesSuppliedConfig ()
 
 testGetArrayToConfigTransformation ()
 
 testArrayToConfigTransformationAllowsUnsetFields ()
 
 testGetInstallObjective ()
 
 testGetUpdateObjective ()
 

Detailed Description

Definition at line 14 of file AgentCollectionTest.php.

Member Function Documentation

◆ testArrayToConfigTransformationAllowsUnsetFields()

ILIAS\Tests\Setup\AgentCollectionTest::testArrayToConfigTransformationAllowsUnsetFields ( )

Definition at line 213 of file AgentCollectionTest.php.

214 {
215 $ff = $this->createMock(FieldFactory::class);
216 $refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
217
218 $c1 = $this->newAgent();
219 $c2 = $this->newAgent();
220 $c3 = $this->newAgent();
221
222 $conf1 = $this->newConfig();
223 $conf3 = $this->newConfig();
224
225 foreach ([$c1,$c3] as $c) {
226 $c
227 ->method("hasConfig")
228 ->willReturn(true);
229 }
230 $c2
231 ->method("hasConfig")
232 ->willReturn(false);
233
234 $arr = ["c1" => ["c1_data"]];
235
236 $c1
237 ->expects($this->once())
238 ->method("getArrayToConfigTransformation")
239 ->with()
240 ->willReturn($refinery->custom()->transformation(function ($v) use ($conf1) {
241 $this->assertEquals($v, ["c1_data"]);
242 return $conf1;
243 }));
244 $c2
245 ->expects($this->never())
246 ->method("getArrayToConfigTransformation");
247 $c3
248 ->expects($this->once())
249 ->method("getArrayToConfigTransformation")
250 ->with()
251 ->willReturn($refinery->custom()->transformation(function ($v) use ($conf3) {
252 $this->assertEquals($v, null);
253 return $conf3;
254 }));
255
256 $col = new Setup\AgentCollection($ff, $refinery, ["c1" => $c1,"c2" => $c2,"c3" => $c3]);
257 $trafo = $col->getArrayToConfigTransformation();
258 $conf = $trafo($arr);
259
260 $this->assertInstanceOf(Setup\ConfigCollection::class, $conf);
261 $this->assertEquals(["c1", "c3"], $conf->getKeys());
262 $this->assertEquals($conf1, $conf->getConfig("c1"));
263 $this->assertEquals($conf3, $conf->getConfig("c3"));
264 }

References Vendor\Package\$c.

◆ testGetArrayToConfigTransformation()

ILIAS\Tests\Setup\AgentCollectionTest::testGetArrayToConfigTransformation ( )

Definition at line 160 of file AgentCollectionTest.php.

161 {
162 $ff = $this->createMock(FieldFactory::class);
163 $refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
164
165 $c1 = $this->newAgent();
166 $c2 = $this->newAgent();
167 $c3 = $this->newAgent();
168
169 $conf1 = $this->newConfig();
170 $conf3 = $this->newConfig();
171
172 foreach ([$c1,$c3] as $c) {
173 $c
174 ->method("hasConfig")
175 ->willReturn(true);
176 }
177 $c2
178 ->method("hasConfig")
179 ->willReturn(false);
180
181 $arr = ["c1" => ["c1_data"], "c3" => ["c3_data"]];
182
183 $c1
184 ->expects($this->once())
185 ->method("getArrayToConfigTransformation")
186 ->with()
187 ->willReturn($refinery->custom()->transformation(function ($v) use ($conf1) {
188 $this->assertEquals($v, ["c1_data"]);
189 return $conf1;
190 }));
191 $c2
192 ->expects($this->never())
193 ->method("getArrayToConfigTransformation");
194 $c3
195 ->expects($this->once())
196 ->method("getArrayToConfigTransformation")
197 ->with()
198 ->willReturn($refinery->custom()->transformation(function ($v) use ($conf3) {
199 $this->assertEquals($v, ["c3_data"]);
200 return $conf3;
201 }));
202
203 $col = new Setup\AgentCollection($ff, $refinery, ["c1" => $c1,"c2" => $c2,"c3" => $c3]);
204 $trafo = $col->getArrayToConfigTransformation();
205 $conf = $trafo($arr);
206
207 $this->assertInstanceOf(Setup\ConfigCollection::class, $conf);
208 $this->assertEquals(["c1", "c3"], $conf->getKeys());
209 $this->assertEquals($conf1, $conf->getConfig("c1"));
210 $this->assertEquals($conf3, $conf->getConfig("c3"));
211 }

References Vendor\Package\$c.

◆ testGetConfigInput()

ILIAS\Tests\Setup\AgentCollectionTest::testGetConfigInput ( )

Definition at line 46 of file AgentCollectionTest.php.

47 {
48 $ff = $this->createMock(FieldFactory::class);
49 $refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
50
51 $c1 = $this->newAgent();
52 $c2 = $this->newAgent();
53 $c3 = $this->newAgent();
54
55 $inp1 = $this->newInput();
56 $inp3 = $this->newInput();
57 $group = $this->newInput();
58
59 foreach ([$c1,$c3] as $c) {
60 $c
61 ->expects($this->once())
62 ->method("hasConfig")
63 ->willReturn(true);
64 }
65 $c2
66 ->expects($this->once())
67 ->method("hasConfig")
68 ->willReturn(false);
69 $c1
70 ->expects($this->once())
71 ->method("getConfigInput")
72 ->willReturn($inp1);
73 $c2
74 ->expects($this->never())
75 ->method("getConfigInput");
76 $c3
77 ->expects($this->once())
78 ->method("getConfigInput")
79 ->willReturn($inp3);
80
81 $col = new Setup\AgentCollection($ff, $refinery, ["c1" => $c1,"c2" => $c2,"c3" => $c3]);
82
83 $ff
84 ->expects($this->once())
85 ->method("group")
86 ->with(["c1" => $inp1, "c3" => $inp3])
87 ->willReturn($group);
88
89 $group
90 ->expects($this->once())
91 ->method("withAdditionalTransformation")
92 ->with($this->callback(function (Transformation $t) {
93 $conf1 = $this->newConfig();
94 $conf3 = $this->newConfig();
95 $res = $t->transform(["c1" => $conf1, "c3" => $conf3]);
96 $this->assertInstanceOf(Setup\ConfigCollection::class, $res);
97 $this->assertEquals(["c1", "c3"], $res->getKeys());
98 $this->assertEquals($conf1, $res->getConfig("c1"));
99 $this->assertEquals($conf3, $res->getConfig("c3"));
100 return true;
101 }))
102 ->willReturn($group);
103
104 $res = $col->getConfigInput();
105
106 $this->assertEquals($group, $res);
107 }
foreach($_POST as $key=> $value) $res

References Vendor\Package\$c, $res, and ILIAS\Refinery\Transformation\transform().

+ Here is the call graph for this function:

◆ testGetConfigInputUsesSuppliedConfig()

ILIAS\Tests\Setup\AgentCollectionTest::testGetConfigInputUsesSuppliedConfig ( )

Definition at line 109 of file AgentCollectionTest.php.

110 {
111 $ff = $this->createMock(FieldFactory::class);
112 $refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
113
114 $c1 = $this->newAgent();
115 $c2 = $this->newAgent();
116 $c3 = $this->newAgent();
117
118 $inp = $this->newInput();
119
120 $conf1 = $this->newConfig();
121 $conf3 = $this->newConfig();
122
123 foreach ([$c1,$c3] as $c) {
124 $c
125 ->method("hasConfig")
126 ->willReturn(true);
127 }
128 $c2
129 ->method("hasConfig")
130 ->willReturn(false);
131 $c1
132 ->expects($this->once())
133 ->method("getConfigInput")
134 ->with($conf1)
135 ->willReturn($inp);
136 $c2
137 ->expects($this->never())
138 ->method("getConfigInput");
139 $c3
140 ->expects($this->once())
141 ->method("getConfigInput")
142 ->with($conf3)
143 ->willReturn($inp);
144
145 $col = new Setup\AgentCollection($ff, $refinery, ["c1" => $c1,"c2" => $c2,"c3" => $c3]);
146
147 $ff
148 ->method("group")
149 ->willReturn($inp);
150
151 $inp
152 ->method("withAdditionalTransformation")
153 ->willReturn($inp);
154
155 $conf = new Setup\ConfigCollection(["c1" => $conf1, "c3" => $conf3]);
156
157 $col->getConfigInput($conf);
158 }

References Vendor\Package\$c.

◆ testGetInstallObjective()

ILIAS\Tests\Setup\AgentCollectionTest::testGetInstallObjective ( )

Definition at line 267 of file AgentCollectionTest.php.

268 {
269 $ff = $this->createMock(FieldFactory::class);
270 $refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
271
272 $c1 = $this->newAgent();
273 $c2 = $this->newAgent();
274
275 $g1 = $this->newObjective();
276 $g2 = $this->newObjective();
277
278 $conf1 = $this->newConfig();
279
280 $c1
281 ->expects($this->once())
282 ->method("hasConfig")
283 ->willReturn(true);
284 $c2
285 ->expects($this->once())
286 ->method("hasConfig")
287 ->willReturn(false);
288
289 $c1
290 ->expects($this->once())
291 ->method("getInstallObjective")
292 ->with($conf1)
293 ->willReturn($g1);
294 $c2
295 ->expects($this->once())
296 ->method("getInstallObjective")
297 ->with()
298 ->willReturn($g2);
299
300 $col = new Setup\AgentCollection($ff, $refinery, ["c1" => $c1,"c2" => $c2]);
301 $conf = new Setup\ConfigCollection(["c1" => $conf1]);
302
303 $g = $col->getInstallObjective($conf);
304
305 $this->assertInstanceOf(Setup\ObjectiveCollection::class, $g);
306 $this->assertEquals([$g1, $g2], $g->getObjectives());
307 }

◆ testGetUpdateObjective()

ILIAS\Tests\Setup\AgentCollectionTest::testGetUpdateObjective ( )

Definition at line 309 of file AgentCollectionTest.php.

310 {
311 $ff = $this->createMock(FieldFactory::class);
312 $refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
313
314 $c1 = $this->newAgent();
315 $c2 = $this->newAgent();
316
317 $g1 = $this->newObjective();
318 $g2 = $this->newObjective();
319
320 $conf1 = $this->newConfig();
321
322 $c1
323 ->expects($this->once())
324 ->method("hasConfig")
325 ->willReturn(true);
326 $c2
327 ->expects($this->once())
328 ->method("hasConfig")
329 ->willReturn(false);
330
331 $c1
332 ->expects($this->once())
333 ->method("getUpdateObjective")
334 ->with($conf1)
335 ->willReturn($g1);
336 $c2
337 ->expects($this->once())
338 ->method("getUpdateObjective")
339 ->with()
340 ->willReturn($g2);
341
342 $col = new Setup\AgentCollection($ff, $refinery, ["c1" => $c1,"c2" => $c2]);
343 $conf = new Setup\ConfigCollection(["c1" => $conf1]);
344
345 $g = $col->getUpdateObjective($conf);
346
347 $this->assertInstanceOf(Setup\ObjectiveCollection::class, $g);
348 $this->assertEquals([$g1, $g2], $g->getObjectives());
349 }

◆ testHasConfig()

ILIAS\Tests\Setup\AgentCollectionTest::testHasConfig ( )

Definition at line 18 of file AgentCollectionTest.php.

19 {
20 $ff = $this->createMock(FieldFactory::class);
21 $refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
22
23 $c1 = $this->newAgent();
24 $c2 = $this->newAgent();
25 $c3 = $this->newAgent();
26 $c4 = $this->newAgent();
27
28 $c1->method("hasConfig")->willReturn(true);
29 $c2->method("hasConfig")->willReturn(true);
30 $c3->method("hasConfig")->willReturn(false);
31 $c4->method("hasConfig")->willReturn(false);
32
33 $col1 = new Setup\AgentCollection($ff, $refinery, ["c1" => $c1]);
34 $col2 = new Setup\AgentCollection($ff, $refinery, ["c1" => $c1, "c2" => $c2]);
35 $col3 = new Setup\AgentCollection($ff, $refinery, ["c1" => $c1, "c3" => $c3]);
36 $col4 = new Setup\AgentCollection($ff, $refinery, ["c3" => $c3]);
37 $col5 = new Setup\AgentCollection($ff, $refinery, ["c3" => $c3, "c4" => $c4]);
38
39 $this->assertTrue($col1->hasConfig());
40 $this->assertTrue($col2->hasConfig());
41 $this->assertTrue($col3->hasConfig());
42 $this->assertFalse($col4->hasConfig());
43 $this->assertFalse($col5->hasConfig());
44 }

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