ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilWebDAVLockUriPathResolverTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use PHPUnit\Framework\TestCase;
22use Sabre\DAV\Exception\BadRequest;
23use Sabre\DAV\Exception\NotFound;
24
25#[\PHPUnit\Framework\Attributes\PreserveGlobalState(false)]
26#[\PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses]
27class ilWebDAVLockUriPathResolverTest extends TestCase
28{
30
31 public function setUp(): void
32 {
33 $this->webdav_test_helper = new ilWebDAVTestHelper();
34 define('CLIENT_ID', $this->webdav_test_helper->getClientId());
35 define('ROOT_FOLDER_ID', 1);
36 }
37
39 {
40 $invalid_path = [
41 "",
42 "invalid_client_id",
43 "invalid_client_id/and_some_path"
44 ];
46
47 foreach ($invalid_path as $current_path) {
48 try {
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());
53 }
54 }
55 }
56
58 {
59 $path_only_clientid = $this->webdav_test_helper->getClientId();
61
62 $this->assertSame(1, $path_resolver->getRefIdForWebDAVPath($path_only_clientid));
63 }
64
66 {
67 $path_with_valid_ref_id = $this->webdav_test_helper->getClientId() . '/ref_50';
69
70 $this->assertSame(50, $path_resolver->getRefIdForWebDAVPath($path_with_valid_ref_id));
71 }
72
74 {
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'
79 ];
81
82 foreach ($invalid_refmount_path as $current_path) {
83 try {
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());
88 }
89 }
90 }
91
93 {
94 // Arrange
95 $path = $this->webdav_test_helper->getClientId() . '/Last Child/Last Third Child';
96 $expected_ref_id = 2335634322;
97 $path_resolver = $this->getPathResolverWithExpectationForFunctionsInHelper(2, 8);
98
99 $this->assertSame($expected_ref_id, $path_resolver->getRefIdForWebDAVPath($path));
100 }
101
103 ): void {
104 // Arrange
105 $path = $this->webdav_test_helper->getClientId() . '/Second Child/Second First Child';
106 $expected_ref_id = 72;
107 $path_resolver = $this->getPathResolverWithExpectationForFunctionsInHelper(2, 11);
108
109 $this->assertSame($expected_ref_id, $path_resolver->getRefIdForWebDAVPath($path));
110 }
111
113 {
114 // Arrange
115 $pathes = [
116 $this->webdav_test_helper->getClientId() . '/Non exitent First Child/Last Third Child' => [
117 'parameters' => [1, 4],
118 'error_message' => 'Node not found'
119 ],
120 $this->webdav_test_helper->getClientId() . '/Last Child/Non existent Last Child' => [
121 'parameters' => [2, 8],
122 'error_message' => 'Last node not found'
123 ]
124 ];
125
126 foreach ($pathes as $path => $additional_info) {
127 $path_resolver = $this->getPathResolverWithExpectationForFunctionsInHelper(
128 ...$additional_info['parameters']
129 );
130 try {
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());
135 }
136 }
137 }
138
140 {
141 $mocked_repo_helper = $this->createMock(ilWebDAVRepositoryHelper::class);
142 return new ilWebDAVLockUriPathResolver($mocked_repo_helper);
143 }
144
146 int $expects_children,
147 int $expects_ref_id
149 $webdav_test_helper = new ilWebDAVTestHelper();
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']
155 );
156 $mocked_repo_helper->expects($this->exactly($expects_ref_id))
157 ->method('getObjectTitleFromRefId')->willReturnCallback(
158 fn(int $ref_id): string => $tree[$ref_id]['title']
159 );
160 return new ilWebDAVLockUriPathResolver($mocked_repo_helper);
161 }
162}
getPathResolverWithExpectationForFunctionsInHelper(int $expects_children, int $expects_ref_id)
testGetRefIdForWebDAVPathWithPathPointingToElementWithIdenticalTitleReturnsRefIdOfLastIdenticalElement()
$ref_id
Definition: ltiauth.php:66
$path
Definition: ltiservices.php:30