1 <?php declare(strict_types=1);
16 ->getMockBuilder(ilTermsOfServiceDocument::class)
17 ->disableOriginalConstructor()
20 $criterionAssignment = $this
21 ->getMockBuilder(ilTermsOfServiceDocumentCriterionAssignment::class)
22 ->disableOriginalConstructor()
23 ->onlyMethods([
'getCriterionId'])
24 ->addMethods([
'getId'])
28 ->expects($this->any())
33 ->expects($this->any())
34 ->method(
'getCriterionId')
37 $criterionTypeFactory = $this
38 ->getMockBuilder(ilTermsOfServiceCriterionTypeFactoryInterface::class)
41 $criterionType1 = $this
42 ->getMockBuilder(ilTermsOfServiceCriterionType::class)
46 ->expects($this->any())
47 ->method(
'getTypeIdent')
48 ->willReturn(
'dummy1');
51 ->expects($this->any())
53 ->willReturn($this->getMockBuilder(ilTermsOfServiceCriterionTypeGUI::class)->getMock());
55 $criterionType2 = $this
56 ->getMockBuilder(ilTermsOfServiceCriterionType::class)
60 ->expects($this->any())
61 ->method(
'getTypeIdent')
62 ->willReturn(
'dummy2');
65 ->expects($this->any())
67 ->willReturn($this->getMockBuilder(ilTermsOfServiceCriterionTypeGUI::class)->getMock());
70 ->expects($this->once())
71 ->method(
'getTypesByIdentMap')
78 ->getMockBuilder(ilObjUser::class)
79 ->disableOriginalConstructor()
85 $criterionTypeFactory,
92 $this->assertEquals($criterionType1->getTypeIdent(), $form->getItemByPostVar(
'criterion')->getValue());
101 ->getMockBuilder(ilTermsOfServiceDocument::class)
102 ->disableOriginalConstructor()
105 $criterionAssignment = $this
106 ->getMockBuilder(ilTermsOfServiceDocumentCriterionAssignment::class)
107 ->disableOriginalConstructor()
108 ->onlyMethods([
'getCriterionId',
'getCriterionValue'])
109 ->addMethods([
'getId'])
113 ->expects($this->any())
118 ->expects($this->any())
119 ->method(
'getCriterionId')
120 ->willReturn(
'dummy2');
123 ->expects($this->any())
124 ->method(
'getCriterionValue')
127 $criterionTypeFactory = $this
128 ->getMockBuilder(ilTermsOfServiceCriterionTypeFactoryInterface::class)
131 $criterionType1 = $this
132 ->getMockBuilder(ilTermsOfServiceCriterionType::class)
136 ->expects($this->any())
137 ->method(
'getTypeIdent')
138 ->willReturn(
'dummy1');
141 ->expects($this->any())
143 ->willReturn($this->getMockBuilder(ilTermsOfServiceCriterionTypeGUI::class)->getMock());
145 $criterionType2 = $this
146 ->getMockBuilder(ilTermsOfServiceCriterionType::class)
150 ->expects($this->any())
151 ->method(
'getTypeIdent')
152 ->willReturn(
'dummy2');
155 ->expects($this->any())
157 ->willReturn($this->getMockBuilder(ilTermsOfServiceCriterionTypeGUI::class)->getMock());
159 $criterionTypeFactory
160 ->expects($this->once())
161 ->method(
'getTypesByIdentMap')
168 ->getMockBuilder(ilObjUser::class)
169 ->disableOriginalConstructor()
174 $criterionAssignment,
175 $criterionTypeFactory,
182 $this->assertEquals($criterionType2->getTypeIdent(), $form->getItemByPostVar(
'criterion')->getValue());
191 ->getMockBuilder(ilTermsOfServiceDocument::class)
192 ->disableOriginalConstructor()
196 ->expects($this->once())
200 ->expects($this->once())
201 ->method(
'attachCriterion');
203 $criterionAssignment = $this
204 ->getMockBuilder(ilTermsOfServiceDocumentCriterionAssignment::class)
205 ->disableOriginalConstructor()
206 ->onlyMethods([
'getCriterionId',
'getCriterionValue'])
207 ->addMethods([
'getId'])
211 ->expects($this->any())
216 ->expects($this->any())
217 ->method(
'getCriterionId')
220 $criterionTypeFactory = $this
221 ->getMockBuilder(ilTermsOfServiceCriterionTypeFactoryInterface::class)
224 $criterionType1 = $this
225 ->getMockBuilder(ilTermsOfServiceCriterionType::class)
229 ->expects($this->any())
230 ->method(
'getTypeIdent')
231 ->willReturn(
'dummy1');
234 ->expects($this->any())
236 ->willReturn($this->getMockBuilder(ilTermsOfServiceCriterionTypeGUI::class)->getMock());
238 $criterionType2 = $this
239 ->getMockBuilder(ilTermsOfServiceCriterionType::class)
243 ->expects($this->any())
244 ->method(
'getTypeIdent')
245 ->willReturn(
'dummy2');
248 ->expects($this->any())
250 ->willReturn($this->getMockBuilder(ilTermsOfServiceCriterionTypeGUI::class)->getMock());
252 $criterionTypeFactory
253 ->expects($this->once())
254 ->method(
'getTypesByIdentMap')
260 $criterionTypeFactory
261 ->expects($this->once())
262 ->method(
'findByTypeIdent')
263 ->willReturn($criterionType1);
266 ->getMockBuilder(ilObjUser::class)
267 ->disableOriginalConstructor()
268 ->onlyMethods([
'getId'])
272 ->expects($this->any())
276 $form = $this->getMockBuilder(ilTermsOfServiceCriterionFormGUI::class)
277 ->setConstructorArgs([
279 $criterionAssignment,
280 $criterionTypeFactory,
286 ->onlyMethods([
'checkInput'])
290 ->expects($this->once())
291 ->method(
'checkInput')
295 'criterion' => $criterionType1->getTypeIdent()
298 $form->setCheckInputCalled(
true);
300 $this->assertTrue($form->saveObject());
301 $this->assertFalse($form->hasTranslatedError());
302 $this->assertEmpty($form->getTranslatedError());
313 ->expects($this->any())
315 ->willReturn(
'translation');
320 ->getMockBuilder(ilTermsOfServiceDocument::class)
321 ->disableOriginalConstructor()
325 ->expects($this->never())
329 ->expects($this->never())
330 ->method(
'attachCriterion');
332 $criterionAssignment = $this
333 ->getMockBuilder(ilTermsOfServiceDocumentCriterionAssignment::class)
334 ->disableOriginalConstructor()
335 ->onlyMethods([
'getCriterionId',
'getCriterionValue'])
336 ->addMethods([
'getId'])
340 ->expects($this->any())
345 ->expects($this->any())
346 ->method(
'getCriterionId')
347 ->willReturn(
'usr_global_role');
350 ->expects($this->any())
351 ->method(
'getCriterionValue')
354 $criterionTypeFactory = $this
355 ->getMockBuilder(ilTermsOfServiceCriterionTypeFactoryInterface::class)
358 $criterionType1 = $this
359 ->getMockBuilder(ilTermsOfServiceCriterionType::class)
363 ->expects($this->any())
364 ->method(
'getTypeIdent')
365 ->willReturn(
'dummy1');
368 ->expects($this->any())
370 ->willReturn($this->getMockBuilder(ilTermsOfServiceCriterionTypeGUI::class)->getMock());
372 $criterionType2 = $this
373 ->getMockBuilder(ilTermsOfServiceCriterionType::class)
377 ->expects($this->any())
378 ->method(
'getTypeIdent')
379 ->willReturn(
'dummy2');
381 $criterionTypeGui2 = $this->getMockBuilder(ilTermsOfServiceCriterionTypeGUI::class)->getMock();
384 ->expects($this->any())
385 ->method(
'getConfigByForm')
386 ->willReturn($criterionAssignment->getCriterionValue());
389 ->expects($this->any())
391 ->willReturn($criterionTypeGui2);
393 $criterionTypeFactory
394 ->expects($this->once())
395 ->method(
'getTypesByIdentMap')
401 $criterionTypeFactory
402 ->expects($this->exactly(2))
403 ->method(
'findByTypeIdent')
404 ->willReturnOnConsecutiveCalls(
409 $anotherCriterionAssignment = $this
410 ->getMockBuilder(ilTermsOfServiceDocumentCriterionAssignment::class)
411 ->disableOriginalConstructor()
412 ->onlyMethods([
'getCriterionId',
'getCriterionValue'])
413 ->addMethods([
'getId'])
416 $anotherCriterionAssignment
417 ->expects($this->any())
421 $anotherCriterionAssignment
422 ->expects($this->any())
423 ->method(
'getCriterionId')
424 ->willReturn(
'usr_global_role');
426 $anotherCriterionAssignment
427 ->expects($this->any())
428 ->method(
'getCriterionValue')
432 ->expects($this->once())
434 ->willReturn([$anotherCriterionAssignment]);
437 ->getMockBuilder(ilObjUser::class)
438 ->disableOriginalConstructor()
439 ->onlyMethods([
'getId'])
443 ->expects($this->any())
447 $form = $this->getMockBuilder(ilTermsOfServiceCriterionFormGUI::class)
448 ->setConstructorArgs([
450 $criterionAssignment,
451 $criterionTypeFactory,
457 ->onlyMethods([
'checkInput'])
461 ->expects($this->exactly(2))
462 ->method(
'checkInput')
466 'criterion' => $criterionType1->getTypeIdent()
469 $form->setCheckInputCalled(
true);
473 'Failed asserting form cannot be saved selected criterion type was not found' 475 $this->assertTrue($form->hasTranslatedError());
476 $this->assertNotEmpty($form->getTranslatedError());
480 'Failed asserting form cannot be saved selected criterion type was already assigned to document' 482 $this->assertTrue($form->hasTranslatedError());
483 $this->assertNotEmpty($form->getTranslatedError());
setGlobalVariable(string $name, $value)
Class ilTermsOfServiceCriterionTypeNotFoundException.
Class ilTermsOfServiceCriterionConfig.
Class ilTermsOfServiceBaseTest.