ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
AdminConfirmedObjectiveTest.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
6
8
9class AdminConfirmedObjectiveTest extends \PHPUnit\Framework\TestCase
10{
11 public function setUp() : void
12 {
13 $this->message = "This needs to be confirmed...";
14 $this->o = new Setup\AdminConfirmedObjective($this->message);
15 }
16
17 public function testGetHash()
18 {
19 $this->assertIsString($this->o->getHash());
20 }
21
23 {
24 $other = new Setup\AdminConfirmedObjective("");
25 $this->assertNotEquals($this->o->getHash(), $other->getHash());
26 }
27
28 public function testGetLabel()
29 {
30 $this->assertIsString($this->o->getLabel());
31 }
32
33 public function testIsNotable()
34 {
35 $this->assertFalse($this->o->isNotable());
36 }
37
38 public function testGetPreconditions()
39 {
40 $env = $this->createMock(Setup\Environment::class);
41
42 $pre = $this->o->getPreconditions($env);
43 $this->assertEquals([], $pre);
44 }
45
46 public function testAlreadyAchieved()
47 {
48 $env = $this->createMock(Setup\Environment::class);
49 $admin_interaction = $this->createMock(Setup\AdminInteraction::class);
50 $achievement_tracker = $this->createMock(Setup\AchievementTracker::class);
51
52 $env
53 ->method("getResource")
54 ->will($this->returnValueMap([
55 [Setup\Environment::RESOURCE_ADMIN_INTERACTION, $admin_interaction],
56 [Setup\Environment::RESOURCE_ACHIEVEMENT_TRACKER, $achievement_tracker]
57 ]));
58
59 $admin_interaction
60 ->expects($this->never())
61 ->method("confirmOrDeny");
62
63 $achievement_tracker
64 ->expects($this->once())
65 ->method("isAchieved")
66 ->with($this->o)
67 ->willReturn(true);
68
69 $achievement_tracker
70 ->expects($this->never())
71 ->method("trackAchievementOf");
72
73 $res = $this->o->achieve($env);
74 $this->assertSame($env, $res);
75 }
76
78 {
79 $env = $this->createMock(Setup\Environment::class);
80 $admin_interaction = $this->createMock(Setup\AdminInteraction::class);
81 $achievement_tracker = $this->createMock(Setup\AchievementTracker::class);
82
83 $env
84 ->method("getResource")
85 ->will($this->returnValueMap([
86 [Setup\Environment::RESOURCE_ADMIN_INTERACTION, $admin_interaction],
87 [Setup\Environment::RESOURCE_ACHIEVEMENT_TRACKER, $achievement_tracker]
88 ]));
89
90 $admin_interaction
91 ->expects($this->once())
92 ->method("confirmOrDeny")
93 ->with($this->message)
94 ->willReturn(true);
95
96 $achievement_tracker
97 ->expects($this->once())
98 ->method("isAchieved")
99 ->with($this->o)
100 ->willReturn(false);
101
102 $achievement_tracker
103 ->expects($this->once())
104 ->method("trackAchievementOf")
105 ->with($this->o);
106
107 $res = $this->o->achieve($env);
108 $this->assertSame($env, $res);
109 }
110
111 public function testAchieveWithDenial()
112 {
113 $this->expectException(Setup\NoConfirmationException::class);
114
115 $env = $this->createMock(Setup\Environment::class);
116 $admin_interaction = $this->createMock(Setup\AdminInteraction::class);
117 $achievement_tracker = $this->createMock(Setup\AchievementTracker::class);
118
119 $env
120 ->method("getResource")
121 ->will($this->returnValueMap([
122 [Setup\Environment::RESOURCE_ADMIN_INTERACTION, $admin_interaction],
123 [Setup\Environment::RESOURCE_ACHIEVEMENT_TRACKER, $achievement_tracker]
124 ]));
125
126 $admin_interaction
127 ->expects($this->once())
128 ->method("confirmOrDeny")
129 ->with($this->message)
130 ->willReturn(false);
131
132 $achievement_tracker
133 ->expects($this->once())
134 ->method("isAchieved")
135 ->with($this->o)
136 ->willReturn(false);
137
138 $achievement_tracker
139 ->expects($this->never())
140 ->method("trackAchievementOf");
141
142 $res = $this->o->achieve($env);
143 }
144}
An exception for terminatinating execution or to throw for unit testing.
An admin needs to confirm something to achieve this objective.
foreach($_POST as $key=> $value) $res