ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
ilTermsOfServiceDocumentCriteriaEvaluationTest.php
Go to the documentation of this file.
1 <?php declare(strict_types=1);
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  $criterionTypeFactory
84  ->expects($this->exactly(3))
85  ->method('findByTypeIdent')
86  ->willReturnOnConsecutiveCalls(
87  $criterionType1,
88  $criterionType2,
89  $criterionType3
90  );
91 
92  $evaluator = new ilTermsOfServiceLogicalAndDocumentCriteriaEvaluation($criterionTypeFactory, $user, $log);
93 
94  $this->assertTrue($evaluator->evaluate($doc));
95  }
96 
101  {
102  $user = $this->getUserMock();
103  $log = $this->getLogMock();
104 
105  $criterionTypeFactory = $this->getCriterionTypeFactoryMock();
106 
107  $criterionType1 = $this->getCriterionTypeMock('dummy1');
108  $criterionAssignment1 = $this->getCriterionAssignmentMock($criterionType1);
109 
110  $criterionType2 = $this->getCriterionTypeMock('dummy2');
111  $criterionAssignment2 = $this->getCriterionAssignmentMock($criterionType2);
112 
113  $criterionType3 = $this->getCriterionTypeMock('dummy3');
114  $criterionAssignment3 = $this->getCriterionAssignmentMock($criterionType3);
115 
116  $criterionType1
117  ->expects($this->once())
118  ->method('evaluate')
119  ->with($user)
120  ->willReturn(true);
121 
122  $criterionType2
123  ->expects($this->once())
124  ->method('evaluate')
125  ->with($user)
126  ->willReturn(false);
127 
128  $criterionType3
129  ->expects($this->never())
130  ->method('evaluate')
131  ->with($user)
132  ->willReturn(true);
133 
134  $doc = $this
135  ->getMockBuilder(ilTermsOfServiceSignableDocument::class)
136  ->getMock();
137 
138  $doc
139  ->expects($this->once())
140  ->method('criteria')
141  ->willReturn([
142  $criterionAssignment1,
143  $criterionAssignment2,
144  $criterionAssignment3
145  ]);
146 
147  $criterionTypeFactory
148  ->expects($this->exactly(2))
149  ->method('findByTypeIdent')
150  ->willReturnOnConsecutiveCalls(
151  $criterionType1,
152  $criterionType2,
153  $criterionType3
154  );
155 
156  $evaluator = new ilTermsOfServiceLogicalAndDocumentCriteriaEvaluation($criterionTypeFactory, $user, $log);
157 
158  $this->assertFalse($evaluator->evaluate($doc));
159  }
160 }
getCriterionAssignmentMock(ilTermsOfServiceCriterionType $criterionType)
$log
Definition: result.php:15
Class ilTermsOfServiceDocumentCriteriaEvaluationTest.
Class ilTermsOfServiceEvaluationBaseTest.