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(ilObjectCustomIconFactory::class);
    69         $DIC[
'learning_object_metadata'] = $this->createMock(LOMServices::class);
    83         $object = $this->createMock(ilObjFolder::class);
    84         $object->expects($this->once())->method(
'getTitle')->willReturn(
'Some random Title');
    86         $user = $this->createStub(ilObjUser::class);
    87         $request = $this->createStub(RequestInterface::class);
    88         $dav_factory = $this->createStub(ilWebDAVObjFactory::class);
    89         $repository_helper = $this->createStub(ilWebDAVRepositoryHelper::class);
    91         $dav_container = 
new ilDAVContainer($object, $user, $request, $dav_factory, $repository_helper);
    93         $this->assertEquals(
'Some random Title', $dav_container->getName());
   100                 'name' => 
'Second Fourth Child',
   101                 'class' => ilDAVContainer::class,
   102                 'expects_objects' => 7
   105                 'name' => 
'Last Last Child',
   106                 'class' => ilDAVFile::class,
   107                 'expects_objects' => 4
   111         foreach ($ref_ids as 
$ref_id => $additional_information) {
   114                 $additional_information[
'expects_objects']
   116             $object = $dav_container->getChild($additional_information[
'name']);
   117             $this->assertInstanceOf($additional_information[
'class'], $object);
   118             $this->assertEquals($additional_information[
'name'], $object->getName());
   126         $tree = $webdav_test_helper->getTree();
   128         foreach ($tree[
$ref_id][
'children'] as $child_ref) {
   134                 $dav_container->getChild($tree[$child_ref][
'title']);
   135                 $this->assertFalse(
'This should never happen');
   136             } 
catch (NotFound 
$e) {
   137                 $this->assertEquals($tree[$child_ref][
'title'] . 
' not found', $e->getMessage());
   147                 'name' => 
'Second Third Child',
   148                 'expects_objects' => 7
   151                 'name' => 
'Last Third Child',
   152                 'expects_objects' => 4
   156         foreach ($ref_ids as 
$ref_id => $additional_information) {
   160                     $additional_information[
'expects_objects']
   162                 $dav_container->getChild($additional_information[
'name']);
   163                 $this->assertFalse(
'This should not happen');
   164             } 
catch (NotFound 
$e) {
   165                 $this->assertEquals($additional_information[
'name'] . 
' not found', $e->getMessage());
   173         $name = 
'None existent name';
   180             $dav_container->getChild($name);
   181             $this->assertFalse(
'This should not happen');
   182         } 
catch (NotFound 
$e) {
   183             $this->assertEquals(
"$name not found", $e->getMessage());
   191                 'name' => 
'Second Last Child',
   192                 'expects_objects' => 7
   195                 'name' => 
'Last Second Child',
   196                 'expects_objects' => 4
   200         foreach ($ref_ids as 
$ref_id => $additional_information) {
   204                     $additional_information[
'expects_objects']
   206                 $dav_container->getChild($additional_information[
'name']);
   207                 $this->assertFalse(
'This should not happen');
   208             } 
catch (NotFound 
$e) {
   209                 $this->assertEquals($additional_information[
'name'] . 
' not found', $e->getMessage());
   217         $additional_information = [
   218             'names' => [
'Last First Child', 
'Last Last Child'],
   219             'classes' => [ilDAVContainer::class, ilDAVFile::class],
   220             'ref_id' => [
'233563432', 
'2335634323356343'],
   221             'expects_objects' => 4,
   222             'expects_problem_info_file' => 0
   231         $additional_information = [
   232             'names' => [
'Second First Child', 
'Second Second Child', 
'Second Fourth Child', 
'Problem Info File'],
   233             'classes' => [ilDAVFile::class, ilDAVFile::class, ilDAVContainer::class, ilDAVProblemInfoFile::class],
   234             'ref_id' => [
'72', 
'78', 
'7221', 
'7222'],
   235             'expects_objects' => 7,
   236             'expects_problem_info_file' => 1,
   249             $additional_information[
'expects_objects'],
   250             $additional_information[
'expects_problem_info_file']
   252         $children = $dav_container->getChildren();
   253         $this->assertEquals(count($additional_information[
'names']), count($children));
   254         for ($i = 0, $i_max = count($children); $i < $i_max; $i++) {
   255             $this->assertInstanceOf(
   256                 $additional_information[
'classes'][$i],
   257                 $children[$additional_information[
'ref_id'][$i]]
   260                 $additional_information[
'names'][$i],
   261                 $children[$additional_information[
'ref_id'][$i]]->getName()
   275         $children = $dav_container->getChildren();
   276         $this->assertEquals(1, count($children));
   283                 'name' => 
'Second Fourth Child',
   284                 'expects_objects' => 6
   287                 'name' => 
'Last Last Child',
   288                 'expects_objects' => 4
   292         foreach ($ref_ids as 
$ref_id => $additional_information) {
   295                 $additional_information[
'expects_objects']
   297             $this->assertTrue($dav_container->childExists($additional_information[
'name']));
   304         $additional_information = [
   305             'name' => 
'Second Second Child',
   306             'expects_objects' => 4
   311             $additional_information[
'expects_objects']
   313         $this->assertTrue($dav_container->childExists($additional_information[
'name']));
   320         $tree = $webdav_test_helper->getTree();
   322         foreach ($tree[
$ref_id][
'children'] as $child_ref) {
   327             $this->assertFalse($dav_container->childExists($tree[$child_ref][
'title']));
   335                 'name' => 
'Second Third Child',
   336                 'expects_objects' => 7
   339                 'name' => 
'Last Third Child',
   340                 'expects_objects' => 4
   344         foreach ($ref_ids as 
$ref_id => $additional_information) {
   347                 $additional_information[
'expects_objects']
   349             $this->assertFalse($dav_container->childExists($additional_information[
'name']));
   356         $name = 
'None existent name';
   363         $this->assertFalse($dav_container->childExists($name));
   370                 'name' => 
'Second Last Child',
   371                 'expects_objects' => 7
   374                 'name' => 
'Last Second Child',
   375                 'expects_objects' => 4
   379         foreach ($ref_ids as 
$ref_id => $additional_information) {
   382                 $additional_information[
'expects_objects']
   385             $this->assertFalse($dav_container->childExists($additional_information[
'name']));
   391         $parent_ref = 233563432;
   396             $dav_container->setName(
'My Valid Name');
   397             $this->assertFalse(
'This should not happen!');
   398         } 
catch (Forbidden 
$e) {
   399             $this->assertEquals(
'Permission denied', $e->getMessage());
   407         $tree = $webdav_test_helper->getTree();
   409         foreach ($tree[
'22'][
'children'] as $invalid_object) {
   413                 $dav_container->setName($tree[$invalid_object][
'title']);
   414                 $this->assertFalse(
'This should not happen!');
   415             } 
catch (Forbidden 
$e) {
   416                 $this->assertEquals(
'Forbidden characters in title', $e->getMessage());
   423         $parent_ref = 233563432;
   428             $dav_container->createFile(
'My New File.txt');
   429             $this->assertFalse(
'This should not happen!');
   430         } 
catch (Forbidden 
$e) {
   431             $this->assertEquals(
'Permission denied', $e->getMessage());
   437         $parent_ref = 233563432;
   442             $dav_container->createDirectory(
'My New Folder');
   443             $this->assertFalse(
'This should not happen!');
   444         } 
catch (Forbidden 
$e) {
   445             $this->assertEquals(
'Permission denied', $e->getMessage());
   455         define(
'ILIAS_LOG_ENABLED', 
false);
   458         $tree = $webdav_test_helper->getTree();
   460         foreach ($tree[
'22'][
'children'] as $invalid_object) {
   464                 $dav_container->createDirectory($tree[$invalid_object][
'title']);
   465                 $this->assertFalse(
'This should not happen!');
   466             } 
catch (Forbidden 
$e) {
   467                 $this->assertEquals(
'Forbidden characters in title', $e->getMessage());
   474         $parent_ref = 233563432;
   479             $dav_container->delete();
   480             $this->assertFalse(
'This should not happen!');
   481         } 
catch (Forbidden 
$e) {
   482             $this->assertEquals(
'Permission denied', $e->getMessage());
   489         int $expects_problem_info_file = 0,
   490         int $expects_child_ref = 1,
   491         bool $for_create = 
false   494         $object_folder->setRefId($object_ref_id);
   495         $user = $this->createStub(ilObjUser::class);
   496         $request = $this->createStub(RequestInterface::class);
   499         $tree = $webdav_test_helper->getTree();
   501         $mocked_dav_factory = $this->createPartialMock(
   502             ilWebDAVObjFactory::class,
   503             [
'retrieveDAVObjectByRefID', 
'getProblemInfoFile']
   505         $mocked_dav_factory->expects($this->exactly($expects_object))
   506                            ->method(
'retrieveDAVObjectByRefID')->willReturnCallback(
   508                                    if ($tree[$ref_id][
'access'] === 
'none') {
   509                                        throw new Forbidden(
"No read permission for object with reference ID $ref_id");
   512                                    if ($tree[$ref_id][
'type'] === 
'fold') {
   513                                        $obj_class = ilDAVContainer::class;
   514                                    } elseif ($tree[$ref_id][
'type'] === 
'file') {
   515                                        $obj_class = ilDAVFile::class;
   520                                    if ($this->hasTitleForbiddenChars($tree[$ref_id][
'title'])) {
   524                                    if ($this->isHiddenFile($tree[$ref_id][
'title'])) {
   528                                    $object = $this->createMock($obj_class);
   529                                    $object->expects($this->atMost(3))->method(
'getName')->willReturn($tree[$ref_id][
'title']);
   533         $mocked_dav_factory->expects($this->exactly($expects_problem_info_file))
   534                            ->method(
'getProblemInfoFile')->willReturnCallback(
   536                                    $problem_info_file = $this->createMock(ilDAVProblemInfoFile::class);
   537                                    $problem_info_file->expects($this->atMost(2))->method(
'getName')->willReturn(
'Problem Info File');
   538                                    return $problem_info_file;
   542         $mocked_repo_helper = $this->createPartialMock(
   543             ilWebDAVRepositoryHelper::class,
   544             [
'getChildrenOfRefId', 
'checkcreateAccessForType', 
'checkAccess']
   546         $mocked_repo_helper->expects($this->exactly($expects_child_ref))
   547                            ->method(
'getChildrenOfRefId')->willReturnCallback(
   548                                fn(
int $parent_ref): array => $tree[$parent_ref][
'children']
   550         $mocked_repo_helper->expects($this->atMost(1))
   551                            ->method(
'checkcreateAccessForType')->willReturnCallback(
   552                                fn($parent_ref, $type): 
bool => $tree[$parent_ref][
'access'] === 
'write'   554         $mocked_repo_helper->expects($this->atMost(1))
   555                            ->method(
'checkAccess')->willReturnCallback(
   556                                fn(
string $permission, 
int $ref_id): 
bool => in_array(
   559                                ) && $tree[$ref_id][
'access'] === 
'write'   564             $object_child->setType(
'fold');
   572             $dav_container->setChildcollection($object_child);
   573             return $dav_container;
   576         return new ilDAVContainer($object_folder, $user, $request, $mocked_dav_factory, $mocked_repo_helper);
 const OBJECT_TYPE_NOT_DAVABLE
 
const OBJECT_TITLE_NOT_DAVABLE
 
testGetChilrendWithExistingNameOfFolderOrFileReturnsArrayOfObjects()
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
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()
 
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()
disabled 
 
testChildExistsWithExistingNameOfOtherObjectTypeReturnsFalse()
 
testGetChildrenFromFolderWithOnlyNonDavableNamedContentReturnsEmptyArray()
 
testSetNameWithoutPermissionsThrowsForbiddenError()
 
testDeleteWithoutPermissionsThrowsForbiddenError()
 
testGetChilrendWithExistingNameOfFolderOrFileReturnsArrayWithProblemInfoFile()