1 <?php declare(strict_types=1);
23 ->getMockBuilder(ilTermsOfServiceDocument::class)
24 ->disableOriginalConstructor()
25 ->setMethods([
'getId'])
29 ->getMockBuilder(ilHtmlPurifierInterface::class)
33 ->getMockBuilder(ilObjUser::class)
34 ->disableOriginalConstructor()
38 ->getMockBuilder(Filesystem::class)
42 ->getMockBuilder(FileUpload::class)
58 $form->getItemByPostVar(
'document')->getRequired(),
59 'Failed asserting document upload is required for new documents' 64 $form->getCommandButtons(),
65 'Failed asserting save and cancel buttons are given if form is editable' 67 $this->assertArrayHasKey(
69 $form->getCommandButtons(),
70 'Failed asserting save and cancel buttons are given if form is editable' 72 $this->assertArrayHasKey(
74 $form->getCommandButtons(),
75 'Failed asserting save and cancel buttons are given if form is editable' 79 $form->getCommandButtons()[0][
'cmd'],
80 'Failed asserting save and cancel buttons are given if form is editable' 84 $form->getCommandButtons()[1][
'cmd'],
85 'Failed asserting save and cancel buttons are given if form is editable' 102 $form->getCommandButtons(),
103 'Failed asserting only cancel button is given if form is not editable' 105 $this->assertArrayHasKey(
107 $form->getCommandButtons(),
108 'Failed asserting only cancel button is given if form is not editable' 112 $form->getCommandButtons()[0][
'cmd'],
113 'Failed asserting only cancel button is given if form is not editable' 123 ->getMockBuilder(ilTermsOfServiceDocument::class)
124 ->disableOriginalConstructor()
125 ->setMethods([
'getId',
'fetchAllCriterionAssignments'])
129 ->expects($this->any())
130 ->method(
'fetchAllCriterionAssignments');
133 ->getMockBuilder(ilHtmlPurifierInterface::class)
140 $this->getMockBuilder(ImmutableStringMap::class)->getMock(),
146 ->getMockBuilder(ilObjUser::class)
147 ->disableOriginalConstructor()
148 ->setMethods([
'getId'])
152 ->expects($this->exactly(2))
157 ->getMockBuilder(Filesystem::class)
161 ->expects($this->exactly(2))
163 ->with(
'/agreements/' . $uploadResult->getName())
167 ->expects($this->exactly(2))
169 ->with(
'/agreements/' . $uploadResult->getName())
170 ->willReturn(
'phpunit');
173 ->expects($this->atLeast(1))
176 ->willReturnArgument(0);
179 ->expects($this->exactly(2))
181 ->with(
'/agreements/' . $uploadResult->getName());
184 ->getMockBuilder(FileUpload::class)
198 ->expects($this->any())
199 ->method(
'hasUploads')
203 ->expects($this->exactly(2))
204 ->method(
'hasBeenProcessed')
208 ->expects($this->exactly(2))
212 ->expects($this->exactly(2))
213 ->method(
'getResults')
219 ->expects($this->exactly(2))
220 ->method(
'moveOneFileTo')
231 $documentConnector = $this->getMockBuilder(arConnector::class)->getMock();
232 $criterionConnector = $this->getMockBuilder(arConnector::class)->getMock();
234 $expectedSortingValueExistingDocuments = 10;
237 ->expects($this->once())
239 ->willReturnCallback(
function () use ($expectedSortingValueExistingDocuments) {
243 'title' =>
'another',
244 'sorting' => $expectedSortingValueExistingDocuments - 1,
250 ->expects($this->once())
258 $form = $this->getMockBuilder(ilTermsOfServiceDocumentFormGUI::class)
259 ->setConstructorArgs([
270 ->setMethods([
'checkInput'])
274 ->expects($this->once())
275 ->method(
'checkInput')
278 $_FILES[
'document'] = [];
280 'title' =>
'phpunit',
284 $form->setCheckInputCalled(
true);
286 $this->assertTrue($form->saveObject());
287 $this->assertFalse($form->hasTranslatedError());
288 $this->assertEmpty($form->getTranslatedError());
290 $expectedSortingValueExistingDocuments,
291 $document->getSorting(),
292 'Failed asserting that the sorting of the new document equals the maximum incremented by one when other documents exist' 295 $documentConnector = $this->getMockBuilder(arConnector::class)->getMock();
298 ->expects($this->once())
300 ->willReturnCallback(
function () {
306 $form = $this->getMockBuilder(ilTermsOfServiceDocumentFormGUI::class)
307 ->setConstructorArgs([
318 ->setMethods([
'checkInput'])
322 ->expects($this->once())
323 ->method(
'checkInput')
326 $form->setCheckInputCalled(
true);
328 $this->assertTrue($form->saveObject());
329 $this->assertFalse($form->hasTranslatedError());
330 $this->assertEmpty($form->getTranslatedError());
333 $document->getSorting(),
334 'Failed asserting that the sorting of the new document equals 1 when no other document exists' 344 ->getMockBuilder(ilTermsOfServiceDocument::class)
345 ->disableOriginalConstructor()
346 ->setMethods([
'getId'])
350 ->expects($this->any())
355 ->getMockBuilder(ilHtmlPurifierInterface::class)
359 ->getMockBuilder(ilObjUser::class)
360 ->disableOriginalConstructor()
361 ->setMethods([
'getId'])
365 ->getMockBuilder(Filesystem::class)
369 ->getMockBuilder(FileUpload::class)
385 $form->getItemByPostVar(
'document')->getRequired(),
386 'Failed asserting document upload is not required for existing documents' 395 $expectedSorting = 10;
398 ->getMockBuilder(ilTermsOfServiceDocument::class)
399 ->disableOriginalConstructor()
400 ->setMethods([
'fetchAllCriterionAssignments'])
403 $document->setId(4711);
404 $document->setTitle(
'phpunit');
405 $document->setSorting($expectedSorting);
408 ->getMockBuilder(ilHtmlPurifierInterface::class)
412 ->getMockBuilder(ilObjUser::class)
413 ->disableOriginalConstructor()
414 ->setMethods([
'getId'])
418 ->expects($this->once())
423 ->getMockBuilder(Filesystem::class)
427 ->getMockBuilder(FileUpload::class)
441 ->expects($this->any())
442 ->method(
'hasUploads')
447 $documentConnector = $this->getMockBuilder(arConnector::class)->getMock();
452 $form = $this->getMockBuilder(ilTermsOfServiceDocumentFormGUI::class)
453 ->setConstructorArgs([
464 ->setMethods([
'checkInput'])
468 ->expects($this->once())
469 ->method(
'checkInput')
473 'title' =>
'phpunit',
477 $form->setCheckInputCalled(
true);
479 $this->assertTrue($form->saveObject());
480 $this->assertFalse($form->hasTranslatedError());
481 $this->assertEmpty($form->getTranslatedError());
484 $document->getSorting(),
485 'Failed asserting that the sorting of the existing document has not been changed' 497 ->expects($this->any())
499 ->willReturn(
'translation');
504 ->getMockBuilder(ilTermsOfServiceDocument::class)
505 ->disableOriginalConstructor()
506 ->setMethods([
'getId',
'fetchAllCriterionAssignments'])
510 ->getMockBuilder(ilHtmlPurifierInterface::class)
514 ->getMockBuilder(ilObjUser::class)
515 ->disableOriginalConstructor()
520 ->getMockBuilder(FileUpload::class)
534 ->expects($this->exactly(3))
535 ->method(
'hasUploads')
539 ->expects($this->exactly(3))
540 ->method(
'hasBeenProcessed')
544 ->expects($this->exactly(3))
551 $this->getMockBuilder(ImmutableStringMap::class)->getMock(),
560 $this->getMockBuilder(ImmutableStringMap::class)->getMock(),
566 ->expects($this->exactly(3))
567 ->method(
'getResults')
568 ->willReturnOnConsecutiveCalls(
570 [0 => $uploadFailingResult],
575 ->getMockBuilder(Filesystem::class)
579 ->expects($this->once())
581 ->with(
'/agreements/' . $uploadResult->getName())
586 $documentConnector = $this->getMockBuilder(arConnector::class)->getMock();
591 $form = $this->getMockBuilder(ilTermsOfServiceDocumentFormGUI::class)
592 ->setConstructorArgs([
603 ->setMethods([
'checkInput'])
607 ->expects($this->once())
608 ->method(
'checkInput')
616 $form->setCheckInputCalled(
true);
618 $this->assertFalse($form->saveObject());
619 $this->assertTrue($form->hasTranslatedError());
620 $this->assertNotEmpty($form->getTranslatedError());
622 $form = $this->getMockBuilder(ilTermsOfServiceDocumentFormGUI::class)
623 ->setConstructorArgs([
634 ->setMethods([
'checkInput'])
638 ->expects($this->once())
639 ->method(
'checkInput')
642 $form->setCheckInputCalled(
true);
644 $this->assertFalse($form->saveObject());
645 $this->assertTrue($form->hasTranslatedError());
646 $this->assertNotEmpty($form->getTranslatedError());
648 $form = $this->getMockBuilder(ilTermsOfServiceDocumentFormGUI::class)
649 ->setConstructorArgs([
660 ->setMethods([
'checkInput'])
664 ->expects($this->once())
665 ->method(
'checkInput')
668 $form->setCheckInputCalled(
true);
670 $this->assertFalse($form->saveObject());
671 $this->assertTrue($form->hasTranslatedError());
672 $this->assertNotEmpty($form->getTranslatedError());
setGlobalVariable(string $name, $value)
static register(ActiveRecord $ar, arConnector $connector)
Class ilTermsOfServiceDocumentCriterionAssignment.
Class ilTermsOfServiceBaseTest.
Class ilTermsOfServiceDocument.