ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilWebDAVLockUriPathResolverTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
30 {
32 
33  public function __construct(?string $name = null, array $data = [], $dataName = '')
34  {
35  $this->webdav_test_helper = new ilWebDAVTestHelper();
36  parent::__construct($name, $data, $dataName);
37  }
38 
39  public function setUp(): void
40  {
41  define('CLIENT_ID', $this->webdav_test_helper->getClientId());
42  define('ROOT_FOLDER_ID', 1);
43  }
44 
46  {
47  $invalid_path = [
48  "",
49  "invalid_client_id",
50  "invalid_client_id/and_some_path"
51  ];
53 
54  foreach ($invalid_path as $current_path) {
55  try {
56  $path_resolver->getRefIdForWebDAVPath($current_path);
57  $this->assertFalse('This should not happen!');
58  } catch (BadRequest $e) {
59  $this->assertEquals('Invalid client id given', $e->getMessage());
60  }
61  }
62  }
63 
65  {
66  $path_only_clientid = $this->webdav_test_helper->getClientId();
68 
69  $this->assertEquals(1, $path_resolver->getRefIdForWebDAVPath($path_only_clientid));
70  }
71 
73  {
74  $path_with_valid_ref_id = $this->webdav_test_helper->getClientId() . '/ref_50';
76 
77  $this->assertEquals(50, $path_resolver->getRefIdForWebDAVPath($path_with_valid_ref_id));
78  }
79 
81  {
82  $invalid_refmount_path = [
83  $this->webdav_test_helper->getClientId() . '/ref_0',
84  $this->webdav_test_helper->getClientId() . '/ref_-23',
85  $this->webdav_test_helper->getClientId() . '/ref_adfadf'
86  ];
88 
89  foreach ($invalid_refmount_path as $current_path) {
90  try {
91  $path_resolver->getRefIdForWebDAVPath($current_path);
92  $this->assertFalse('This should not happen!');
93  } catch (NotFound $e) {
94  $this->assertEquals('Mount point not found', $e->getMessage());
95  }
96  }
97  }
98 
100  {
101  // Arrange
102  $path = $this->webdav_test_helper->getClientId() . '/Last Child/Last Third Child';
103  $expected_ref_id = 2335634322;
104  $path_resolver = $this->getPathResolverWithExpectationForFunctionsInHelper(2, 8);
105 
106  $this->assertEquals($expected_ref_id, $path_resolver->getRefIdForWebDAVPath($path));
107  }
108 
110  ): void {
111  // Arrange
112  $path = $this->webdav_test_helper->getClientId() . '/Second Child/Second First Child';
113  $expected_ref_id = 72;
114  $path_resolver = $this->getPathResolverWithExpectationForFunctionsInHelper(2, 11);
115 
116  $this->assertEquals($expected_ref_id, $path_resolver->getRefIdForWebDAVPath($path));
117  }
118 
120  {
121  // Arrange
122  $pathes = [
123  $this->webdav_test_helper->getClientId() . '/Non exitent First Child/Last Third Child' => [
124  'parameters' => [1, 4],
125  'error_message' => 'Node not found'
126  ],
127  $this->webdav_test_helper->getClientId() . '/Last Child/Non existent Last Child' => [
128  'parameters' => [2, 8],
129  'error_message' => 'Last node not found'
130  ]
131  ];
132 
133  foreach ($pathes as $path => $additional_info) {
135  ...$additional_info['parameters']
136  );
137  try {
138  $path_resolver->getRefIdForWebDAVPath($path);
139  $this->assertFalse('This should not happen!');
140  } catch (NotFound $e) {
141  $this->assertEquals($additional_info['error_message'], $e->getMessage());
142  }
143  }
144  }
145 
147  {
148  $mocked_repo_helper = $this->createMock(ilWebDAVRepositoryHelper::class);
149  return new ilWebDAVLockUriPathResolver($mocked_repo_helper);
150  }
151 
153  int $expects_children,
154  int $expects_ref_id
156  $webdav_test_helper = new ilWebDAVTestHelper();
157  $tree = $webdav_test_helper->getTree();
158  $mocked_repo_helper = $this->createMock(ilWebDAVRepositoryHelper::class);
159  $mocked_repo_helper->expects($this->exactly($expects_children))
160  ->method('getChildrenOfRefId')->willReturnCallback(
161  fn(int $parent_ref): array => $tree[$parent_ref]['children']
162  );
163  $mocked_repo_helper->expects($this->exactly($expects_ref_id))
164  ->method('getObjectTitleFromRefId')->willReturnCallback(
165  fn(int $ref_id): string => $tree[$ref_id]['title']
166  );
167  return new ilWebDAVLockUriPathResolver($mocked_repo_helper);
168  }
169 }
$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)