19declare(strict_types=1);
21use PHPUnit\Framework\TestCase;
22use Sabre\DAV\Exception\BadRequest;
23use Sabre\DAV\Exception\NotFound;
25#[\PHPUnit\Framework\Attributes\PreserveGlobalState(false)]
26#[\PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses]
34 define(
'CLIENT_ID', $this->webdav_test_helper->getClientId());
35 define(
'ROOT_FOLDER_ID', 1);
43 "invalid_client_id/and_some_path"
47 foreach ($invalid_path as $current_path) {
49 $path_resolver->getRefIdForWebDAVPath($current_path);
50 $this->assertFalse(
'This should not happen!');
51 }
catch (BadRequest
$e) {
52 $this->assertSame(
'Invalid client id given',
$e->getMessage());
59 $path_only_clientid = $this->webdav_test_helper->getClientId();
62 $this->assertSame(1, $path_resolver->getRefIdForWebDAVPath($path_only_clientid));
67 $path_with_valid_ref_id = $this->webdav_test_helper->getClientId() .
'/ref_50';
70 $this->assertSame(50, $path_resolver->getRefIdForWebDAVPath($path_with_valid_ref_id));
75 $invalid_refmount_path = [
76 $this->webdav_test_helper->getClientId() .
'/ref_0',
77 $this->webdav_test_helper->getClientId() .
'/ref_-23',
78 $this->webdav_test_helper->getClientId() .
'/ref_adfadf'
82 foreach ($invalid_refmount_path as $current_path) {
84 $path_resolver->getRefIdForWebDAVPath($current_path);
85 $this->assertFalse(
'This should not happen!');
86 }
catch (NotFound
$e) {
87 $this->assertSame(
'Mount point not found',
$e->getMessage());
95 $path = $this->webdav_test_helper->getClientId() .
'/Last Child/Last Third Child';
96 $expected_ref_id = 2335634322;
99 $this->assertSame($expected_ref_id, $path_resolver->getRefIdForWebDAVPath(
$path));
105 $path = $this->webdav_test_helper->getClientId() .
'/Second Child/Second First Child';
106 $expected_ref_id = 72;
109 $this->assertSame($expected_ref_id, $path_resolver->getRefIdForWebDAVPath(
$path));
116 $this->webdav_test_helper->getClientId() .
'/Non exitent First Child/Last Third Child' => [
117 'parameters' => [1, 4],
118 'error_message' =>
'Node not found'
120 $this->webdav_test_helper->getClientId() .
'/Last Child/Non existent Last Child' => [
121 'parameters' => [2, 8],
122 'error_message' =>
'Last node not found'
126 foreach ($pathes as
$path => $additional_info) {
127 $path_resolver = $this->getPathResolverWithExpectationForFunctionsInHelper(
128 ...$additional_info[
'parameters']
131 $path_resolver->getRefIdForWebDAVPath(
$path);
132 $this->assertFalse(
'This should not happen!');
133 }
catch (NotFound
$e) {
134 $this->assertEquals($additional_info[
'error_message'],
$e->getMessage());
141 $mocked_repo_helper = $this->createMock(ilWebDAVRepositoryHelper::class);
146 int $expects_children,
150 $tree = $webdav_test_helper->getTree();
151 $mocked_repo_helper = $this->createMock(ilWebDAVRepositoryHelper::class);
152 $mocked_repo_helper->expects($this->exactly($expects_children))
153 ->method(
'getChildrenOfRefId')->willReturnCallback(
154 fn(
int $parent_ref): array => $tree[$parent_ref][
'children']
156 $mocked_repo_helper->expects($this->exactly($expects_ref_id))
157 ->method(
'getObjectTitleFromRefId')->willReturnCallback(
testGetRefIdForValidRefMountReturnsRefId()
testGetRefIdForWebDAVWithValidClientIdReturnsRootFolderId()
ilWebDAVTestHelper $webdav_test_helper
testGetRefIdForWebDAVPathWhenPathHasNoValidStartElementThrowsBadRequestError()
getPathResolverWithExpectationForFunctionsInHelper(int $expects_children, int $expects_ref_id)
testGetRefIdForWebDAVPathWithInvalidPathThrowsNotFoundError()
getPathResolverWithoutExpectationForFunctionsInHelper()
testGetRefIdForWebDAVPathWithPathPointingToElementWithIdenticalTitleReturnsRefIdOfLastIdenticalElement()
testGetRefIdForInvalidRefMountThrowsNotFoundError()
testGetRefIdForWebDAVPathWithPathReturnsRefIdOfLastElement()