ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\Tests\Setup\AgentCollectionTest Class Reference
+ Inheritance diagram for ILIAS\Tests\Setup\AgentCollectionTest:
+ Collaboration diagram for ILIAS\Tests\Setup\AgentCollectionTest:

Public Member Functions

 testHasConfig ()
 
 testGetArrayToConfigTransformation ()
 
 testArrayToConfigTransformationAllowsUnsetFields ()
 
 testGetInstallObjective ()
 
 testGetUpdateObjective ()
 
 testGetCollectMetricsObjective ()
 
 testGetAgent ()
 
 testWithRemovedAgent ()
 
 testWithAdditionalAgent ()
 
 testGetNamedObjectivesSorting ()
 
 testGetNamedObjectives ()
 
 testGetNamedObjectivePassesCorrectConfig ()
 
 testGetAgents ()
 

Detailed Description

Definition at line 32 of file AgentCollectionTest.php.

Member Function Documentation

◆ testArrayToConfigTransformationAllowsUnsetFields()

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

Definition at line 115 of file AgentCollectionTest.php.

115 : void
116 {
117 $refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
118
119 $c1 = $this->newAgent();
120 $c2 = $this->newAgent();
121 $c3 = $this->newAgent();
122
123 $conf1 = $this->newConfig();
124 $conf3 = $this->newConfig();
125
126 foreach ([$c1,$c3] as $c) {
127 $c
128 ->method("hasConfig")
129 ->willReturn(true);
130 }
131 $c2
132 ->method("hasConfig")
133 ->willReturn(false);
134
135 $arr = ["c1" => ["c1_data"]];
136
137 $c1
138 ->expects($this->once())
139 ->method("getArrayToConfigTransformation")
140 ->with()
141 ->willReturn($refinery->custom()->transformation(function ($v) use ($conf1) {
142 $this->assertEquals($v, ["c1_data"]);
143 return $conf1;
144 }));
145 $c2
146 ->expects($this->never())
147 ->method("getArrayToConfigTransformation");
148 $c3
149 ->expects($this->once())
150 ->method("getArrayToConfigTransformation")
151 ->with()
152 ->willReturn($refinery->custom()->transformation(function ($v) use ($conf3) {
153 $this->assertEquals($v, null);
154 return $conf3;
155 }));
156
157 $col = new Setup\AgentCollection($refinery, ["c1" => $c1,"c2" => $c2,"c3" => $c3]);
158 $trafo = $col->getArrayToConfigTransformation();
159 $conf = $trafo($arr);
160
161 $this->assertInstanceOf(Setup\ConfigCollection::class, $conf);
162 $this->assertEquals(["c1", "c3"], $conf->getKeys());
163 $this->assertEquals($conf1, $conf->getConfig("c1"));
164 $this->assertEquals($conf3, $conf->getConfig("c3"));
165 }
$c
Definition: deliver.php:25

References $c, and ILIAS\UI\examples\Layout\Page\Standard\$refinery.

◆ testGetAgent()

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

Definition at line 274 of file AgentCollectionTest.php.

274 : void
275 {
276 $refinery = $this->createMock(Refinery::class);
277
278 $c1 = $this->newAgent();
279 $c2 = $this->newAgent();
280 $c3 = $this->newAgent();
281 $c4 = $this->newAgent();
282
283 $c = new Setup\AgentCollection(
284 $refinery,
285 ["c1" => $c1, "c2" => $c2, "c3" => $c3, "c4" => $c4]
286 );
287
288 $this->assertSame($c1, $c->getAgent("c1"));
289 $this->assertSame($c2, $c->getAgent("c2"));
290 $this->assertSame($c3, $c->getAgent("c3"));
291 $this->assertSame($c4, $c->getAgent("c4"));
292 $this->assertNull($c->getAgent("c5"));
293 }

References $c, and ILIAS\UI\examples\Layout\Page\Standard\$refinery.

◆ testGetAgents()

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

Definition at line 496 of file AgentCollectionTest.php.

