289 : void
290 {
292
294 ->method('txt')
295 ->willReturn('translation');
296
298
299 $document = $this
300 ->getMockBuilder(ilTermsOfServiceDocument::class)
301 ->disableOriginalConstructor()
302 ->getMock();
303
304 $document
305 ->expects($this->never())
306 ->method('save');
307
308 $document
309 ->expects($this->never())
310 ->method('attachCriterion');
311
312 $criterionAssignment = $this
313 ->getMockBuilder(ilTermsOfServiceDocumentCriterionAssignment::class)
314 ->disableOriginalConstructor()
315 ->onlyMethods(['getCriterionId', 'getCriterionValue'])
316 ->addMethods(['getId'])
317 ->getMock();
318
319 $criterionAssignment
320 ->method('getId')
321 ->willReturn(1);
322
323 $criterionAssignment
324 ->method('getCriterionId')
325 ->willReturn('usr_global_role');
326
327 $criterionAssignment
328 ->method('getCriterionValue')
330
331 $criterionTypeFactory = $this
332 ->getMockBuilder(ilTermsOfServiceCriterionTypeFactoryInterface::class)
333 ->getMock();
334
335 $criterionType1 = $this
336 ->getMockBuilder(ilTermsOfServiceCriterionType::class)
337 ->getMock();
338
339 $criterionType1
340 ->method('getTypeIdent')
341 ->willReturn('dummy1');
342
343 $criterionType1
344 ->method('ui')
345 ->willReturn($this->getMockBuilder(ilTermsOfServiceCriterionTypeGUI::class)->getMock());
346
347 $criterionType2 = $this
348 ->getMockBuilder(ilTermsOfServiceCriterionType::class)
349 ->getMock();
350
351 $criterionType2
352 ->method('getTypeIdent')
353 ->willReturn('dummy2');
354
355 $criterionTypeGui2 = $this->getMockBuilder(ilTermsOfServiceCriterionTypeGUI::class)->getMock();
356
357 $criterionTypeGui2
358 ->method('getConfigByForm')
359 ->willReturn($criterionAssignment->getCriterionValue());
360
361 $criterionType2
362 ->method('ui')
363 ->willReturn($criterionTypeGui2);
364
365 $criterionTypeFactory
366 ->expects($this->once())
367 ->method('getTypesByIdentMap')
368 ->willReturn([
369 $criterionType1,
370 $criterionType2
371 ]);
372
373 $criterionTypeFactory
374 ->expects($this->exactly(2))
375 ->method('findByTypeIdent')
376 ->willReturnOnConsecutiveCalls(
378 $criterionType1
379 );
380
381 $anotherCriterionAssignment = $this
382 ->getMockBuilder(ilTermsOfServiceDocumentCriterionAssignment::class)
383 ->disableOriginalConstructor()
384 ->onlyMethods(['getCriterionId', 'getCriterionValue'])
385 ->addMethods(['getId'])
386 ->getMock();
387
388 $anotherCriterionAssignment
389 ->method('getId')
390 ->willReturn(2);
391
392 $anotherCriterionAssignment
393 ->method('getCriterionId')
394 ->willReturn('usr_global_role');
395
396 $anotherCriterionAssignment
397 ->method('getCriterionValue')
399
400 $document
401 ->expects($this->once())
402 ->method('criteria')
403 ->willReturn([$anotherCriterionAssignment]);
404
405 $user = $this
406 ->getMockBuilder(ilObjUser::class)
407 ->disableOriginalConstructor()
408 ->onlyMethods(['getId'])
409 ->getMock();
410
411 $user
412 ->method('getId')
413 ->willReturn(6);
414
415 $form = $this->getMockBuilder(ilTermsOfServiceCriterionFormGUI::class)
416 ->setConstructorArgs([
417 $document,
418 $criterionAssignment,
419 $criterionTypeFactory,
420 $user,
421 'action',
422 'save',
423 'cancel'
424 ])
425 ->onlyMethods(['checkInput'])
426 ->getMock();
427
428 $form
429 ->expects($this->exactly(2))
430 ->method('checkInput')
431 ->willReturn(true);
432
433 $form->setCheckInputCalled(true);
434
435 $this->assertFalse(
436 $form->saveObject(),
437 'Failed asserting form cannot be saved selected criterion type was not found'
438 );
439 $this->assertTrue($form->hasTranslatedError());
440 $this->assertNotEmpty($form->getTranslatedError());
441
442 $this->assertFalse(
443 $form->saveObject(),
444 'Failed asserting form cannot be saved selected criterion type was already assigned to document'
445 );
446 $this->assertTrue($form->hasTranslatedError());
447 $this->assertNotEmpty($form->getTranslatedError());
448 }
setGlobalVariable(string $name, $value)
Class ilTermsOfServiceCriterionConfig.
Class ilTermsOfServiceCriterionTypeNotFoundException.