ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilWebDAVLockUriPathResolverTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 require_once "./Services/WebDAV/test/ilWebDAVTestHelper.php";
25 
30 class ilWebDAVLockUriPathResolverTest extends TestCase
31 {
33 
34  public function __construct(?string $name = null, array $data = [], $dataName = '')
35  {
36  $this->webdav_test_helper = new ilWebDAVTestHelper();
37  parent::__construct($name, $data, $dataName);
38  }
39 
40  public function setUp(): void
41  {
42  define('CLIENT_ID', $this->webdav_test_helper->getClientId());
43  define('ROOT_FOLDER_ID', 1);
44  }
45 
47  {
48  $invalid_path = [
49  "",
50  "invalid_client_id",
51  "invalid_client_id/and_some_path"
52  ];
54 
55  foreach ($invalid_path as $current_path) {
56  try {
57  $path_resolver->getRefIdForWebDAVPath($current_path);
58  $this->assertFalse('This should not happen!');
59  } catch (BadRequest $e) {
60  $this->assertEquals('Invalid client id given', $e->getMessage());
61  }
62  }
63  }
64 
66  {
67  $path_only_clientid = $this->webdav_test_helper->getClientId();
69 
70  $this->assertEquals(1, $path_resolver->getRefIdForWebDAVPath($path_only_clientid));
71  }
72 
74  {
75  $path_with_valid_ref_id = $this->webdav_test_helper->getClientId() . '/ref_50';
77 
78  $this->assertEquals(50, $path_resolver->getRefIdForWebDAVPath($path_with_valid_ref_id));
79  }
80 
82  {
83  $invalid_refmount_path = [
84  $this->webdav_test_helper->getClientId() . '/ref_0',
85  $this->webdav_test_helper->getClientId() . '/ref_-23',
86  $this->webdav_test_helper->getClientId() . '/ref_adfadf'
87  ];
89 
90  foreach ($invalid_refmount_path as $current_path) {
91  try {
92  $path_resolver->getRefIdForWebDAVPath($current_path);
93  $this->assertFalse('This should not happen!');
94  } catch (NotFound $e) {
95  $this->assertEquals('Mount point not found', $e->getMessage());
96  }
97  }
98  }
99 
101  {
102  // Arrange
103  $path = $this->webdav_test_helper->getClientId() . '/Last Child/Last Third Child';
104  $expected_ref_id = 2335634322;
105  $path_resolver = $this->getPathResolverWithExpectationForFunctionsInHelper(2, 8);
106 
107  $this->assertEquals($expected_ref_id, $path_resolver->getRefIdForWebDAVPath($path));
108  }
109 
111  ): void {
112  // Arrange
113  $path = $this->webdav_test_helper->getClientId() . '/Second Child/Second First Child';
114  $expected_ref_id = 72;
115  $path_resolver = $this->getPathResolverWithExpectationForFunctionsInHelper(2, 11);
116 
117  $this->assertEquals($expected_ref_id, $path_resolver->getRefIdForWebDAVPath($path));
118  }
119 
121  {
122  // Arrange
123  $pathes = [
124  $this->webdav_test_helper->getClientId() . '/Non exitent First Child/Last Third Child' => [
125  'parameters' => [1, 4],
126  'error_message' => 'Node not found'
127  ],
128  $this->webdav_test_helper->getClientId() . '/Last Child/Non existent Last Child' => [
129  'parameters' => [2, 8],
130  'error_message' => 'Last node not found'
131  ]
132  ];
133 
134  foreach ($pathes as $path => $additional_info) {
136  ...$additional_info['parameters']
137  );
138  try {
139  $path_resolver->getRefIdForWebDAVPath($path);
140  $this->assertFalse('This should not happen!');
141  } catch (NotFound $e) {
142  $this->assertEquals($additional_info['error_message'], $e->getMessage());
143  }
144  }
145  }
146 
148  {
149  $mocked_repo_helper = $this->createMock(ilWebDAVRepositoryHelper::class);
150  return new ilWebDAVLockUriPathResolver($mocked_repo_helper);
151  }
152 
154  int $expects_children,
155  int $expects_ref_id
157  $webdav_test_helper = new ilWebDAVTestHelper();
158  $tree = $webdav_test_helper->getTree();
159  $mocked_repo_helper = $this->createMock(ilWebDAVRepositoryHelper::class);
160  $mocked_repo_helper->expects($this->exactly($expects_children))
161  ->method('getChildrenOfRefId')->willReturnCallback(
162  fn(int $parent_ref): array => $tree[$parent_ref]['children']
163  );
164  $mocked_repo_helper->expects($this->exactly($expects_ref_id))
165  ->method('getObjectTitleFromRefId')->willReturnCallback(
166  fn(int $ref_id): string => $tree[$ref_id]['title']
167  );
168  return new ilWebDAVLockUriPathResolver($mocked_repo_helper);
169  }
170 }
$path
Definition: ltiservices.php:32
$ref_id
Definition: ltiauth.php:67
__construct(VocabulariesInterface $vocabularies)
__construct(?string $name=null, array $data=[], $dataName='')
testGetRefIdForWebDAVPathWithPathPointingToElementWithIdenticalTitleReturnsRefIdOfLastIdenticalElement()
getPathResolverWithExpectationForFunctionsInHelper(int $expects_children, int $expects_ref_id)