496 : void
497 {
498 $refinery = $this->createMock(Refinery::class);
499
500 $c1 = $this->newAgent();
501 $c2 = $this->newAgent();
502 $c3 = $this->newAgent();
503 $c4 = $this->newAgent();
504
505 $agentCollection = new Setup\AgentCollection(
506 $refinery,
507 ["c1" => $c1, "c2" => $c2, "c3" => $c3, "c4" => $c4]
508 );
509
510 $this->assertEquals([
511 "c1" => $c1,
512 "c2" => $c2,
513 "c3" => $c3,
514 "c4" => $c4
515 ], $agentCollection->getAgents());
516 }

References ILIAS\UI\examples\Layout\Page\Standard\$refinery.

◆ testGetArrayToConfigTransformation()

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

Definition at line 63 of file AgentCollectionTest.php.

63 : void
64 {
65 $refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
66
67 $c1 = $this->newAgent();
68 $c2 = $this->newAgent();
69 $c3 = $this->newAgent();
70
71 $conf1 = $this->newConfig();
72 $conf3 = $this->newConfig();
73
74 foreach ([$c1,$c3] as $c) {
75 $c
76 ->method("hasConfig")
77 ->willReturn(true);
78 }
79 $c2
80 ->method("hasConfig")
81 ->willReturn(false);
82
83 $arr = ["c1" => ["c1_data"], "c3" => ["c3_data"]];
84
85 $c1
86 ->expects($this->once())
87 ->method("getArrayToConfigTransformation")
88 ->with()
89 ->willReturn($refinery->custom()->transformation(function ($v) use ($conf1) {
90 $this->assertEquals($v, ["c1_data"]);
91 return $conf1;
92 }));
93 $c2
94 ->expects($this->never())
95 ->method("getArrayToConfigTransformation");
96 $c3
97 ->expects($this->once())
98 ->method("getArrayToConfigTransformation")
99 ->with()
100 ->willReturn($refinery->custom()->transformation(function ($v) use ($conf3) {
101 $this->assertEquals($v, ["c3_data"]);
102 return $conf3;
103 }));
104
105 $col = new Setup\AgentCollection($refinery, ["c1" => $c1,"c2" => $c2,"c3" => $c3]);
106 $trafo = $col->getArrayToConfigTransformation();
107 $conf = $trafo($arr);
108
109 $this->assertInstanceOf(Setup\ConfigCollection::class, $conf);
110 $this->assertEquals(["c1", "c3"], $conf->getKeys());
111 $this->assertEquals($conf1, $conf->getConfig("c1"));
112 $this->assertEquals($conf3, $conf->getConfig("c3"));
113 }

References $c, and ILIAS\UI\examples\Layout\Page\Standard\$refinery.

◆ testGetCollectMetricsObjective()

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

Definition at line 242 of file AgentCollectionTest.php.

242 : void
243 {
244 $refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
245
246 $c1 = $this->newAgent();
247 $c2 = $this->newAgent();
248
249 $g1 = $this->newObjective();
250 $g2 = $this->newObjective();
251
252 $conf1 = $this->newConfig();
253
254 $c1
255 ->expects($this->once())
256 ->method("getUpdateObjective")
257 ->with($conf1)
258 ->willReturn($g1);
259 $c2
260 ->expects($this->once())
261 ->method("getUpdateObjective")
262 ->with()
263 ->willReturn($g2);
264
265 $col = new Setup\AgentCollection($refinery, ["c1" => $c1,"c2" => $c2]);
266 $conf = new Setup\ConfigCollection(["c1" => $conf1]);
267
268 $g = $col->getUpdateObjective($conf);
269
270 $this->assertInstanceOf(Setup\ObjectiveCollection::class, $g);
271 $this->assertEquals([$g1, $g2], $g->getObjectives());
272 }

References ILIAS\UI\examples\Layout\Page\Standard\$refinery.

◆ testGetInstallObjective()

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

Definition at line 167 of file AgentCollectionTest.php.

