19 declare(strict_types=1);
    32 require_once 
"./Services/WebDAV/test/webdav_overrides.php";
    33 require_once 
"./Services/WebDAV/test/ilWebDAVTestHelper.php";
    41     protected function setUp(): void
    46         $this->dic = is_object($DIC) ? clone 
$DIC : 
$DIC;
    49         $DIC[
'tree'] = $this->createMock(ilTree::class);
    50         $DIC[
'lng'] = $this->createMock(ilLanguage::class);
    51         $DIC[
'http'] = $this->createMock(Services::class);
    52         $DIC[
'rbacsystem'] = $this->createMock(ilRbacSystem::class);
    53         $DIC[
'rbacreview'] = $this->createMock(ilRbacReview::class);
    54         $DIC[
'ilAccess'] = $this->createMock(ilAccess::class);
    55         $DIC[
'ilDB'] = $this->createMock(ilDBInterface::class);
    56         $DIC[
'ilLog'] = $this->createMock(ilLogger::class);
    57         $DIC[
'ilErr'] = $this->createMock(ilErrorHandling::class);
    58         $DIC[
'ilUser'] = $this->createMock(ilObjUser::class);
    59         $DIC[
'objDefinition'] = $this->createMock(ilObjectDefinition::class);
    60         $DIC[
'ilSetting'] = $this->createMock(ilSetting::class);
    61         $DIC[
'ilias'] = $this->createMock(ILIAS::class);
    62         $DIC[
'ilAppEventHandler'] = $this->createMock(ilAppEventHandler::class);
    63         $DIC[
'filesystem'] = $this->createMock(Filesystems::class);
    64         $DIC[
'upload'] = $this->createMock(FileUpload::class);
    66         $DIC[
'refinery'] = $this->createMock(Factory::class);
    67         $DIC[
'object.customicons.factory'] = $this->createMock(ilObjectCustomIconFactory::class);
    81         $object = $this->createMock(ilObjFolder::class);
    82         $object->expects($this->once())->method(
'getTitle')->willReturn(
'Some random Title');
    84         $user = $this->createStub(ilObjUser::class);
    85         $request = $this->createStub(RequestInterface::class);
    86         $dav_factory = $this->createStub(ilWebDAVObjFactory::class);
    87         $repository_helper = $this->createStub(ilWebDAVRepositoryHelper::class);
    89         $dav_container = 
new ilDAVContainer($object, $user, $request, $dav_factory, $repository_helper);
    91         $this->assertEquals(
'Some random Title', $dav_container->getName());
    98                 'name' => 
'Second Fourth Child',
    99                 'class' => ilDAVContainer::class,
   100                 'expects_objects' => 7
   103                 'name' => 
