ILIAS  release_8 Revision v8.24
ilTermsOfServiceDocumentCriteriaEvaluationTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26{
28 {
29 $user = $this->getUserMock();
30 $criterionTypeFactory = $this->getCriterionTypeFactoryMock();
31 $log = $this->getLogMock();
32
33 $doc = $this
34 ->getMockBuilder(ilTermsOfServiceSignableDocument::class)
35 ->getMock();
36
37 $doc
38 ->expects($this->once())
39 ->method('criteria')
40 ->willReturn([]);
41
42 $evaluator = new ilTermsOfServiceLogicalAndDocumentCriteriaEvaluation($criterionTypeFactory, $user, $log);
43
44 $this->assertTrue($evaluator->evaluate($doc));
45 }
46
48 {
49 $user = $this->getUserMock();
50 $log = $this->getLogMock();
51
52 $criterionTypeFactory = $this->getCriterionTypeFactoryMock();
53
54 $criterionType1 = $this->getCriterionTypeMock('dummy1');
55 $criterionAssignment1 = $this->getCriterionAssignmentMock($criterionType1);
56
57 $criterionType2 = $this->getCriterionTypeMock('dummy2');
58 $criterionAssignment2 = $this->getCriterionAssignmentMock($criterionType2);
59
60 $criterionType3 = $this->getCriterionTypeMock('dummy3');
61 $criterionAssignment3 = $this->getCriterionAssignmentMock($criterionType3);
62
63 $criterionType1
64 ->expects($this->once())
65 ->method('evaluate')
66 ->with($user)
67 ->willReturn(true);
68
69 $criterionType2
70 ->expects($this->once())
71 ->method('evaluate')
72 ->with($user)
73 ->willReturn(true);
74
75 $criterionType3
76 ->expects($this->once())
77 ->method('evaluate')
78 ->with($user)
79 ->willReturn(true);
80
81 $doc = $this
82 ->getMockBuilder(ilTermsOfServiceSignableDocument::class)
83 ->getMock();
84
85 $doc
86 ->expects($this->once())
87 ->method('criteria')
88 ->willReturn([
89 $criterionAssignment1,
90 $criterionAssignment2,
91 $criterionAssignment3
92 ]);
93
94 $criterionTypeFactory
95 ->expects($this->exactly(3))
96 ->method('findByTypeIdent')
97 ->willReturnOnConsecutiveCalls(
98 $criterionType1,
99 $criterionType2,
100 $criterionType3
101 );
102
103 $evaluator = new ilTermsOfServiceLogicalAndDocumentCriteriaEvaluation($criterionTypeFactory, $user, $log);
104
105 $this->assertTrue($evaluator->evaluate($doc));
106 }
107
109 {
110 $user = $this->getUserMock();
111 $log = $this->getLogMock();
112
113 $criterionTypeFactory = $this->getCriterionTypeFactoryMock();
114
115 $criterionType1 = $this->getCriterionTypeMock('dummy1');
116 $criterionAssignment1 = $this->getCriterionAssignmentMock($criterionType1);
117
118 $criterionType2 = $this->getCriterionTypeMock('dummy2');
119 $criterionAssignment2 = $this->getCriterionAssignmentMock($criterionType2);
120
121 $criterionType3 = $this->getCriterionTypeMock('dummy3');
122 $criterionAssignment3 = $this->getCriterionAssignmentMock($criterionType3);
123
124 $criterionType1
125 ->expects($this->once())
126 ->method('evaluate')
127 ->with($user)
128 ->willReturn(true);
129
130 $criterionType2
131 ->expects($this->once())
132 ->method('evaluate')
133 ->with($user)
134 ->willReturn(false);
135
136 $criterionType3
137 ->expects($this->never())
138 ->method('evaluate')
139 ->with($user)
140 ->willReturn(true);
141
142 $doc = $this
143 ->getMockBuilder(ilTermsOfServiceSignableDocument::class)
144 ->getMock();
145
146 $doc
147 ->expects($this->once())
148 ->method('criteria')
149 ->willReturn([
150 $criterionAssignment1,
151 $criterionAssignment2,
152 $criterionAssignment3
153 ]);
154
155 $criterionTypeFactory
156 ->expects($this->exactly(2))
157 ->method('findByTypeIdent')
158 ->willReturnOnConsecutiveCalls(
159 $criterionType1,
160 $criterionType2,
161 $criterionType3
162 );
163
164 $evaluator = new ilTermsOfServiceLogicalAndDocumentCriteriaEvaluation($criterionTypeFactory, $user, $log);
165
166 $this->assertFalse($evaluator->evaluate($doc));
167 }
168
170 {
173 $this->getUserMock(),
174 $this->getLogMock()
175 );
176
177 $this->assertNotSame($evaluator, $evaluator->withContextUser($this->getUserMock()));
178 }
179}
Class ilTermsOfServiceEvaluationBaseTest.
getCriterionAssignmentMock(ilTermsOfServiceCriterionType $criterionType)
$log
Definition: result.php:33