167 : void
168 {
169 $refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
170
171 $c1 = $this->newAgent();
172 $c2 = $this->newAgent();
173
174 $g1 = $this->newObjective();
175 $g2 = $this->newObjective();
176
177 $conf1 = $this->newConfig();
178
179 $c1
180 ->expects($this->once())
181 ->method("hasConfig")
182 ->willReturn(true);
183 $c2
184 ->expects($this->once())
185 ->method("hasConfig")
186 ->willReturn(false);
187
188 $c1
189 ->expects($this->once())
190 ->method("getInstallObjective")
191 ->with($conf1)
192 ->willReturn($g1);
193 $c2
194 ->expects($this->once())
195 ->method("getInstallObjective")
196 ->with()
197 ->willReturn($g2);
198
199 $col = new Setup\AgentCollection($refinery, ["c1" => $c1,"c2" => $c2]);
200 $conf = new Setup\ConfigCollection(["c1" => $conf1]);
201
202 $g = $col->getInstallObjective($conf);
203
204 $this->assertInstanceOf(Setup\ObjectiveCollection::class, $g);
205 $this->assertEquals([$g1, $g2], $g->getObjectives());
206 }

References ILIAS\UI\examples\Layout\Page\Standard\$refinery.

◆ testGetNamedObjectivePassesCorrectConfig()

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

Definition at line 468 of file AgentCollectionTest.php.

469 {
470 $refinery = $this->createMock(Refinery::class);
471 $agent = $this->newAgent();
472
473 $seen_config = null;
474 $agent
475 ->method("getNamedObjectives")
476 ->will($this->returnCallback(function ($config) use (&$seen_config) {
477 $seen_config = $config;
478 return [];
479 }));
480
481 $collection = new Setup\AgentCollection(
482 $refinery,
483 ["agent" => $agent]
484 );
485
486 $agent_config = $this->createMock(Setup\Config::class);
487 $config = new Setup\ConfigCollection(
488 ["agent" => $agent_config]
489 );
490
491 $result = $collection->getNamedObjectives($config);
492
493 $this->assertSame($agent_config, $seen_config);
494 }

References ILIAS\UI\examples\Layout\Page\Standard\$refinery.

◆ testGetNamedObjectives()

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

Definition at line 428 of file AgentCollectionTest.php.

428 : void
429 {
430 $refinery = $this->createMock(Refinery::class);
431 $config = new Setup\ConfigCollection([]);
432
433 $aAgent = $this->newAgent();
434 $bAgent = $this->newAgent();
435
436 $aReturn = [
437 "a-1" => $this->newObjectiveConstructor(),
438 "a-2" => $this->newObjectiveConstructor()
439 ];
440
441 $bReturn = [
442 "b-1" => $this->newObjectiveConstructor(),
443 "b-2" => $this->newObjectiveConstructor(),
444 ];
445
446 $aAgent
447 ->expects($this->once())
448 ->method("getNamedObjectives")
449 ->willReturn($aReturn);
450 $bAgent
451 ->expects($this->once())
452 ->method("getNamedObjectives")
453 ->willReturn($bReturn);
454
455 $testAgentCollection = new Setup\AgentCollection(
456 $refinery,
457 ["aAgent" => $aAgent, "bAgent" => $bAgent]
458 );
459
460 $result = $testAgentCollection->getNamedObjectives($config);
461
462 $this->assertSame($aReturn["a-1"], $result["aAgent.a-1"]);
463 $this->assertSame($aReturn["a-2"], $result["aAgent.a-2"]);
464 $this->assertSame($bReturn["b-1"], $result["bAgent.b-1"]);
465 $this->assertSame($bReturn["b-2"], $result["bAgent.b-2"]);
466 }

References ILIAS\UI\examples\Layout\Page\Standard\$refinery.

◆ testGetNamedObjectivesSorting()

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

Definition at line 355 of file AgentCollectionTest.php.

