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)
45 $form = new \ilTermsOfServiceDocumentFormGUI(
57 $this->assertTrue(
$form->getItemByPostVar(
'document')->getRequired(),
'Failed asserting document upload is required for new documents');
59 $this->assertCount(2,
$form->getCommandButtons(),
'Failed asserting save and cancel buttons are given if form is editable');
60 $this->assertArrayHasKey(0,
$form->getCommandButtons(),
'Failed asserting save and cancel buttons are given if form is editable');
61 $this->assertArrayHasKey(1,
$form->getCommandButtons(),
'Failed asserting save and cancel buttons are given if form is editable');
62 $this->assertEquals(
'save',
$form->getCommandButtons()[0][
'cmd'],
'Failed asserting save and cancel buttons are given if form is editable');
63 $this->assertEquals(
'cancel',
$form->getCommandButtons()[1][
'cmd'],
'Failed asserting save and cancel buttons are given if form is editable');
65 $form = new \ilTermsOfServiceDocumentFormGUI(
77 $this->assertCount(1, $form->getCommandButtons(),
'Failed asserting only cancel button is given if form is not editable');
78 $this->assertArrayHasKey(0, $form->getCommandButtons(),
'Failed asserting only cancel button is given if form is not editable');
79 $this->assertEquals(
'cancel', $form->getCommandButtons()[0][
'cmd'],
'Failed asserting only cancel button is given if form is not editable');
88 ->getMockBuilder(\ilTermsOfServiceDocument::class)
89 ->disableOriginalConstructor()
90 ->setMethods([
'getId',
'fetchAllCriterionAssignments'])
94 ->expects($this->any())
95 ->method(
'fetchAllCriterionAssignments');
98 ->getMockBuilder(\ilHtmlPurifierInterface::class)
105 $this->getMockBuilder(ImmutableStringMap::class)->getMock(),
111 ->getMockBuilder(\ilObjUser::class)
112 ->disableOriginalConstructor()
113 ->setMethods([
'getId'])
117 ->expects($this->exactly(2))
122 ->getMockBuilder(Filesystem::class)
126 ->expects($this->exactly(2))
128 ->with(
'/agreements/' . $uploadResult->getName())
132 ->expects($this->exactly(2))
134 ->with(
'/agreements/' . $uploadResult->getName())
135 ->willReturn(
'phpunit');
138 ->expects($this->atLeast(1))
141 ->willReturnArgument(0);
144 ->expects($this->exactly(2))
146 ->with(
'/agreements/' . $uploadResult->getName());
149 ->getMockBuilder(FileUpload::class)
150 ->setMethods([
'moveFilesTo',
'uploadSizeLimit',
'register',
'hasBeenProcessed',
'hasUploads',
'process',
'getResults',
'moveOneFileTo'])
154 ->expects($this->any())
155 ->method(
'hasUploads')
159 ->expects($this->exactly(2))
160 ->method(
'hasBeenProcessed')
164 ->expects($this->exactly(2))
168 ->expects($this->exactly(2))
169 ->method(
'getResults')
175 ->expects($this->exactly(2))
176 ->method(
'moveOneFileTo')
187 $documentConnector = $this->getMockBuilder(\arConnector::class)->getMock();
188 $criterionConnector = $this->getMockBuilder(\arConnector::class)->getMock();
190 $expectedSortingValueExistingDocuments = 10;
193 ->expects($this->
once())
195 ->willReturnCallback(
function () use ($expectedSortingValueExistingDocuments) {
198 'title' =>
'another',
199 'sorting' => $expectedSortingValueExistingDocuments - 1,
204 ->expects($this->
once())
212 $form = $this->getMockBuilder(\ilTermsOfServiceDocumentFormGUI::class)
213 ->setConstructorArgs([
214 $document, $purifier,
$user, $fs, $fu,
215 'action',
'save',
'cancel',
218 ->setMethods([
'checkInput'])
222 ->expects($this->
once())
223 ->method(
'checkInput')
226 $_FILES[
'document'] = [];
228 'title' =>
'phpunit',
232 $form->setCheckInputCalled(
true);
234 $this->assertTrue(
$form->saveObject());
235 $this->assertFalse(
$form->hasTranslatedError());
236 $this->assertEmpty(
$form->getTranslatedError());
238 $expectedSortingValueExistingDocuments,
239 $document->getSorting(),
240 'Failed asserting that the sorting of the new document equals the maximum incremented by one when other documents exist' 243 $documentConnector = $this->getMockBuilder(\arConnector::class)->getMock();
246 ->expects($this->
once())
248 ->willReturnCallback(
function () {
254 $form = $this->getMockBuilder(\ilTermsOfServiceDocumentFormGUI::class)
255 ->setConstructorArgs([
256 $document, $purifier,
$user, $fs, $fu,
257 'action',
'save',
'cancel',
260 ->setMethods([
'checkInput'])
264 ->expects($this->
once())
265 ->method(
'checkInput')
268 $form->setCheckInputCalled(
true);
270 $this->assertTrue(
$form->saveObject());
271 $this->assertFalse(
$form->hasTranslatedError());
272 $this->assertEmpty(
$form->getTranslatedError());
275 $document->getSorting(),
276 'Failed asserting that the sorting of the new document equals 1 when no other document exists' 286 ->getMockBuilder(\ilTermsOfServiceDocument::class)
287 ->disableOriginalConstructor()
288 ->setMethods([
'getId'])
292 ->expects($this->any())
297 ->getMockBuilder(\ilHtmlPurifierInterface::class)
301 ->getMockBuilder(\ilObjUser::class)
302 ->disableOriginalConstructor()
303 ->setMethods([
'getId'])
307 ->getMockBuilder(Filesystem::class)
311 ->getMockBuilder(FileUpload::class)
314 $form = new \ilTermsOfServiceDocumentFormGUI(
326 $this->assertFalse(
$form->getItemByPostVar(
'document')->getRequired(),
'Failed asserting document upload is not required for existing documents');
334 $expectedSorting = 10;
337 ->getMockBuilder(\ilTermsOfServiceDocument::class)
338 ->disableOriginalConstructor()
339 ->setMethods([
'fetchAllCriterionAssignments'])
342 $document->setId(4711);
343 $document->setTitle(
'phpunit');
344 $document->setSorting($expectedSorting);
347 ->getMockBuilder(\ilHtmlPurifierInterface::class)
351 ->getMockBuilder(\ilObjUser::class)
352 ->disableOriginalConstructor()
353 ->setMethods([
'getId'])
357 ->expects($this->
once())
362 ->getMockBuilder(Filesystem::class)
366 ->getMockBuilder(FileUpload::class)
367 ->setMethods([
'moveFilesTo',
'uploadSizeLimit',
'register',
'hasBeenProcessed',
'hasUploads',
'process',
'getResults',
'moveOneFileTo'])
371 ->expects($this->any())
372 ->method(
'hasUploads')
377 $documentConnector = $this->getMockBuilder(\arConnector::class)->getMock();
382 $form = $this->getMockBuilder(\ilTermsOfServiceDocumentFormGUI::class)
383 ->setConstructorArgs([
384 $document, $purifier,
$user, $fs, $fu,
385 'action',
'save',
'cancel',
388 ->setMethods([
'checkInput'])
392 ->expects($this->
once())
393 ->method(
'checkInput')
397 'title' =>
'phpunit',
401 $form->setCheckInputCalled(
true);
403 $this->assertTrue(
$form->saveObject());
404 $this->assertFalse(
$form->hasTranslatedError());
405 $this->assertEmpty(
$form->getTranslatedError());
408 $document->getSorting(),
409 'Failed asserting that the sorting of the existing document has not been changed' 421 ->expects($this->any())
423 ->willReturn(
'translation');
428 ->getMockBuilder(\ilTermsOfServiceDocument::class)
429 ->disableOriginalConstructor()
430 ->setMethods([
'getId',
'fetchAllCriterionAssignments'])
434 ->getMockBuilder(\ilHtmlPurifierInterface::class)
438 ->getMockBuilder(\ilObjUser::class)
439 ->disableOriginalConstructor()
444 ->getMockBuilder(FileUpload::class)
445 ->setMethods([
'moveFilesTo',
'uploadSizeLimit',
'register',
'hasBeenProcessed',
'hasUploads',
'process',
'getResults',
'moveOneFileTo'])
449 ->expects($this->exactly(3))
450 ->method(
'hasUploads')
454 ->expects($this->exactly(3))
455 ->method(
'hasBeenProcessed')
459 ->expects($this->exactly(3))
466 $this->getMockBuilder(ImmutableStringMap::class)->getMock(),
475 $this->getMockBuilder(ImmutableStringMap::class)->getMock(),
481 ->expects($this->exactly(3))
482 ->method(
'getResults')
483 ->willReturnOnConsecutiveCalls(
485 [0 => $uploadFailingResult],
490 ->getMockBuilder(Filesystem::class)
494 ->expects($this->
once())
496 ->with(
'/agreements/' . $uploadResult->getName())
501 $documentConnector = $this->getMockBuilder(\arConnector::class)->getMock();
506 $form = $this->getMockBuilder(\ilTermsOfServiceDocumentFormGUI::class)
507 ->setConstructorArgs([
508 $document, $purifier,
$user, $fs, $fu,
509 'action',
'save',
'cancel',
512 ->setMethods([
'checkInput'])
516 ->expects($this->
once())
517 ->method(
'checkInput')
525 $form->setCheckInputCalled(
true);
527 $this->assertFalse(
$form->saveObject());
528 $this->assertTrue(
$form->hasTranslatedError());
529 $this->assertNotEmpty(
$form->getTranslatedError());
531 $form = $this->getMockBuilder(\ilTermsOfServiceDocumentFormGUI::class)
532 ->setConstructorArgs([
533 $document, $purifier,
$user, $fs, $fu,
534 'action',
'save',
'cancel',
537 ->setMethods([
'checkInput'])
541 ->expects($this->
once())
542 ->method(
'checkInput')
545 $form->setCheckInputCalled(
true);
547 $this->assertFalse($form->saveObject());
548 $this->assertTrue($form->hasTranslatedError());
549 $this->assertNotEmpty($form->getTranslatedError());
551 $form = $this->getMockBuilder(\ilTermsOfServiceDocumentFormGUI::class)
552 ->setConstructorArgs([
553 $document, $purifier,
$user, $fs, $fu,
554 'action',
'save',
'cancel',
557 ->setMethods([
'checkInput'])
561 ->expects($this->
once())
562 ->method(
'checkInput')
565 $form->setCheckInputCalled(
true);
567 $this->assertFalse($form->saveObject());
568 $this->assertTrue($form->hasTranslatedError());
569 $this->assertNotEmpty($form->getTranslatedError());
setGlobalVariable(string $name, $value)
static register(ActiveRecord $ar, arConnector $connector)
Class ilTermsOfServiceDocumentCriterionAssignment.
Class ilTermsOfServiceBaseTest.
if(isset($_POST['submit'])) $form
Class ilTermsOfServiceDocument.
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.