19 declare(strict_types=1);
33 require_once
"./components/ILIAS/WebDAV/tests/webdav_overrides.php";
34 require_once
"./components/ILIAS/WebDAV/tests/ilWebDAVTestHelper.php";
42 protected function setUp(): void
47 $this->dic = is_object($DIC) ? clone
$DIC :
$DIC;
50 $DIC[
'tree'] = $this->createMock(ilTree::class);
51 $DIC[
'lng'] = $this->createMock(ilLanguage::class);
52 $DIC[
'http'] = $this->createMock(Services::class);
53 $DIC[
'rbacsystem'] = $this->createMock(ilRbacSystem::class);
54 $DIC[
'rbacreview'] = $this->createMock(ilRbacReview::class);
55 $DIC[
'ilAccess'] = $this->createMock(ilAccess::class);
56 $DIC[
'ilDB'] = $this->createMock(ilDBInterface::class);
57 $DIC[
'ilLog'] = $this->createMock(ilLogger::class);
58 $DIC[
'ilErr'] = $this->createMock(ilErrorHandling::class);
59 $DIC[
'ilUser'] = $this->createMock(ilObjUser::class);
60 $DIC[
'objDefinition'] = $this->createMock(ilObjectDefinition::class);
61 $DIC[
'ilSetting'] = $this->createMock(ilSetting::class);
62 $DIC[
'ilias'] = $this->createMock(ILIAS::class);
63 $DIC[
'ilAppEventHandler'] = $this->createMock(ilAppEventHandler::class);
64 $DIC[
'filesystem'] = $this->createMock(Filesystems::class);
65 $DIC[
'upload'] = $this->createMock(FileUpload::class);
67 $DIC[
'refinery'] = $this->createMock(Factory::class);
68 $DIC[
'object.customicons.factory'] = $this->createMock(
ILIAS\ILIASObject\Properties\AdditionalProperties\
Icon\Factory::class);
69 $DIC[
'learning_object_metadata'] = $this->createMock(LOMServices::class);
84 $object = $this->createMock(ilObjFolder::class);
85 $object->expects($this->once())->method(
'getTitle')->willReturn(
'Some random Title');
87 $user = $this->createStub(ilObjUser::class);
88 $request = $this->createStub(RequestInterface::class);
89 $dav_factory = $this->createStub(ilWebDAVObjFactory::class);
90 $repository_helper = $this->createStub(ilWebDAVRepositoryHelper::class);
92 $dav_container =
new ilDAVContainer($object, $user, $request, $dav_factory, $repository_helper);
94 $this->assertEquals(
'Some random Title', $dav_container->getName());
101 'name' =>
'Second Fourth Child',
102 'class' => ilDAVContainer::class,
103 'expects_objects' => 7
106 'name' =>
'Last Last Child',
107 'class' => ilDAVFile::class,
108 'expects_objects' => 4
112 foreach ($ref_ids as
$ref_id => $additional_information) {
115 $additional_information[
'expects_objects']
117 $object = $dav_container->getChild($additional_information[
'name']);
118 $this->assertInstanceOf($additional_information[
'class'], $object);
119 $this->assertEquals($additional_information[
'name'], $object->getName());
127 $tree = $webdav_test_helper->getTree();
129 foreach ($tree[
$ref_id][
'children'] as $child_ref) {
135 $dav_container->getChild($tree[$child_ref][
'title']);
136 $this->assertFalse(
'This should never happen');
137 }
catch (NotFound
$e) {
138 $this->assertEquals($tree[$child_ref][
'title'] .
' not found', $e->getMessage());
148 'name' =>
'Second Third Child',
149 'expects_objects' => 7
152 'name' =>
'Last Third Child',
153 'expects_objects' => 4
157 foreach ($ref_ids as
$ref_id => $additional_information) {
161 $additional_information[
'expects_objects']
163 $dav_container->getChild($additional_information[
'name']);
164 $this->assertFalse(
'This should not happen');
165 }
catch (NotFound
$e) {
166 $this->assertEquals($additional_information[
'name'] .
' not found', $e->getMessage());
174 $name =
'None existent name';
181 $dav_container->getChild($name);
182 $this->assertFalse(
'This should not happen');
183 }
catch (NotFound
$e) {
184 $this->assertEquals(
"$name not found", $e->getMessage());
192 'name' =>
'Second Last Child',
193 'expects_objects' => 7
196 'name' =>
'Last Second Child',
197 'expects_objects' => 4
201 foreach ($ref_ids as
$ref_id => $additional_information) {
205 $additional_information[
'expects_objects']
207 $dav_container->getChild($additional_information[
'name']);
208 $this->assertFalse(
'This should not happen');
209 }
catch (NotFound
$e) {
210 $this->assertEquals($additional_information[
'name'] .
' not found', $e->getMessage());
218 $additional_information = [
219 'names' => [
'Last First Child',
'Last Last Child'],
220 'classes' => [ilDAVContainer::class, ilDAVFile::class],
221 'ref_id' => [
'233563432',
'2335634323356343'],
222 'expects_objects' => 4,
223 'expects_problem_info_file' => 0
232 $additional_information = [
233 'names' => [
'Second First Child',
'Second Second Child',
'Second Fourth Child',
'Problem Info File'],
234 'classes' => [ilDAVFile::class, ilDAVFile::class, ilDAVContainer::class, ilDAVProblemInfoFile::class],
235 'ref_id' => [
'72',
'78',
'7221',
'7222'],
236 'expects_objects' => 7,
237 'expects_problem_info_file' => 1,
250 $additional_information[
'expects_objects'],
251 $additional_information[
'expects_problem_info_file']
253 $children = $dav_container->getChildren();
254 $this->assertEquals(count($additional_information[
'names']), count($children));
255 for ($i = 0, $i_max = count($children); $i < $i_max; $i++) {
256 $this->assertInstanceOf(
257 $additional_information[
'classes'][$i],
258 $children[$additional_information[
'ref_id'][$i]]
261 $additional_information[
'names'][$i],
262 $children[$additional_information[
'ref_id'][$i]]->getName()
276 $children = $dav_container->getChildren();
277 $this->assertEquals(1, count($children));
284 'name' =>
'Second Fourth Child',
285 'expects_objects' => 6
288 'name' =>
'Last Last Child',
289 'expects_objects' => 4
293 foreach ($ref_ids as
$ref_id => $additional_information) {
296 $additional_information[
'expects_objects']
298 $this->assertTrue($dav_container->childExists($additional_information[
'name']));
305 $additional_information = [
306 'name' =>
'Second Second Child',
307 'expects_objects' => 4
312 $additional_information[
'expects_objects']
314 $this->assertTrue($dav_container->childExists($additional_information[
'name']));
321 $tree = $webdav_test_helper->getTree();
323 foreach ($tree[
$ref_id][
'children'] as $child_ref) {
328 $this->assertFalse($dav_container->childExists($tree[$child_ref][
'title']));
336 'name' =>
'Second Third Child',
337 'expects_objects' => 7
340 'name' =>
'Last Third Child',
341 'expects_objects' => 4
345 foreach ($ref_ids as
$ref_id => $additional_information) {
348 $additional_information[
'expects_objects']
350 $this->assertFalse($dav_container->childExists($additional_information[
'name']));
357 $name =
'None existent name';
364 $this->assertFalse($dav_container->childExists($name));
371 'name' =>
'Second Last Child',
372 'expects_objects' => 7
375 'name' =>
'Last Second Child',
376 'expects_objects' => 4
380 foreach ($ref_ids as
$ref_id => $additional_information) {
383 $additional_information[
'expects_objects']
386 $this->assertFalse($dav_container->childExists($additional_information[
'name']));
392 $parent_ref = 233563432;
397 $dav_container->setName(
'My Valid Name');
398 $this->assertFalse(
'This should not happen!');
399 }
catch (Forbidden
$e) {
400 $this->assertEquals(
'Permission denied', $e->getMessage());
408 $tree = $webdav_test_helper->getTree();
410 foreach ($tree[
'22'][
'children'] as $invalid_object) {
414 $dav_container->setName($tree[$invalid_object][
'title']);
415 $this->assertFalse(
'This should not happen!');
416 }
catch (Forbidden
$e) {
417 $this->assertEquals(
'Forbidden characters in title', $e->getMessage());
424 $parent_ref = 233563432;
429 $dav_container->createFile(
'My New File.txt');
430 $this->assertFalse(
'This should not happen!');
431 }
catch (Forbidden
$e) {
432 $this->assertEquals(
'Permission denied', $e->getMessage());
438 $parent_ref = 233563432;
443 $dav_container->createDirectory(
'My New Folder');
444 $this->assertFalse(
'This should not happen!');
445 }
catch (Forbidden
$e) {
446 $this->assertEquals(
'Permission denied', $e->getMessage());
450 #[\PHPUnit\Framework\Attributes\PreserveGlobalState(false)] 451 #[\PHPUnit\Framework\Attributes\RunInSeparateProcess] 454 define(
'ILIAS_LOG_ENABLED',
false);
457 $tree = $webdav_test_helper->getTree();
459 foreach ($tree[
'22'][
'children'] as $invalid_object) {
463 $dav_container->createDirectory($tree[$invalid_object][
'title']);
464 $this->assertFalse(
'This should not happen!');
465 }
catch (Forbidden
$e) {
466 $this->assertEquals(
'Forbidden characters in title', $e->getMessage());
473 $parent_ref = 233563432;
478 $dav_container->delete();
479 $this->assertFalse(
'This should not happen!');
480 }
catch (Forbidden
$e) {
481 $this->assertEquals(
'Permission denied', $e->getMessage());
488 int $expects_problem_info_file = 0,
489 int $expects_child_ref = 1,
490 bool $for_create =
false 493 $object_folder->setRefId($object_ref_id);
494 $user = $this->createStub(ilObjUser::class);
495 $request = $this->createStub(RequestInterface::class);
498 $tree = $webdav_test_helper->getTree();
500 $mocked_dav_factory = $this->createPartialMock(
501 ilWebDAVObjFactory::class,
502 [
'retrieveDAVObjectByRefID',
'getProblemInfoFile']
504 $mocked_dav_factory->expects($this->exactly($expects_object))
505 ->method(
'retrieveDAVObjectByRefID')->willReturnCallback(
507 if ($tree[$ref_id][
'access'] ===
'none') {
508 throw new Forbidden(
"No read permission for object with reference ID $ref_id");
511 if ($tree[$ref_id][
'type'] ===
'fold') {
512 $obj_class = ilDAVContainer::class;
513 } elseif ($tree[$ref_id][
'type'] ===
'file') {
514 $obj_class = ilDAVFile::class;
519 if ($this->hasTitleForbiddenChars($tree[$ref_id][
'title'])) {
523 if ($this->isHiddenFile($tree[$ref_id][
'title'])) {
527 $object = $this->createMock($obj_class);
528 $object->expects($this->atMost(3))->method(
'getName')->willReturn($tree[$ref_id][
'title']);
532 $mocked_dav_factory->expects($this->exactly($expects_problem_info_file))
533 ->method(
'getProblemInfoFile')->willReturnCallback(
535 $problem_info_file = $this->createMock(ilDAVProblemInfoFile::class);
536 $problem_info_file->expects($this->atMost(2))->method(
'getName')->willReturn(
'Problem Info File');
537 return $problem_info_file;
541 $mocked_repo_helper = $this->createPartialMock(
542 ilWebDAVRepositoryHelper::class,
543 [
'getChildrenOfRefId',
'checkcreateAccessForType',
'checkAccess']
545 $mocked_repo_helper->expects($this->exactly($expects_child_ref))
546 ->method(
'getChildrenOfRefId')->willReturnCallback(
547 fn(
int $parent_ref): array => $tree[$parent_ref][
'children']
549 $mocked_repo_helper->expects($this->atMost(1))
550 ->method(
'checkcreateAccessForType')->willReturnCallback(
551 fn($parent_ref, $type):
bool => $tree[$parent_ref][
'access'] ===
'write' 553 $mocked_repo_helper->expects($this->atMost(1))
554 ->method(
'checkAccess')->willReturnCallback(
555 fn(
string $permission,
int $ref_id):
bool => in_array(
558 ) && $tree[$ref_id][
'access'] ===
'write' 563 $object_child->setType(
'fold');
571 $dav_container->setChildcollection($object_child);
572 return $dav_container;
575 return new ilDAVContainer($object_folder, $user, $request, $mocked_dav_factory, $mocked_repo_helper);
const OBJECT_TYPE_NOT_DAVABLE
const OBJECT_TITLE_NOT_DAVABLE
testGetChilrendWithExistingNameOfFolderOrFileReturnsArrayOfObjects()
testChildExistsWithExistingNonDavableNameReturnsFalse()
getChildrenTest(int $ref_id, array $additional_information)
Interface Observer Contains several chained tasks and infos about them.
testChildExistsWithExistingNameOfFolderOrFileReturnsTrue()
testGetChildWithExistingNameOfFolderOrFileReturnsIlObject()
Customizing of pimple-DIC for ILIAS.
testChildExistsWithExistingNameOfFolderOrFileWithoutAccessReturnsFalse()
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
testGetChildWithExistingNonDavableNameThrowsNotFoundError()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getDAVContainerWithExpectationForFunctions(int $object_ref_id, int $expects_object, int $expects_problem_info_file=0, int $expects_child_ref=1, bool $for_create=false)
testChildExistsWithExistingNameOfFolderOrFileWhenOtherObjectOfSameNameExistsReturnsTrue()
testGetChildWithExistingNameOfOtherObjectTypeThrowsNotFoundError()
testGetChildWithNonExistentNameOfFolderOrFileThrowsNotFoundError()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
testGetChildWithExistingNameOfFolderOrFileWithoutAccessThrowsNotFoundError()
testSetNameWithNonDavableNameThrowsForbiddenError()
testCreateFileWithoutPermissionsThrowsForbiddenError()
testCreateDirectoryWithoutPermissionsThrowsForbiddenError()
testGetNameGetsObjectTitle()
testChildExistsWithNonExistentNameOfFolderOrFileReturnsFalse()
testCreateDirectoryWithNonDavableNameThrowsForbiddenError()
testChildExistsWithExistingNameOfOtherObjectTypeReturnsFalse()
testGetChildrenFromFolderWithOnlyNonDavableNamedContentReturnsEmptyArray()
testSetNameWithoutPermissionsThrowsForbiddenError()
testDeleteWithoutPermissionsThrowsForbiddenError()
testGetChilrendWithExistingNameOfFolderOrFileReturnsArrayWithProblemInfoFile()