ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ObjectiveCollectionTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2019 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
5namespace ILIAS\Tests\Setup;
6
8
9class ObjectiveCollectionTest extends \PHPUnit\Framework\TestCase
10{
11 use Helper;
12
13 public function testGetObjectives()
14 {
15 $g1 = $this->newObjective();
16 $g2 = $this->newObjective();
17 $g3 = $this->newObjective();
18
19 $c = new Setup\ObjectiveCollection("", false, $g1, $g2, $g3);
20
21 $this->assertEquals([$g1, $g2, $g3], $c->getObjectives());
22 }
23
24 public function testGetHash()
25 {
26 $g1 = $this->newObjective();
27 $g2 = $this->newObjective();
28 $g3 = $this->newObjective();
29
30 $c1 = new Setup\ObjectiveCollection("", false, $g1, $g2, $g3);
31 $c2 = new Setup\ObjectiveCollection("", false, $g1, $g2);
32 $c3 = new Setup\ObjectiveCollection("", false, $g1, $g2, $g3);
33
34 $this->assertIsString($c1->getHash());
35 $this->assertIsString($c2->getHash());
36 $this->assertIsString($c3->getHash());
37
38 $this->assertEquals($c1->getHash(), $c1->getHash());
39 $this->assertNotEquals($c1->getHash(), $c2->getHash());
40 $this->assertEquals($c1->getHash(), $c3->getHash());
41 }
42
43 public function testGetLabel()
44 {
45 $c = new Setup\ObjectiveCollection("LABEL", false);
46 $this->assertEquals("LABEL", $c->getLabel());
47 }
48
49 public function testIsNotable()
50 {
51 $c1 = new Setup\ObjectiveCollection("", false);
52 $c2 = new Setup\ObjectiveCollection("", true);
53 $this->assertFalse($c1->isNotable());
54 $this->assertTrue($c2->isNotable());
55 }
56
57 public function testGetPreconditions()
58 {
59 $g1 = $this->newObjective();
60 $g2 = $this->newObjective();
61 $g3 = $this->newObjective();
62
63 $c = new Setup\ObjectiveCollection("", false, $g1, $g2, $g3);
64
65 $env = $this->createMock(Setup\Environment::class);
66
67 $pre = $c->getPreconditions($env);
68 $this->assertEquals([$g1,$g2, $g3], $pre);
69 }
70
71
72 public function testAchieve()
73 {
74 $g1 = $this->newObjective();
75 $g2 = $this->newObjective();
76 $g3 = $this->newObjective();
77
78 $c = new Setup\ObjectiveCollection("", false, $g1, $g2, $g3);
79
80 $env = $this->createMock(Setup\Environment::class);
81
82 foreach ([$g1,$g2,$g3] as $g) {
83 $g
84 ->expects($this->never())
85 ->method("achieve");
86 }
87
88 $res = $c->achieve($env);
89 $this->assertSame($env, $res);
90 }
91}
An exception for terminatinating execution or to throw for unit testing.
A objective collection is a objective that is achieved once all subobjectives are achieved.
foreach($_POST as $key=> $value) $res