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')
72 $criterionType1, $criterionType2
76 ->getMockBuilder(\ilObjUser::class)
77 ->disableOriginalConstructor()
80 $form = new \ilTermsOfServiceCriterionFormGUI(
83 $criterionTypeFactory,
90 $this->assertEquals($criterionType1->getTypeIdent(),
$form->getItemByPostVar(
'criterion')->getValue());
99 ->getMockBuilder(\ilTermsOfServiceDocument::class)
100 ->disableOriginalConstructor()
103 $criterionAssignment = $this
104 ->getMockBuilder(\ilTermsOfServiceDocumentCriterionAssignment::class)
105 ->disableOriginalConstructor()
106 ->setMethods([
'getId',
'getCriterionId',
'getCriterionValue'])
110 ->expects($this->any())
115 ->expects($this->any())
116 ->method(
'getCriterionId')
117 ->willReturn(
'dummy2');
120 ->expects($this->any())
121 ->method(
'getCriterionValue')
124 $criterionTypeFactory = $this
125 ->getMockBuilder(\ilTermsOfServiceCriterionTypeFactoryInterface::class)
128 $criterionType1 = $this
129 ->getMockBuilder(\ilTermsOfServiceCriterionType::class)
133 ->expects($this->any())
134 ->method(
'getTypeIdent')
135 ->willReturn(
'dummy1');
138 ->expects($this->any())
140 ->willReturn($this->getMockBuilder(\ilTermsOfServiceCriterionTypeGUI::class)->getMock());
142 $criterionType2 = $this
143 ->getMockBuilder(\ilTermsOfServiceCriterionType::class)
147 ->expects($this->any())
148 ->method(
'getTypeIdent')
149 ->willReturn(
'dummy2');
152 ->expects($this->any())
154 ->willReturn($this->getMockBuilder(\ilTermsOfServiceCriterionTypeGUI::class)->getMock());
156 $criterionTypeFactory
157 ->expects($this->
once())
158 ->method(
'getTypesByIdentMap')
160 $criterionType1, $criterionType2
164 ->getMockBuilder(\ilObjUser::class)
165 ->disableOriginalConstructor()
168 $form = new \ilTermsOfServiceCriterionFormGUI(
170 $criterionAssignment,
171 $criterionTypeFactory,
178 $this->assertEquals($criterionType2->getTypeIdent(),
$form->getItemByPostVar(
'criterion')->getValue());
187 ->getMockBuilder(\ilTermsOfServiceDocument::class)
188 ->disableOriginalConstructor()
192 ->expects($this->
once())
196 ->expects($this->
once())
197 ->method(
'attachCriterion');
199 $criterionAssignment = $this
200 ->getMockBuilder(\ilTermsOfServiceDocumentCriterionAssignment::class)
201 ->disableOriginalConstructor()
202 ->setMethods([
'getId',
'getCriterionId',
'getCriterionValue'])
206 ->expects($this->any())
211 ->expects($this->any())
212 ->method(
'getCriterionId')
215 $criterionTypeFactory = $this
216 ->getMockBuilder(\ilTermsOfServiceCriterionTypeFactoryInterface::class)
219 $criterionType1 = $this
220 ->getMockBuilder(\ilTermsOfServiceCriterionType::class)
224 ->expects($this->any())
225 ->method(
'getTypeIdent')
226 ->willReturn(
'dummy1');
229 ->expects($this->any())
231 ->willReturn($this->getMockBuilder(\ilTermsOfServiceCriterionTypeGUI::class)->getMock());
233 $criterionType2 = $this
234 ->getMockBuilder(\ilTermsOfServiceCriterionType::class)
238 ->expects($this->any())
239 ->method(
'getTypeIdent')
240 ->willReturn(
'dummy2');
243 ->expects($this->any())
245 ->willReturn($this->getMockBuilder(\ilTermsOfServiceCriterionTypeGUI::class)->getMock());
247 $criterionTypeFactory
248 ->expects($this->
once())
249 ->method(
'getTypesByIdentMap')
251 $criterionType1, $criterionType2
254 $criterionTypeFactory
255 ->expects($this->
once())
256 ->method(
'findByTypeIdent')
257 ->willReturn($criterionType1);
260 ->getMockBuilder(\ilObjUser::class)
261 ->disableOriginalConstructor()
262 ->setMethods([
'getId'])
266 ->expects($this->any())
270 $form = $this->getMockBuilder(\ilTermsOfServiceCriterionFormGUI::class)
271 ->setConstructorArgs([
272 $document, $criterionAssignment, $criterionTypeFactory,
$user,
273 'action',
'save',
'cancel' 275 ->setMethods([
'checkInput'])
279 ->expects($this->
once())
280 ->method(
'checkInput')
284 'criterion' => $criterionType1->getTypeIdent()
287 $form->setCheckInputCalled(
true);
289 $this->assertTrue(
$form->saveObject());
290 $this->assertFalse(
$form->hasTranslatedError());
291 $this->assertEmpty(
$form->getTranslatedError());
302 ->expects($this->any())
304 ->willReturn(
'translation');
309 ->getMockBuilder(\ilTermsOfServiceDocument::class)
310 ->disableOriginalConstructor()
314 ->expects($this->never())
318 ->expects($this->never())
319 ->method(
'attachCriterion');
321 $criterionAssignment = $this
322 ->getMockBuilder(\ilTermsOfServiceDocumentCriterionAssignment::class)
323 ->disableOriginalConstructor()
324 ->setMethods([
'getId',
'getCriterionId',
'getCriterionValue'])
328 ->expects($this->any())
333 ->expects($this->any())
334 ->method(
'getCriterionId')
335 ->willReturn(
'usr_global_role');
338 ->expects($this->any())
339 ->method(
'getCriterionValue')
342 $criterionTypeFactory = $this
343 ->getMockBuilder(\ilTermsOfServiceCriterionTypeFactoryInterface::class)
346 $criterionType1 = $this
347 ->getMockBuilder(\ilTermsOfServiceCriterionType::class)
351 ->expects($this->any())
352 ->method(
'getTypeIdent')
353 ->willReturn(
'dummy1');
356 ->expects($this->any())
358 ->willReturn($this->getMockBuilder(\ilTermsOfServiceCriterionTypeGUI::class)->getMock());
360 $criterionType2 = $this
361 ->getMockBuilder(\ilTermsOfServiceCriterionType::class)
365 ->expects($this->any())
366 ->method(
'getTypeIdent')
367 ->willReturn(
'dummy2');
369 $criterionTypeGui2 = $this->getMockBuilder(\ilTermsOfServiceCriterionTypeGUI::class)->getMock();
372 ->expects($this->any())
373 ->method(
'getConfigByForm')
374 ->willReturn($criterionAssignment->getCriterionValue());
377 ->expects($this->any())
379 ->willReturn($criterionTypeGui2);
381 $criterionTypeFactory
382 ->expects($this->
once())
383 ->method(
'getTypesByIdentMap')
385 $criterionType1, $criterionType2
388 $criterionTypeFactory
389 ->expects($this->exactly(2))
390 ->method(
'findByTypeIdent')
391 ->willReturnOnConsecutiveCalls(
396 $anotherCriterionAssignment = $this
397 ->getMockBuilder(\ilTermsOfServiceDocumentCriterionAssignment::class)
398 ->disableOriginalConstructor()
399 ->setMethods([
'getId',
'getCriterionId',
'getCriterionValue'])
402 $anotherCriterionAssignment
403 ->expects($this->any())
407 $anotherCriterionAssignment
408 ->expects($this->any())
409 ->method(
'getCriterionId')
410 ->willReturn(
'usr_global_role');
412 $anotherCriterionAssignment
413 ->expects($this->any())
414 ->method(
'getCriterionValue')
418 ->expects($this->
once())
420 ->willReturn([$anotherCriterionAssignment]);
423 ->getMockBuilder(\ilObjUser::class)
424 ->disableOriginalConstructor()
425 ->setMethods([
'getId'])
429 ->expects($this->any())
433 $form = $this->getMockBuilder(\ilTermsOfServiceCriterionFormGUI::class)
434 ->setConstructorArgs([
435 $document, $criterionAssignment, $criterionTypeFactory,
$user,
436 'action',
'save',
'cancel' 438 ->setMethods([
'checkInput'])
442 ->expects($this->exactly(2))
443 ->method(
'checkInput')
447 'criterion' => $criterionType1->getTypeIdent()
450 $form->setCheckInputCalled(
true);
454 'Failed asserting form cannot be saved selected criterion type was not found' 456 $this->assertTrue(
$form->hasTranslatedError());
457 $this->assertNotEmpty(
$form->getTranslatedError());
461 'Failed asserting form cannot be saved selected criterion type was already assigned to document' 463 $this->assertTrue(
$form->hasTranslatedError());
464 $this->assertNotEmpty(
$form->getTranslatedError());
setGlobalVariable(string $name, $value)
Class ilTermsOfServiceCriterionTypeNotFoundException.
Class ilTermsOfServiceCriterionConfig.
Class ilTermsOfServiceBaseTest.
if(isset($_POST['submit'])) $form
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.