ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ilWebDAVLockUriPathResolverTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
25 #[\PHPUnit\Framework\Attributes\PreserveGlobalState(false)]
26 #[\PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses]
28 {
30 
31  public function __construct(?string $name = null, array $data = [], $dataName = '')
32  {
33  $this->webdav_test_helper = new ilWebDAVTestHelper();
34  parent::__construct($name, $data, $dataName);
35  }
36 
37  public function setUp(): void
38  {
39  define('CLIENT_ID', $this->webdav_test_helper->getClientId());
40  define('ROOT_FOLDER_ID', 1);
41  }
42 
44  {
45  $invalid_path = [
46  "",
47  "invalid_client_id",
48  "invalid_client_id/and_some_path"
49  ];
51 
52  foreach ($invalid_path as $current_path) {
53  try {
54  $path_resolver->getRefIdForWebDAVPath($current_path);
55  $this->assertFalse('This should not happen!');
56  } catch (BadRequest $e) {
57  $this->assertEquals('Invalid client id given', $e->getMessage());
58  }
59  }
60  }
61 
63  {
64  $path_only_clientid = $this->webdav_test_helper->getClientId();
66 
67  $this->assertEquals(1, $path_resolver->getRefIdForWebDAVPath($path_only_clientid));
68  }
69 
71  {
72  $path_with_valid_ref_id = $this->webdav_test_helper->getClientId() . '/ref_50';
74 
75  $this->assertEquals(50, $path_resolver->getRefIdForWebDAVPath($path_with_valid_ref_id));
76  }
77 
79  {
80  $invalid_refmount_path = [
81  $this->webdav_test_helper->getClientId() . '/ref_0',
82  $this->webdav_test_helper->getClientId() . '/ref_-23',
83  $this->webdav_test_helper->getClientId() . '/ref_adfadf'
84  ];
86 
87  foreach ($invalid_refmount_path as $current_path) {
88  try {
89  $path_resolver->getRefIdForWebDAVPath($current_path);
90  $this->assertFalse('This should not happen!');
91  } catch (NotFound $e) {
92  $this->assertEquals('Mount point not found', $e->getMessage());
93  }
94  }
95  }
96 
98  {
99  // Arrange
100  $path = $this->webdav_test_helper->getClientId() . '/Last Child/Last Third Child';
101  $expected_ref_id = 2335634322;
102  $path_resolver = $this->getPathResolverWithExpectationForFunctionsInHelper(2, 8);
103 
104  $this->assertEquals($expected_ref_id, $path_resolver->getRefIdForWebDAVPath($path));
105  }
106 
108  ): void {
109  // Arrange
110  $path = $this->webdav_test_helper->getClientId() . '/Second Child/Second First Child';
111  $expected_ref_id = 72;
112  $path_resolver = $this->getPathResolverWithExpectationForFunctionsInHelper(2, 11);
113 
114  $this->assertEquals($expected_ref_id, $path_resolver->getRefIdForWebDAVPath($path));
115  }
116 
118  {
119  // Arrange
120  $pathes = [
121  $this->webdav_test_helper->getClientId() . '/Non exitent First Child/Last Third Child' => [
122  'parameters' => [1, 4],
123  'error_message' => 'Node not found'
124  ],
125  $this->webdav_test_helper->getClientId() . '/Last Child/Non existent Last Child' => [
126  'parameters' => [2, 8],
127  'error_message' => 'Last node not found'
128  ]
129  ];
130 
131  foreach ($pathes as $path => $additional_info) {
133  ...$additional_info['parameters']
134  );
135  try {
136  $path_resolver->getRefIdForWebDAVPath($path);
137  $this->assertFalse('This should not happen!');
138  } catch (NotFound $e) {
139  $this->assertEquals($additional_info['error_message'], $e->getMessage());
140  }
141  }
142  }
143 
145  {
146  $mocked_repo_helper = $this->createMock(ilWebDAVRepositoryHelper::class);
147  return new ilWebDAVLockUriPathResolver($mocked_repo_helper);
148  }
149 
151  int $expects_children,
152  int $expects_ref_id
154  $webdav_test_helper = new ilWebDAVTestHelper();
155  $tree = $webdav_test_helper->getTree();
156  $mocked_repo_helper = $this->createMock(ilWebDAVRepositoryHelper::class);
157  $mocked_repo_helper->expects($this->exactly($expects_children))
158  ->method('getChildrenOfRefId')->willReturnCallback(
159  fn(int $parent_ref): array => $tree[$parent_ref]['children']
160  );
161  $mocked_repo_helper->expects($this->exactly($expects_ref_id))
162  ->method('getObjectTitleFromRefId')->willReturnCallback(
163  fn(int $ref_id): string => $tree[$ref_id]['title']
164  );
165  return new ilWebDAVLockUriPathResolver($mocked_repo_helper);
166  }
167 }
$path
Definition: ltiservices.php:29
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$ref_id
Definition: ltiauth.php:65
__construct(?string $name=null, array $data=[], $dataName='')
testGetRefIdForWebDAVPathWithPathPointingToElementWithIdenticalTitleReturnsRefIdOfLastIdenticalElement()
getPathResolverWithExpectationForFunctionsInHelper(int $expects_children, int $expects_ref_id)
__construct(Container $dic, ilPlugin $plugin)