'Last Last Child',
   104                 'class' => ilDAVFile::class,
   105                 'expects_objects' => 4
   109         foreach ($ref_ids as 
$ref_id => $additional_information) {
   112                 $additional_information[
'expects_objects']
   114             $object = $dav_container->getChild($additional_information[
'name']);
   115             $this->assertInstanceOf($additional_information[
'class'], $object);
   116             $this->assertEquals($additional_information[
'name'], $object->getName());
   124         $tree = $webdav_test_helper->getTree();
   126         foreach ($tree[
$ref_id][
'children'] as $child_ref) {
   132                 $dav_container->getChild($tree[$child_ref][
'title']);
   133                 $this->assertFalse(
'This should never happen');
   134             } 
catch (NotFound 
$e) {
   135                 $this->assertEquals($tree[$child_ref][
'title'] . 
' not found', $e->getMessage());
   145                 'name' => 
'Second Third Child',
   146                 'expects_objects' => 7
   149                 'name' => 
'Last Third Child',
   150                 'expects_objects' => 4
   154         foreach ($ref_ids as 
$ref_id => $additional_information) {
   158                     $additional_information[
'expects_objects']
   160                 $dav_container->getChild($additional_information[
'name']);
   161                 $this->assertFalse(
'This should not happen');
   162             } 
catch (NotFound 
$e) {
   163                 $this->assertEquals($additional_information[
'name'] . 
' not found', $e->getMessage());
   171         $name = 
'None existent name';
   178             $dav_container->getChild($name);
   179             $this->assertFalse(
'This should not happen');
   180         } 
catch (NotFound 
$e) {
   181             $this->assertEquals(
"$name not found", $e->getMessage());
   189                 'name' => 
'Second Last Child',
   190                 'expects_objects' => 7
   193                 'name' => 
'Last Second Child',
   194                 'expects_objects' => 4
   198         foreach ($ref_ids as 
$ref_id => $additional_information) {
   202                     $additional_information[
'expects_objects']
   204                 $dav_container->getChild($additional_information[
'name']);
   205                 $this->assertFalse(
'This should not happen');
   206             } 
catch (NotFound 
$e) {
   207                 $this->assertEquals($additional_information[
'name'] . 
' not found', $e->getMessage());
   215         $additional_information = [
   216             'names' => [
'Last First Child', 
'Last Last Child'],
   217             'classes' => [ilDAVContainer::class, ilDAVFile::class],
   218             'ref_id' => [
'233563432', 
'2335634323356343'],
   219             'expects_objects' => 4,
   220             'expects_problem_info_file' => 0
   229         $additional_information = [
   230             'names' => [
'Second First Child', 
'Second Second Child', 
'Second Fourth Child', 
'Problem Info File'],
   231             'classes' => [ilDAVFile::class, ilDAVFile::class, ilDAVContainer::class, ilDAVProblemInfoFile::class],
   232             'ref_id' => [
'72', 
'78', 
'7221', 
'7222'],
   233             'expects_objects' => 7,
   234             'expects_problem_info_file' => 1,
   247             $additional_information[
'expects_objects'],
   248             $additional_information[
'expects_problem_info_file']
   250         $children = $dav_container->getChildren();
   251         $this->assertEquals(count($additional_information[
'names']), count($children));
   252         for ($i = 0, $i_max = count($children); $i < $i_max; $i++) {
   253             $this->assertInstanceOf(
   254                 $additional_information[
'classes'][$i],
   255                 $children[$additional_information[
'ref_id'][$i]]
   258                 $additional_information[
'names'][$i],
   259                 $children[$additional_information[
'ref_id'][$i]]->getName()
   273         $children = $dav_container->getChildren();
   274         $this->assertEquals(1, count($children));
   281                 'name' => 
'Second Fourth Child',
   282                 'expects_objects' => 6
   285                 'name' => 
'Last Last Child',
   286                 'expects_objects' => 4
   290         foreach ($ref_ids as 
$ref_id => $additional_information) {
   293                 $additional_information[
'expects_objects']
   295             $this->assertTrue($dav_container->childExists($additional_information[
'name']));
   302         $additional_information = [
   303             'name' => 
'Second Second Child',
   304             'expects_objects' => 4
   309             $additional_information[
'expects_objects']
   311         $this->assertTrue($dav_container->childExists($additional_information[
'name']));
   318         $tree = $webdav_test_helper->getTree();
   320         foreach ($tree[
$ref_id][
'children'] as $child_ref) {
   325             $this->assertFalse($dav_container->childExists($tree[$child_ref][
'title']));
   333                 'name' => 
'Second Third Child',
   334                 'expects_objects' => 7
   337                 'name' => 
'Last Third Child',
   338                 'expects_objects' => 4
   342         foreach ($ref_ids as 
$ref_id => $additional_information) {
   345                 $additional_information[
'expects_objects']
   347             $this->assertFalse($dav_container->childExists($additional_information[
'name']));
   354         $name = 
'None existent name';
   361         $this->assertFalse($dav_container->childExists($name));
   368                 'name' => 
'Second Last Child',
   369                 'expects_objects' => 7
   372                 'name' => 
'Last Second Child',
   373                 'expects_objects' => 4
   377         foreach ($ref_ids as 
$ref_id => $additional_information) {
   380                 $additional_information[
'expects_objects']
   383             $this->assertFalse($dav_container->childExists($additional_information[
'name']));
   389         $parent_ref = 233563432;
   394             $dav_container->setName(
'My Valid Name');
   395             $this->assertFalse(
'This should not happen!');
   396         } 
catch (Forbidden 
$e) {
   397             $this->assertEquals(
'Permission denied', $e->getMessage());
   405         $tree = $webdav_test_helper->getTree();
   407         foreach ($tree[
'22'][
'children'] as $invalid_object) {
   411                 $dav_container->setName($tree[$invalid_object][
'title']);
   412                 $this->assertFalse(
'This should not happen!');
   413             } 
catch (Forbidden 
$e) {
   414                 $this->assertEquals(
'Forbidden characters in title', $e->getMessage());
   421         $parent_ref = 233563432;
   426             $dav_container->createFile(
'My New File.txt');
   427             $this->assertFalse(
'This should not happen!');
   428         } 
catch (Forbidden 
$e) {
   429             $this->assertEquals(
'Permission denied', $e->getMessage());
   435         $parent_ref = 233563432;
   440             $dav_container->createDirectory(
'My New Folder');
   441             $this->assertFalse(
'This should not happen!');
   442         } 
catch (Forbidden 
$e) {
   443             $this->assertEquals(
'Permission denied', $e->getMessage());
   453         define(
'ILIAS_LOG_ENABLED', 
false);
   456         $tree = $webdav_test_helper->getTree();
   458         foreach ($tree[
'22'][
'children'] as $invalid_object) {
   462                 $dav_container->createDirectory($tree[$invalid_object][
'title']);
   463                 $this->assertFalse(
'This should not happen!');
   464             } 
catch (Forbidden 
$e) {
   465                 $this->assertEquals(
'Forbidden characters in title', $e->getMessage());
   472         $parent_ref = 233563432;
   477             $dav_container->delete();
   478             $this->assertFalse(
'This should not happen!');
   479         } 
catch (Forbidden 
$e) {
   480             $this->assertEquals(
'Permission denied', $e->getMessage());
   487         int $expects_problem_info_file = 0,
   488         int $expects_child_ref = 1,
   489         bool $for_create = 
false   492         $object_folder->setRefId($object_ref_id);
   493         $user = $this->createStub(ilObjUser::class);
   494         $request = $this->createStub(RequestInterface::class);
   497         $tree = $webdav_test_helper->getTree();
   499         $mocked_dav_factory = $this->createPartialMock(
   500             ilWebDAVObjFactory::class,
   501             [
'retrieveDAVObjectByRefID', 
'getProblemInfoFile']
   503         $mocked_dav_factory->expects($this->exactly($expects_object))
   504                            ->method(
'retrieveDAVObjectByRefID')->willReturnCallback(
   506                                    if ($tree[$ref_id][
'access'] === 
'none') {
   507                                        throw new Forbidden(
"No read permission for object with reference ID $ref_id");
   510                                    if ($tree[$ref_id][
'type'] === 
'fold') {
   511                                        $obj_class = ilDAVContainer::class;
   512                                    } elseif ($tree[$ref_id][
'type'] === 
'file') {
   513                                        $obj_class = ilDAVFile::class;
   518                                    if ($this->hasTitleForbiddenChars($tree[$ref_id][
'title'])) {
   522                                    if ($this->isHiddenFile($tree[$ref_id][
'title'])) {
   526                                    $object = $this->createMock($obj_class);
   527                                    $object->expects($this->atMost(3))->method(
'getName')->willReturn($tree[$ref_id][
'title']);
   531         $mocked_dav_factory->expects($this->exactly($expects_problem_info_file))
   532                            ->method(
'getProblemInfoFile')->willReturnCallback(
   534                                    $problem_info_file = $this->createMock(ilDAVProblemInfoFile::class);
   535                                    $problem_info_file->expects($this->atMost(2))->method(
'getName')->willReturn(
'Problem Info File');
   536                                    return $problem_info_file;
   540         $mocked_repo_helper = $this->createPartialMock(
   541             ilWebDAVRepositoryHelper::class,
   542             [
'getChildrenOfRefId', 
'checkcreateAccessForType', 
'checkAccess']
   544         $mocked_repo_helper->expects($this->exactly($expects_child_ref))
   545                            ->method(
'getChildrenOfRefId')->willReturnCallback(
   546                                fn(
int $parent_ref): array => $tree[$parent_ref][
'children']
   548         $mocked_repo_helper->expects($this->atMost(1))
   549                            ->method(
'checkcreateAccessForType')->willReturnCallback(
   550                                fn($parent_ref, $type): 
bool => $tree[$parent_ref][
'access'] === 
'write'   552         $mocked_repo_helper->expects($this->atMost(1))
   553                            ->method(
'checkAccess')->willReturnCallback(
   554                                fn(
string $permission, 
int $ref_id): 
bool => in_array(
   557                                ) && $tree[$ref_id][
'access'] === 
'write'   562             $object_child->setType(
'fold');
   570             $dav_container->setChildcollection($object_child);
   571             return $dav_container;
   574         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)
 
Class ChatMainBarProvider . 
 
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...
 
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()
 
testGetChildWithExistingNameOfFolderOrFileWithoutAccessThrowsNotFoundError()
 
testSetNameWithNonDavableNameThrowsForbiddenError()
 
testCreateFileWithoutPermissionsThrowsForbiddenError()
 
testCreateDirectoryWithoutPermissionsThrowsForbiddenError()
 
testGetNameGetsObjectTitle()
 
testChildExistsWithNonExistentNameOfFolderOrFileReturnsFalse()
 
testCreateDirectoryWithNonDavableNameThrowsForbiddenError()
disabled 
 
testChildExistsWithExistingNameOfOtherObjectTypeReturnsFalse()
 
testGetChildrenFromFolderWithOnlyNonDavableNamedContentReturnsEmptyArray()
 
testSetNameWithoutPermissionsThrowsForbiddenError()
 
testDeleteWithoutPermissionsThrowsForbiddenError()
 
testGetChilrendWithExistingNameOfFolderOrFileReturnsArrayWithProblemInfoFile()