19 declare(strict_types=1);
30 ->getMockBuilder(ilTermsOfServiceDocument::class)
31 ->disableOriginalConstructor()
34 $criterionAssignment = $this
35 ->getMockBuilder(ilTermsOfServiceDocumentCriterionAssignment::class)
36 ->disableOriginalConstructor()
37 ->onlyMethods([
'getCriterionId'])
38 ->addMethods([
'getId'])
46 ->method(
'getCriterionId')
49 $criterionTypeFactory = $this
50 ->getMockBuilder(ilTermsOfServiceCriterionTypeFactoryInterface::class)
53 $criterionType1 = $this
54 ->getMockBuilder(ilTermsOfServiceCriterionType::class)
58 ->method(
'getTypeIdent')
59 ->willReturn(
'dummy1');
63 ->willReturn($this->getMockBuilder(ilTermsOfServiceCriterionTypeGUI::class)->getMock());
65 $criterionType2 = $this
66 ->getMockBuilder(ilTermsOfServiceCriterionType::class)
70 ->method(
'getTypeIdent')
71 ->willReturn(
'dummy2');
75 ->willReturn($this->getMockBuilder(ilTermsOfServiceCriterionTypeGUI::class)->getMock());
78 ->expects($this->once())
79 ->method(
'getTypesByIdentMap')
86 ->getMockBuilder(ilObjUser::class)
87 ->disableOriginalConstructor()
93 $criterionTypeFactory,
100 $this->assertSame($criterionType1->getTypeIdent(), $form->getItemByPostVar(
'criterion')->getValue());
106 ->getMockBuilder(ilTermsOfServiceDocument::class)
107 ->disableOriginalConstructor()
110 $criterionAssignment = $this
111 ->getMockBuilder(ilTermsOfServiceDocumentCriterionAssignment::class)
112 ->disableOriginalConstructor()
113 ->onlyMethods([
'getCriterionId',
'getCriterionValue'])
114 ->addMethods([
'getId'])
122 ->method(
'getCriterionId')
123 ->willReturn(
'dummy2');
126 ->method(
'getCriterionValue')
129 $criterionTypeFactory = $this
130 ->getMockBuilder(ilTermsOfServiceCriterionTypeFactoryInterface::class)
133 $criterionType1 = $this
134 ->getMockBuilder(ilTermsOfServiceCriterionType::class)
138 ->method(
'getTypeIdent')
139 ->willReturn(
'dummy1');
143 ->willReturn($this->getMockBuilder(ilTermsOfServiceCriterionTypeGUI::class)->getMock());
145 $criterionType2 = $this
146 ->getMockBuilder(ilTermsOfServiceCriterionType::class)
150 ->method(
'getTypeIdent')
151 ->willReturn(
'dummy2');
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->assertSame($criterionType2->getTypeIdent(), $form->getItemByPostVar(
'criterion')->getValue());
186 ->getMockBuilder(ilTermsOfServiceDocument::class)
187 ->disableOriginalConstructor()
191 ->expects($this->once())
195 ->expects($this->once())
196 ->method(
'attachCriterion');
198 $criterionAssignment = $this
199 ->getMockBuilder(ilTermsOfServiceDocumentCriterionAssignment::class)
200 ->disableOriginalConstructor()
201 ->onlyMethods([
'getCriterionId',
'getCriterionValue'])
202 ->addMethods([
'getId'])
210 ->method(
'getCriterionId')
213 $criterionTypeFactory = $this
214 ->getMockBuilder(ilTermsOfServiceCriterionTypeFactoryInterface::class)
217 $criterionType1 = $this
218 ->getMockBuilder(ilTermsOfServiceCriterionType::class)
222 ->method(
'getTypeIdent')
223 ->willReturn(
'dummy1');
227 ->willReturn($this->getMockBuilder(ilTermsOfServiceCriterionTypeGUI::class)->getMock());
229 $criterionType2 = $this
230 ->getMockBuilder(ilTermsOfServiceCriterionType::class)
234 ->method(
'getTypeIdent')
235 ->willReturn(
'dummy2');
239 ->willReturn($this->getMockBuilder(ilTermsOfServiceCriterionTypeGUI::class)->getMock());
241 $criterionTypeFactory
242 ->expects($this->once())
243 ->method(
'getTypesByIdentMap')
249 $criterionTypeFactory
250 ->expects($this->once())
251 ->method(
'findByTypeIdent')
252 ->willReturn($criterionType1);
255 ->getMockBuilder(ilObjUser::class)
256 ->disableOriginalConstructor()
257 ->onlyMethods([
'getId'])
264 $form = $this->getMockBuilder(ilTermsOfServiceCriterionFormGUI::class)
265 ->setConstructorArgs([
267 $criterionAssignment,
268 $criterionTypeFactory,
274 ->onlyMethods([
'checkInput'])
278 ->expects($this->once())
279 ->method(
'checkInput')
282 $form->setCheckInputCalled(
true);
284 $this->assertTrue($form->saveObject());
285 $this->assertFalse($form->hasTranslatedError());
286 $this->assertEmpty($form->getTranslatedError());
295 ->willReturn(
'translation');
300 ->getMockBuilder(ilTermsOfServiceDocument::class)
301 ->disableOriginalConstructor()
305 ->expects($this->never())
309 ->expects($this->never())
310 ->method(
'attachCriterion');
312 $criterionAssignment = $this
313 ->getMockBuilder(ilTermsOfServiceDocumentCriterionAssignment::class)
314 ->disableOriginalConstructor()
315 ->onlyMethods([
'getCriterionId',
'getCriterionValue'])
316 ->addMethods([
'getId'])
324 ->method(
'getCriterionId')
325 ->willReturn(
'usr_global_role');
328 ->method(
'getCriterionValue')
331 $criterionTypeFactory = $this
332 ->getMockBuilder(ilTermsOfServiceCriterionTypeFactoryInterface::class)
335 $criterionType1 = $this
336 ->getMockBuilder(ilTermsOfServiceCriterionType::class)
340 ->method(
'getTypeIdent')
341 ->willReturn(
'dummy1');
345 ->willReturn($this->getMockBuilder(ilTermsOfServiceCriterionTypeGUI::class)->getMock());
347 $criterionType2 = $this
348 ->getMockBuilder(ilTermsOfServiceCriterionType::class)
352 ->method(
'getTypeIdent')
353 ->willReturn(
'dummy2');
355 $criterionTypeGui2 = $this->getMockBuilder(ilTermsOfServiceCriterionTypeGUI::class)->getMock();
358 ->method(
'getConfigByForm')
359 ->willReturn($criterionAssignment->getCriterionValue());
363 ->willReturn($criterionTypeGui2);
365 $criterionTypeFactory
366 ->expects($this->once())
367 ->method(
'getTypesByIdentMap')
373 $criterionTypeFactory
374 ->expects($this->exactly(2))
375 ->method(
'findByTypeIdent')
376 ->willReturnOnConsecutiveCalls(
381 $anotherCriterionAssignment = $this
382 ->getMockBuilder(ilTermsOfServiceDocumentCriterionAssignment::class)
383 ->disableOriginalConstructor()
384 ->onlyMethods([
'getCriterionId',
'getCriterionValue'])
385 ->addMethods([
'getId'])
388 $anotherCriterionAssignment
392 $anotherCriterionAssignment
393 ->method(
'getCriterionId')
394 ->willReturn(
'usr_global_role');
396 $anotherCriterionAssignment
397 ->method(
'getCriterionValue')
401 ->expects($this->once())
403 ->willReturn([$anotherCriterionAssignment]);
406 ->getMockBuilder(ilObjUser::class)
407 ->disableOriginalConstructor()
408 ->onlyMethods([
'getId'])
415 $form = $this->getMockBuilder(ilTermsOfServiceCriterionFormGUI::class)
416 ->setConstructorArgs([
418 $criterionAssignment,
419 $criterionTypeFactory,
425 ->onlyMethods([
'checkInput'])
429 ->expects($this->exactly(2))
430 ->method(
'checkInput')
433 $form->setCheckInputCalled(
true);
437 'Failed asserting form cannot be saved selected criterion type was not found' 439 $this->assertTrue($form->hasTranslatedError());
440 $this->assertNotEmpty($form->getTranslatedError());
444 'Failed asserting form cannot be saved selected criterion type was already assigned to document' 446 $this->assertTrue($form->hasTranslatedError());
447 $this->assertNotEmpty($form->getTranslatedError());
setGlobalVariable(string $name, $value)
Class ilTermsOfServiceCriterionTypeNotFoundException.
Class ilTermsOfServiceCriterionConfig.
Class ilTermsOfServiceBaseTest.