ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilTermsOfServiceDocumentCriteriaEvaluationTest.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
9 {
14  {
15  $user = $this->getUserMock();
16  $criterionTypeFactory = $this->getCriterionTypeFactoryMock();
17  $log = $this->getLogMock();
18 
19  $doc = $this
20  ->getMockBuilder(\ilTermsOfServiceSignableDocument::class)
21  ->getMock();
22 
23  $doc
24  ->expects($this->once())
25  ->method('criteria')
26  ->willReturn([]);
27 
28  $evaluator = new \ilTermsOfServiceLogicalAndDocumentCriteriaEvaluation($criterionTypeFactory, $user, $log);
29 
30  $this->assertTrue($evaluator->evaluate($doc));
31  }
32 
37  {
38  $user = $this->getUserMock();
39  $log = $this->getLogMock();
40 
41  $criterionTypeFactory = $this->getCriterionTypeFactoryMock();
42 
43  $criterionType1 = $this->getCriterionTypeMock('dummy1');
44  $criterionAssignment1 = $this->getCriterionAssignmentMock($criterionType1);
45 
46  $criterionType2 = $this->getCriterionTypeMock('dummy2');
47  $criterionAssignment2 = $this->getCriterionAssignmentMock($criterionType2);
48 
49  $criterionType3 = $this->getCriterionTypeMock('dummy3');
50  $criterionAssignment3 = $this->getCriterionAssignmentMock($criterionType3);
51 
52  $criterionType1
53  ->expects($this->once())
54  ->method('evaluate')
55  ->with($user)
56  ->willReturn(true);
57 
58  $criterionType2
59  ->expects($this->once())
60  ->method('evaluate')
61  ->with($user)
62  ->willReturn(true);
63 
64  $criterionType3
65  ->expects($this->once())
66  ->method('evaluate')
67  ->with($user)
68  ->willReturn(true);
69 
70  $doc = $this
71  ->getMockBuilder(\ilTermsOfServiceSignableDocument::class)
72  ->getMock();
73 
74  $doc
75  ->expects($this->once())
76  ->method('criteria')
77  ->willReturn([
78  $criterionAssignment1,
79  $criterionAssignment2,
80  $criterionAssignment3
81  ]);
82 
83 
84  $criterionTypeFactory
85  ->expects($this->exactly(3))
86  ->method('findByTypeIdent')
87  ->willReturnOnConsecutiveCalls(
88  $criterionType1,
89  $criterionType2,
90  $criterionType3
91  );
92 
93  $evaluator = new \ilTermsOfServiceLogicalAndDocumentCriteriaEvaluation($criterionTypeFactory, $user, $log);
94 
95  $this->assertTrue($evaluator->evaluate($doc));
96  }
97 
102  {
103  $user = $this->getUserMock();
104  $log = $this->getLogMock();
105 
106  $criterionTypeFactory = $this->getCriterionTypeFactoryMock();
107 
108  $criterionType1 = $this->getCriterionTypeMock('dummy1');
109  $criterionAssignment1 = $this->getCriterionAssignmentMock($criterionType1);
110 
111  $criterionType2 = $this->getCriterionTypeMock('dummy2');
112  $criterionAssignment2 = $this->getCriterionAssignmentMock($criterionType2);
113 
114  $criterionType3 = $this->getCriterionTypeMock('dummy3');
115  $criterionAssignment3 = $this->getCriterionAssignmentMock($criterionType3);
116 
117  $criterionType1
118  ->expects($this->once())
119  ->method('evaluate')
120  ->with($user)
121  ->willReturn(true);
122 
123  $criterionType2
124  ->expects($this->once())
125  ->method('evaluate')
126  ->with($user)
127  ->willReturn(false);
128 
129  $criterionType3
130  ->expects($this->never())
131  ->method('evaluate')
132  ->with($user)
133  ->willReturn(true);
134 
135  $doc = $this
136  ->getMockBuilder(\ilTermsOfServiceSignableDocument::class)
137  ->getMock();
138 
139  $doc
140  ->expects($this->once())
141  ->method('criteria')
142  ->willReturn([
143  $criterionAssignment1,
144  $criterionAssignment2,
145  $criterionAssignment3
146  ]);
147 
148 
149  $criterionTypeFactory
150  ->expects($this->exactly(2))
151  ->method('findByTypeIdent')
152  ->willReturnOnConsecutiveCalls(
153  $criterionType1,
154  $criterionType2,
155  $criterionType3
156  );
157 
158  $evaluator = new \ilTermsOfServiceLogicalAndDocumentCriteriaEvaluation($criterionTypeFactory, $user, $log);
159 
160  $this->assertFalse($evaluator->evaluate($doc));
161  }
162 }
$log
Definition: sabredav.php:21
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
$user
Definition: migrateto20.php:57
Class ilTermsOfServiceDocumentCriteriaEvaluationTest.
getCriterionAssignmentMock(\ilTermsOfServiceCriterionType $criterionType)
Class ilTermsOfServiceEvaluationBaseTest.