17 $criterionTypeFactory = $this
18 ->getMockBuilder(\ilTermsOfServiceCriterionTypeFactoryInterface::class)
21 return $criterionTypeFactory;
30 $criterionType = $this
31 ->getMockBuilder(\ilTermsOfServiceCriterionType::class)
35 ->expects($this->any())
36 ->method(
'getTypeIdent')
37 ->willReturn($typeIdent);
39 return $criterionType;
52 ->expects($this->any())
53 ->method(
'hasUniqueNature')
57 ->expects($this->any())
58 ->method(
'getTypesByIdentMap')
60 $criterionType1->getTypeIdent() => $criterionType1,
64 ->expects($this->any())
65 ->method(
'findByTypeIdent')
66 ->willReturn($criterionType1);
68 return $criterionTypeFactory;
76 $criterionAssignment1 = $this
77 ->getMockBuilder(\ilTermsOfServiceDocumentCriterionAssignment::class)
78 ->disableOriginalConstructor()
79 ->setMethods([
'getId',
'getCriterionValue',
'getCriterionId'])
83 ->expects($this->any())
88 ->expects($this->any())
89 ->method(
'getCriterionId')
90 ->willReturn(
'usr_global_role');
93 ->expects($this->any())
94 ->method(
'getCriterionValue')
97 $criterionAssignment2 = $this
98 ->getMockBuilder(\ilTermsOfServiceDocumentCriterionAssignment::class)
99 ->disableOriginalConstructor()
100 ->setMethods([
'getId',
'getCriterionValue',
'getCriterionId'])
103 $criterionAssignment2
104 ->expects($this->any())
108 $criterionAssignment2
109 ->expects($this->any())
110 ->method(
'getCriterionId')
111 ->willReturn(
'usr_language');
113 $criterionAssignment2
114 ->expects($this->any())
115 ->method(
'getCriterionValue')
118 $criterionAssignment3 = $this
119 ->getMockBuilder(\ilTermsOfServiceDocumentCriterionAssignment::class)
120 ->setMethods([
'getId',
'getCriterionValue',
'getCriterionId'])
121 ->disableOriginalConstructor()
124 $criterionAssignment3
125 ->expects($this->any())
129 $criterionAssignment3
130 ->expects($this->any())
131 ->method(
'getCriterionId')
132 ->willReturn(
'usr_language');
134 $criterionAssignment3
135 ->expects($this->any())
136 ->method(
'getCriterionValue')
139 $criterionAssignment4 = $this
140 ->getMockBuilder(\ilTermsOfServiceDocumentCriterionAssignment::class)
141 ->disableOriginalConstructor()
142 ->setMethods([
'getId',
'getCriterionValue',
'getCriterionId'])
145 $criterionAssignment4
146 ->expects($this->any())
150 $criterionAssignment4
151 ->expects($this->any())
152 ->method(
'getCriterionId')
153 ->willReturn(
'usr_global_role');
155 $criterionAssignment4
156 ->expects($this->any())
157 ->method(
'getCriterionValue')
161 [$criterionAssignment1, $criterionAssignment2, $criterionAssignment3, $criterionAssignment4]
179 ->getMockBuilder(\ilTermsOfServiceDocument::class)
180 ->disableOriginalConstructor()
181 ->setMethods([
'criteria'])
185 ->expects($this->any())
187 ->willReturn([$criterionAssignment1, $criterionAssignment2]);
189 $constraint = new \ilTermsOfServiceDocumentCriterionAssignmentConstraint(
196 $this->assertTrue($constraint->accepts($criterionAssignment1));
197 $this->assertTrue($constraint->accepts($criterionAssignment2));
198 $this->assertFalse($constraint->accepts($criterionAssignment3));
199 $this->assertTrue($constraint->accepts($criterionAssignment4));
216 ->getMockBuilder(\ilTermsOfServiceDocument::class)
217 ->disableOriginalConstructor()
218 ->setMethods([
'criteria'])
222 ->expects($this->any())
224 ->willReturn([$criterionAssignment1, $criterionAssignment2]);
226 $constraint = new \ilTermsOfServiceDocumentCriterionAssignmentConstraint(
236 $constraint->check($criterionAssignment4);
241 $this->assertFalse($raised);
244 $constraint->check($criterionAssignment3);
247 $this->assertEquals(
'The passed assignment must be unique for the document!', $e->getMessage());
251 $this->assertTrue($raised);
268 ->getMockBuilder(\ilTermsOfServiceDocument::class)
269 ->disableOriginalConstructor()
270 ->setMethods([
'criteria'])
274 ->expects($this->any())
276 ->willReturn([$criterionAssignment1, $criterionAssignment2]);
278 $constraint = new \ilTermsOfServiceDocumentCriterionAssignmentConstraint(
285 $this->assertNull($constraint->problemWith($criterionAssignment1));
286 $this->assertNull($constraint->problemWith($criterionAssignment2));
287 $this->assertNull($constraint->problemWith($criterionAssignment4));
288 $this->assertInternalType(
'string', $constraint->problemWith($criterionAssignment3));
305 ->getMockBuilder(\ilTermsOfServiceDocument::class)
306 ->disableOriginalConstructor()
307 ->setMethods([
'criteria'])
311 ->expects($this->any())
313 ->willReturn([$criterionAssignment1, $criterionAssignment2]);
317 $constraint = new \ilTermsOfServiceDocumentCriterionAssignmentConstraint(
324 $ok = $dataFavtgory->ok($criterionAssignment1);
325 $ok2 = $dataFavtgory->ok($criterionAssignment3);
326 $error = $dataFavtgory->error(
'An error occurred');
329 $this->assertTrue(
$result->isOk());
331 $result = $constraint->restrict($ok2);
332 $this->assertTrue($result->isError());
334 $result = $constraint->restrict($error);
335 $this->assertSame($error, $result);
352 ->getMockBuilder(\ilTermsOfServiceDocument::class)
353 ->disableOriginalConstructor()
354 ->setMethods([
'criteria'])
358 ->expects($this->any())
360 ->willReturn([$criterionAssignment1, $criterionAssignment2]);
362 $constraint = new \ilTermsOfServiceDocumentCriterionAssignmentConstraint(
369 $newConstraint = $constraint->withProblemBuilder(
function () {
372 $this->assertEquals(
'phpunit', $newConstraint->problemWith($criterionAssignment3));
389 ->getMockBuilder(\ilTermsOfServiceDocument::class)
390 ->disableOriginalConstructor()
391 ->setMethods([
'criteria'])
395 ->expects($this->any())
397 ->willReturn([$criterionAssignment1, $criterionAssignment2]);
399 $constraint = new \ilTermsOfServiceDocumentCriterionAssignmentConstraint(
406 $criterionAssignment5 = clone $criterionAssignment3;
408 $constraint->accepts($criterionAssignment1);
409 $constraint->accepts($criterionAssignment2);
410 $constraint->accepts($criterionAssignment3);
411 $constraint->accepts($criterionAssignment4);
412 $constraint->accepts($criterionAssignment5);
414 $this->assertEquals(
'The passed assignment must be unique for the document!', $constraint->problemWith($criterionAssignment3));
415 $this->assertEquals(
'The passed assignment must be unique for the document!', $constraint->problemWith($criterionAssignment5));
432 ->getMockBuilder(\ilTermsOfServiceDocument::class)
433 ->disableOriginalConstructor()
434 ->setMethods([
'criteria'])
438 ->expects($this->any())
440 ->willReturn([$criterionAssignment1, $criterionAssignment2]);
448 ->expects($this->any())
449 ->method(
'hasUniqueNature')
453 ->expects($this->any())
454 ->method(
'hasUniqueNature')
457 $criterionTypeFactory
458 ->expects($this->any())
459 ->method(
'findByTypeIdent')
460 ->willReturn($criterionType2);
462 $constraint = new \ilTermsOfServiceDocumentCriterionAssignmentConstraint(
463 $criterionTypeFactory,
469 $criterionWithSameNature = $this
470 ->getMockBuilder(\ilTermsOfServiceDocumentCriterionAssignment::class)
471 ->setMethods([
'getId',
'getCriterionValue',
'getCriterionId'])
472 ->disableOriginalConstructor()
475 $criterionWithSameNature
476 ->expects($this->any())
480 $criterionWithSameNature
481 ->expects($this->any())
482 ->method(
'getCriterionId')
483 ->willReturn(
'usr_language');
485 $criterionWithSameNature
486 ->expects($this->any())
487 ->method(
'getCriterionValue')
490 $this->assertFalse($constraint->accepts($criterionWithSameNature));
testConstraintExposesCorrectErrorMessagesAfterMultiAccept(\ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment1, \ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment2, \ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment3, \ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment4)
criteriaAssignmentProvider
Interface ilTermsOfServiceCriterionType.
getCriterionTypeMock(string $typeIdent)
Class ilTermsOfServiceCriterionBaseTest.
Class ilTermsOfServiceDocumentCriterionAssignmentConstraintTest.
testConstraintProblemDetectionWorksAsExpected(\ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment1, \ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment2, \ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment3, \ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment4)
criteriaAssignmentProvider
testConstraintRestrictionWorksAsExpected(\ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment1, \ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment2, \ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment3, \ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment4)
criteriaAssignmentProvider
getCriterionConfig($value=null)
Class ilTermsOfServiceDocumentCriterionAssignment.
criteriaAssignmentProvider()
testConstraintCheckWorksAsExpected(\ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment1, \ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment2, \ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment3, \ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment4)
criteriaAssignmentProvider
getTypeMockForConstraint()
getCriterionTypeFactoryMock()
testConstraintAcceptanceWorksAsExpected(\ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment1, \ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment2, \ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment3, \ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment4)
criteriaAssignmentProvider
testConstraintProblemBuilderWorksAsExpected(\ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment1, \ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment2, \ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment3, \ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment4)
criteriaAssignmentProvider
testCriterionWithSameNatureIsNotAcceptedWhenAlreadyAssigned(\ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment1, \ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment2, \ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment3, \ilTermsOfServiceDocumentCriterionAssignment $criterionAssignment4)
criteriaAssignmentProvider
Interface ilTermsOfServiceCriterionTypeFactoryInterface.