1 <?php declare(strict_types=1);
16 ->getMockBuilder(ilTermsOfServiceDocument::class)
17 ->disableOriginalConstructor()
20 $criterionAssignment = $this
21 ->getMockBuilder(ilTermsOfServiceDocumentCriterionAssignment::class)
22 ->disableOriginalConstructor()
23 ->setMethods([
'getId',
'getCriterionId'])
27 ->expects($this->any())
32 ->expects($this->any())
33 ->method(
'getCriterionId')
36 $criterionTypeFactory = $this
37 ->getMockBuilder(ilTermsOfServiceCriterionTypeFactoryInterface::class)
40 $criterionType1 = $this
41 ->getMockBuilder(ilTermsOfServiceCriterionType::class)
45 ->expects($this->any())
46 ->method(
'getTypeIdent')
47 ->willReturn(
'dummy1');
50 ->expects($this->any())
52 ->willReturn($this->getMockBuilder(ilTermsOfServiceCriterionTypeGUI::class)->getMock());
54 $criterionType2 = $this
55 ->getMockBuilder(ilTermsOfServiceCriterionType::class)
59 ->expects($this->any())
60 ->method(
'getTypeIdent')
61 ->willReturn(
'dummy2');
64 ->expects($this->any())
66 ->willReturn($this->getMockBuilder(ilTermsOfServiceCriterionTypeGUI::class)->getMock());
69 ->expects($this->once())
70 ->method(
'getTypesByIdentMap')
77 ->getMockBuilder(ilObjUser::class)
78 ->disableOriginalConstructor()
84 $criterionTypeFactory,
91 $this->assertEquals($criterionType1->getTypeIdent(), $form->getItemByPostVar(
'criterion')->getValue());
100 ->getMockBuilder(ilTermsOfServiceDocument::class)
101 ->disableOriginalConstructor()
104 $criterionAssignment = $this
105 ->getMockBuilder(ilTermsOfServiceDocumentCriterionAssignment::class)
106 ->disableOriginalConstructor()
107 ->setMethods([
'getId',
'getCriterionId',
'getCriterionValue'])
111 ->expects($this->any())
116 ->expects($this->any())
117 ->method(
'getCriterionId')
118 ->willReturn(
'dummy2');
121 ->expects($this->any())
122 ->method(
'getCriterionValue')
125 $criterionTypeFactory = $this
126 ->getMockBuilder(ilTermsOfServiceCriterionTypeFactoryInterface::class)
129 $criterionType1 = $this
130 ->getMockBuilder(ilTermsOfServiceCriterionType::class)
134 ->expects($this->any())
135 ->method(
'getTypeIdent')
136 ->willReturn(
'dummy1');
139 ->expects($this->any())
141 ->willReturn($this->getMockBuilder(ilTermsOfServiceCriterionTypeGUI::class)->getMock());
143 $criterionType2 = $this
144 ->getMockBuilder(ilTermsOfServiceCriterionType::class)
148 ->expects($this->any())
149 ->method(
'getTypeIdent')
150 ->willReturn(
'dummy2');
153 ->expects($this->any())
155 ->willReturn($this->getMockBuilder(ilTermsOfServiceCriterionTypeGUI::class)->getMock());
157 $criterionTypeFactory
158 ->expects($this->once())
159 ->method(
'getTypesByIdentMap')
166 ->getMockBuilder(ilObjUser::class)
167 ->disableOriginalConstructor()
172 $criterionAssignment,
173 $criterionTypeFactory,
180 $this->assertEquals($criterionType2->getTypeIdent(), $form->getItemByPostVar(
'criterion')->getValue());
189 ->getMockBuilder(ilTermsOfServiceDocument::class)
190 ->disableOriginalConstructor()
194 ->expects($this->once())
198 ->expects($this->once())
199 ->method(
'attachCriterion');
201 $criterionAssignment = $this
202 ->getMockBuilder(ilTermsOfServiceDocumentCriterionAssignment::class)
203 ->disableOriginalConstructor()
204 ->setMethods([
'getId',
'getCriterionId',
'getCriterionValue'])
208 ->expects($this->any())
213 ->expects($this->any())
214 ->method(
'getCriterionId')
217 $criterionTypeFactory = $this
218 ->getMockBuilder(ilTermsOfServiceCriterionTypeFactoryInterface::class)
221 $criterionType1 = $this
222 ->getMockBuilder(ilTermsOfServiceCriterionType::class)
226 ->expects($this->any())
227 ->method(
'getTypeIdent')
228 ->willReturn(
'dummy1');
231 ->expects($this->any())
233 ->willReturn($this->getMockBuilder(ilTermsOfServiceCriterionTypeGUI::class)->getMock());
235 $criterionType2 = $this
236 ->getMockBuilder(ilTermsOfServiceCriterionType::class)
240 ->expects($this->any())
241 ->method(
'getTypeIdent')
242 ->willReturn(
'dummy2');
245 ->expects($this->any())
247 ->willReturn($this->getMockBuilder(ilTermsOfServiceCriterionTypeGUI::class)->getMock());
249 $criterionTypeFactory
250 ->expects($this->once())
251 ->method(
'getTypesByIdentMap')
257 $criterionTypeFactory
258 ->expects($this->once())
259 ->method(
'findByTypeIdent')
260 ->willReturn($criterionType1);
263 ->getMockBuilder(ilObjUser::class)
264 ->disableOriginalConstructor()
265 ->setMethods([
'getId'])
269 ->expects($this->any())
273 $form = $this->getMockBuilder(ilTermsOfServiceCriterionFormGUI::class)
274 ->setConstructorArgs([
276 $criterionAssignment,
277 $criterionTypeFactory,
283 ->setMethods([
'checkInput'])
287 ->expects($this->once())
288 ->method(
'checkInput')
292 'criterion' => $criterionType1->getTypeIdent()
295 $form->setCheckInputCalled(
true);
297 $this->assertTrue($form->saveObject());
298 $this->assertFalse($form->hasTranslatedError());
299 $this->assertEmpty($form->getTranslatedError());
310 ->expects($this->any())
312 ->willReturn(
'translation');
317 ->getMockBuilder(ilTermsOfServiceDocument::class)
318 ->disableOriginalConstructor()
322 ->expects($this->never())
326 ->expects($this->never())
327 ->method(
'attachCriterion');
329 $criterionAssignment = $this
330 ->getMockBuilder(ilTermsOfServiceDocumentCriterionAssignment::class)
331 ->disableOriginalConstructor()
332 ->setMethods([
'getId',
'getCriterionId',
'getCriterionValue'])
336 ->expects($this->any())
341 ->expects($this->any())
342 ->method(
'getCriterionId')
343 ->willReturn(
'usr_global_role');
346 ->expects($this->any())
347 ->method(
'getCriterionValue')
350 $criterionTypeFactory = $this
351 ->getMockBuilder(ilTermsOfServiceCriterionTypeFactoryInterface::class)
354 $criterionType1 = $this
355 ->getMockBuilder(ilTermsOfServiceCriterionType::class)
359 ->expects($this->any())
360 ->method(
'getTypeIdent')
361 ->willReturn(
'dummy1');
364 ->expects($this->any())
366 ->willReturn($this->getMockBuilder(ilTermsOfServiceCriterionTypeGUI::class)->getMock());
368 $criterionType2 = $this
369 ->getMockBuilder(ilTermsOfServiceCriterionType::class)
373 ->expects($this->any())
374 ->method(
'getTypeIdent')
375 ->willReturn(
'dummy2');
377 $criterionTypeGui2 = $this->getMockBuilder(ilTermsOfServiceCriterionTypeGUI::class)->getMock();
380 ->expects($this->any())
381 ->method(
'getConfigByForm')
382 ->willReturn($criterionAssignment->getCriterionValue());
385 ->expects($this->any())
387 ->willReturn($criterionTypeGui2);
389 $criterionTypeFactory
390 ->expects($this->once())
391 ->method(
'getTypesByIdentMap')
397 $criterionTypeFactory
398 ->expects($this->exactly(2))
399 ->method(
'findByTypeIdent')
400 ->willReturnOnConsecutiveCalls(
405 $anotherCriterionAssignment = $this
406 ->getMockBuilder(ilTermsOfServiceDocumentCriterionAssignment::class)
407 ->disableOriginalConstructor()
408 ->setMethods([
'getId',
'getCriterionId',
'getCriterionValue'])
411 $anotherCriterionAssignment
412 ->expects($this->any())
416 $anotherCriterionAssignment
417 ->expects($this->any())
418 ->method(
'getCriterionId')
419 ->willReturn(
'usr_global_role');
421 $anotherCriterionAssignment
422 ->expects($this->any())
423 ->method(
'getCriterionValue')
427 ->expects($this->once())
429 ->willReturn([$anotherCriterionAssignment]);
432 ->getMockBuilder(ilObjUser::class)
433 ->disableOriginalConstructor()
434 ->setMethods([
'getId'])
438 ->expects($this->any())
442 $form = $this->getMockBuilder(ilTermsOfServiceCriterionFormGUI::class)
443 ->setConstructorArgs([
445 $criterionAssignment,
446 $criterionTypeFactory,
452 ->setMethods([
'checkInput'])
456 ->expects($this->exactly(2))
457 ->method(
'checkInput')
461 'criterion' => $criterionType1->getTypeIdent()
464 $form->setCheckInputCalled(
true);
468 'Failed asserting form cannot be saved selected criterion type was not found' 470 $this->assertTrue($form->hasTranslatedError());
471 $this->assertNotEmpty($form->getTranslatedError());
475 'Failed asserting form cannot be saved selected criterion type was already assigned to document' 477 $this->assertTrue($form->hasTranslatedError());
478 $this->assertNotEmpty($form->getTranslatedError());
setGlobalVariable(string $name, $value)
Class ilTermsOfServiceCriterionTypeNotFoundException.
Class ilTermsOfServiceCriterionConfig.
Class ilTermsOfServiceBaseTest.