19 declare(strict_types=1);
23 require_once(__DIR__ .
"/Helper.php");
38 $refinery =
new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
40 $c1 = $this->newAgent();
41 $c2 = $this->newAgent();
42 $c3 = $this->newAgent();
43 $c4 = $this->newAgent();
45 $c1->method(
"hasConfig")->willReturn(
true);
46 $c2->method(
"hasConfig")->willReturn(
true);
47 $c3->method(
"hasConfig")->willReturn(
false);
48 $c4->method(
"hasConfig")->willReturn(
false);
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());
65 $refinery =
new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
67 $c1 = $this->newAgent();
68 $c2 = $this->newAgent();
69 $c3 = $this->newAgent();
71 $conf1 = $this->newConfig();
72 $conf3 = $this->newConfig();
74 foreach ([$c1,$c3] as
$c) {
83 $arr = [
"c1" => [
"c1_data"],
"c3" => [
"c3_data"]];
86 ->expects($this->once())
87 ->method(
"getArrayToConfigTransformation")
89 ->willReturn(
$refinery->custom()->transformation(
function ($v) use ($conf1) {
90 $this->assertEquals($v, [
"c1_data"]);
94 ->expects($this->never())
95 ->method(
"getArrayToConfigTransformation");
97 ->expects($this->once())
98 ->method(
"getArrayToConfigTransformation")
100 ->willReturn(
$refinery->custom()->transformation(
function ($v) use ($conf3) {
101 $this->assertEquals($v, [
"c3_data"]);
106 $trafo = $col->getArrayToConfigTransformation();
107 $conf = $trafo($arr);
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"));
117 $refinery =
new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
119 $c1 = $this->newAgent();
120 $c2 = $this->newAgent();
121 $c3 = $this->newAgent();
123 $conf1 = $this->newConfig();
124 $conf3 = $this->newConfig();
126 foreach ([$c1,$c3] as
$c) {
128 ->method(
"hasConfig")
132 ->method(
"hasConfig")
135 $arr = [
"c1" => [
"c1_data"]];
138 ->expects($this->once())
139 ->method(
"getArrayToConfigTransformation")
141 ->willReturn(
$refinery->custom()->transformation(
function ($v) use ($conf1) {
142 $this->assertEquals($v, [
"c1_data"]);
146 ->expects($this->never())
147 ->method(
"getArrayToConfigTransformation");
149 ->expects($this->once())
150 ->method(
"getArrayToConfigTransformation")
152 ->willReturn(
$refinery->custom()->transformation(
function ($v) use ($conf3) {
153 $this->assertEquals($v,
null);
158 $trafo = $col->getArrayToConfigTransformation();
159 $conf = $trafo($arr);
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"));
169 $refinery =
new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
171 $c1 = $this->newAgent();
172 $c2 = $this->newAgent();
174 $g1 = $this->newObjective();
175 $g2 = $this->newObjective();
177 $conf1 = $this->newConfig();
180 ->expects($this->once())
181 ->method(
"hasConfig")
184 ->expects($this->once())
185 ->method(
"hasConfig")
189 ->expects($this->once())
190 ->method(
"getInstallObjective")
194 ->expects($this->once())
195 ->method(
"getInstallObjective")
202 $g = $col->getInstallObjective($conf);
204 $this->assertInstanceOf(
Setup\ObjectiveCollection::class, $g);
205 $this->assertEquals([$g1, $g2], $g->getObjectives());
210 $refinery =
new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
211 $storage = $this->createMock(
Setup\Metrics\Storage::class);
213 $c1 = $this->newAgent();
214 $c2 = $this->newAgent();
216 $g1 = $this->newObjective();
217 $g2 = $this->newObjective();
223 ->expects($this->once())
224 ->method(
"getStatusObjective")
228 ->expects($this->once())
229 ->method(
"getStatusObjective")
236 $g = $col->getStatusObjective($storage);
238 $this->assertInstanceOf(
Setup\ObjectiveCollection::class, $g);
239 $this->assertEquals([$g1, $g2], $g->getObjectives());
244 $refinery =
new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
246 $c1 = $this->newAgent();
247 $c2 = $this->newAgent();
249 $g1 = $this->newObjective();
250 $g2 = $this->newObjective();
252 $conf1 = $this->newConfig();
255 ->expects($this->once())
256 ->method(
"getUpdateObjective")
260 ->expects($this->once())
261 ->method(
"getUpdateObjective")
268 $g = $col->getUpdateObjective($conf);
270 $this->assertInstanceOf(
Setup\ObjectiveCollection::class, $g);
271 $this->assertEquals([$g1, $g2], $g->getObjectives());
276 $refinery = $this->createMock(Refinery::class);
278 $c1 = $this->newAgent();
279 $c2 = $this->newAgent();
280 $c3 = $this->newAgent();
281 $c4 = $this->newAgent();
285 [
"c1" => $c1,
"c2" => $c2,
"c3" => $c3,
"c4" => $c4]
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"));
297 $refinery = $this->createMock(Refinery::class);
299 $c1 = $this->newAgent();
300 $c2 = $this->newAgent();
301 $c3 = $this->newAgent();
302 $c4 = $this->newAgent();
306 [
"c1" => $c1,
"c2" => $c2,
"c3" => $c3,
"c4" => $c4]
308 $cb = $ca->withRemovedAgent(
"c2");
310 $this->assertNotSame($ca, $cb);
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"));
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"));
327 $refinery = $this->createMock(Refinery::class);
329 $c1 = $this->newAgent();
330 $c2 = $this->newAgent();
331 $c3 = $this->newAgent();
332 $c4 = $this->newAgent();
336 [
"c1" => $c1,
"c2" => $c2,
"c3" => $c3]
338 $cb = $ca->withAdditionalAgent(
"c4", $c4);
340 $this->assertNotSame($ca, $cb);
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"));
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"));
357 $refinery = $this->createMock(Refinery::class);
360 $aAgent = $this->newAgent();
361 $bAgent = $this->newAgent();
362 $cAgent = $this->newAgent();
363 $dAgent = $this->newAgent();
366 "a-2" => $this->newObjectiveConstructor(),
367 "a-1" => $this->newObjectiveConstructor()
371 "b-1" => $this->newObjectiveConstructor(),
372 "b-3" => $this->newObjectiveConstructor(),
373 "b-2" => $this->newObjectiveConstructor(),
377 "c-2" => $this->newObjectiveConstructor(),
378 "c-1" => $this->newObjectiveConstructor()
382 "d-2" => $this->newObjectiveConstructor(),
383 "d-3" => $this->newObjectiveConstructor(),
384 "d-1" => $this->newObjectiveConstructor()
388 ->expects($this->once())
389 ->method(
"getNamedObjectives")
390 ->willReturn($aReturn);
393 ->expects($this->once())
394 ->method(
"getNamedObjectives")
395 ->willReturn($bReturn);
398 ->expects($this->once())
399 ->method(
"getNamedObjectives")
400 ->willReturn($cReturn);
403 ->expects($this->once())
404 ->method(
"getNamedObjectives")
405 ->willReturn($dReturn);
409 [
"aAgent" => $aAgent,
"cAgent" => $cAgent,
"bAgent" => $bAgent,
"dAgent" => $dAgent]
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"],
425 $this->assertSame($expected, $testAgentCollection->getNamedObjectives($config));
430 $refinery = $this->createMock(Refinery::class);
433 $aAgent = $this->newAgent();
434 $bAgent = $this->newAgent();
437 "a-1" => $this->newObjectiveConstructor(),
438 "a-2" => $this->newObjectiveConstructor()
442 "b-1" => $this->newObjectiveConstructor(),
443 "b-2" => $this->newObjectiveConstructor(),
447 ->expects($this->once())
448 ->method(
"getNamedObjectives")
449 ->willReturn($aReturn);
451 ->expects($this->once())
452 ->method(
"getNamedObjectives")
453 ->willReturn($bReturn);
457 [
"aAgent" => $aAgent,
"bAgent" => $bAgent]
460 $result = $testAgentCollection->getNamedObjectives($config);
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"]);
470 $refinery = $this->createMock(Refinery::class);
471 $agent = $this->newAgent();
475 ->method(
"getNamedObjectives")
476 ->will($this->returnCallback(
function ($config) use (&$seen_config) {
477 $seen_config = $config;
486 $agent_config = $this->createMock(
Setup\Config::class);
488 [
"agent" => $agent_config]
491 $result = $collection->getNamedObjectives($config);
493 $this->assertSame($agent_config, $seen_config);
498 $refinery = $this->createMock(Refinery::class);
500 $c1 = $this->newAgent();
501 $c2 = $this->newAgent();
502 $c3 = $this->newAgent();
503 $c4 = $this->newAgent();
507 [
"c1" => $c1,
"c2" => $c2,
"c3" => $c3,
"c4" => $c4]
510 $this->assertEquals([
515 ], $agentCollection->getAgents());
testWithAdditionalAgent()
testGetInstallObjective()
An agent that is just a collection of some other agents.
testGetCollectMetricsObjective()
testArrayToConfigTransformationAllowsUnsetFields()
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
testGetArrayToConfigTransformation()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
testGetNamedObjectivesSorting()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
testGetNamedObjectivePassesCorrectConfig()
A collection of some configurations.