355 : void
356 {
357 $refinery = $this->createMock(Refinery::class);
358 $config = new Setup\ConfigCollection([]);
359
360 $aAgent = $this->newAgent();
361 $bAgent = $this->newAgent();
362 $cAgent = $this->newAgent();
363 $dAgent = $this->newAgent();
364
365 $aReturn = [
366 "a-2" => $this->newObjectiveConstructor(),
367 "a-1" => $this->newObjectiveConstructor()
368 ];
369
370 $bReturn = [
371 "b-1" => $this->newObjectiveConstructor(),
372 "b-3" => $this->newObjectiveConstructor(),
373 "b-2" => $this->newObjectiveConstructor(),
374 ];
375
376 $cReturn = [
377 "c-2" => $this->newObjectiveConstructor(),
378 "c-1" => $this->newObjectiveConstructor()
379 ];
380
381 $dReturn = [
382 "d-2" => $this->newObjectiveConstructor(),
383 "d-3" => $this->newObjectiveConstructor(),
384 "d-1" => $this->newObjectiveConstructor()
385 ];
386
387 $aAgent
388 ->expects($this->once())
389 ->method("getNamedObjectives")
390 ->willReturn($aReturn);
391
392 $bAgent
393 ->expects($this->once())
394 ->method("getNamedObjectives")
395 ->willReturn($bReturn);
396
397 $cAgent
398 ->expects($this->once())
399 ->method("getNamedObjectives")
400 ->willReturn($cReturn);
401
402 $dAgent
403 ->expects($this->once())
404 ->method("getNamedObjectives")
405 ->willReturn($dReturn);
406
407 $testAgentCollection = new Setup\AgentCollection(
408 $refinery,
409 ["aAgent" => $aAgent, "cAgent" => $cAgent, "bAgent" => $bAgent, "dAgent" => $dAgent]
410 );
411
412 $expected = [
413 "aAgent.a-1" => $aReturn["a-1"],
414 "aAgent.a-2" => $aReturn["a-2"],
415 "bAgent.b-1" => $bReturn["b-1"],
416 "bAgent.b-2" => $bReturn["b-2"],
417 "bAgent.b-3" => $bReturn["b-3"],
418 "cAgent.c-1" => $cReturn["c-1"],
419 "cAgent.c-2" => $cReturn["c-2"],
420 "dAgent.d-1" => $dReturn["d-1"],
421 "dAgent.d-2" => $dReturn["d-2"],
422 "dAgent.d-3" => $dReturn["d-3"],
423 ];
424
425 $this->assertSame($expected, $testAgentCollection->getNamedObjectives($config));
426 }

References ILIAS\UI\examples\Layout\Page\Standard\$refinery.

◆ testGetUpdateObjective()

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

Definition at line 208 of file AgentCollectionTest.php.

208 : void
209 {
210 $refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
211 $storage = $this->createMock(Setup\Metrics\Storage::class);
212
213 $c1 = $this->newAgent();
214 $c2 = $this->newAgent();
215
216 $g1 = $this->newObjective();
217 $g2 = $this->newObjective();
218
219 $s1 = new Setup\Metrics\StorageOnPathWrapper("c1", $storage);
220 $s2 = new Setup\Metrics\StorageOnPathWrapper("c2", $storage);
221
222 $c1
223 ->expects($this->once())
224 ->method("getStatusObjective")
225 ->with($s1)
226 ->willReturn($g1);
227 $c2
228 ->expects($this->once())
229 ->method("getStatusObjective")
230 ->with($s2)
231 ->willReturn($g2);
232
233 $col = new Setup\AgentCollection($refinery, ["c1" => $c1,"c2" => $c2]);
234 $conf = new Setup\ConfigCollection(["c1" => $c1]);
235
236 $g = $col->getStatusObjective($storage);
237
238 $this->assertInstanceOf(Setup\ObjectiveCollection::class, $g);
239 $this->assertEquals([$g1, $g2], $g->getObjectives());
240 }

References ILIAS\UI\examples\Layout\Page\Standard\$refinery.

◆ testHasConfig()

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

Definition at line 36 of file AgentCollectionTest.php.

36 : void
37 {
38 $refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
39
40 $c1 = $this->newAgent();
41 $c2 = $this->newAgent();
42 $c3 = $this->newAgent();
43 $c4 = $this->newAgent();
44
45 $c1->method("hasConfig")->willReturn(true);
46 $c2->method("hasConfig")->willReturn(true);
47 $c3->method("hasConfig")->willReturn(false);
48 $c4->method("hasConfig")->willReturn(false);
49
50 $col1 = new Setup\AgentCollection($refinery, ["c1" => $c1]);
51 $col2 = new Setup\AgentCollection($refinery, ["c1" => $c1, "c2" => $c2]);
52 $col3 = new Setup\AgentCollection($refinery, ["c1" => $c1, "c3" => $c3]);
53 $col4 = new Setup\AgentCollection($refinery, ["c3" => $c3]);
54 $col5 = new Setup\AgentCollection($refinery, ["c3" => $c3, "c4" => $c4]);
55
56 $this->assertTrue($col1->hasConfig());
57 $this->assertTrue($col2->hasConfig());
58 $this->assertTrue($col3->hasConfig());
59 $this->assertFalse($col4->hasConfig());
60 $this->assertFalse($col5->hasConfig());
61 }

References ILIAS\UI\examples\Layout\Page\Standard\$refinery.

◆ testWithAdditionalAgent()

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

Definition at line 325 of file AgentCollectionTest.php.

325 : void
326 {
327 $refinery = $this->createMock(Refinery::class);
328
329 $c1 = $this->newAgent();
330 $c2 = $this->newAgent();
331 $c3 = $this->newAgent();
332 $c4 = $this->newAgent();
333
334 $ca = new Setup\AgentCollection(
335 $refinery,
336 ["c1" => $c1, "c2" => $c2, "c3" => $c3]
337 );
338 $cb = $ca->withAdditionalAgent("c4", $c4);
339
340 $this->assertNotSame($ca, $cb);
341
342 $this->assertSame($c1, $ca->getAgent("c1"));
343 $this->assertSame($c2, $ca->getAgent("c2"));
344 $this->assertSame($c3, $ca->getAgent("c3"));
345 $this->assertNull($ca->getAgent("c4"));
346 $this->assertNull($ca->getAgent("c5"));
347
348 $this->assertSame($c1, $cb->getAgent("c1"));
349 $this->assertSame($c2, $cb->getAgent("c2"));
350 $this->assertSame($c3, $cb->getAgent("c3"));
351 $this->assertSame($c4, $cb->getAgent("c4"));
352 $this->assertNull($cb->getAgent("c5"));
353 }

References ILIAS\UI\examples\Layout\Page\Standard\$refinery.

◆ testWithRemovedAgent()

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

Definition at line 295 of file AgentCollectionTest.php.

295 : void
296 {
297 $refinery = $this->createMock(Refinery::class);
298
299 $c1 = $this->newAgent();
300 $c2 = $this->newAgent();
301 $c3 = $this->newAgent();
302 $c4 = $this->newAgent();
303
304 $ca = new Setup\AgentCollection(
305 $refinery,
306 ["c1" => $c1, "c2" => $c2, "c3" => $c3, "c4" => $c4]
307 );
308 $cb = $ca->withRemovedAgent("c2");
309
310 $this->assertNotSame($ca, $cb);
311
312 $this->assertSame($c1, $ca->getAgent("c1"));
313 $this->assertSame($c2, $ca->getAgent("c2"));
314 $this->assertSame($c3, $ca->getAgent("c3"));
315 $this->assertSame($c4, $ca->getAgent("c4"));
316 $this->assertNull($ca->getAgent("c5"));
317
318 $this->assertSame($c1, $cb->getAgent("c1"));
319 $this->assertNull($cb->getAgent("c2"));
320 $this->assertSame($c3, $cb->getAgent("c3"));
321 $this->assertSame($c4, $cb->getAgent("c4"));
322 $this->assertNull($cb->getAgent("c5"));
323 }

References ILIAS\UI\examples\Layout\Page\Standard\$refinery.


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