ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilWebDAVLockUriPathResolverTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
8 
25 require_once "./Services/WebDAV/test/ilWebDAVTestHelper.php";
26 
31 class ilWebDAVLockUriPathResolverTest extends TestCase
32 {
34 
35  public function __construct(?string $name = null, array $data = [], $dataName = '')
36  {
37  $this->webdav_test_helper = new ilWebDAVTestHelper();
38  parent::__construct($name, $data, $dataName);
39  }
40 
41  public function setUp(): void
42  {
43  define('CLIENT_ID', $this->webdav_test_helper->getClientId());
44  define('ROOT_FOLDER_ID', 1);
45  }
46 
48  {
49  $invalid_path = [
50  "",
51  "invalid_client_id",
52  "invalid_client_id/and_some_path"
53  ];
55 
56  foreach ($invalid_path as $current_path) {
57  try {
58  $path_resolver->getRefIdForWebDAVPath($current_path);
59  $this->assertFalse('This should not happen!');
60  } catch (BadRequest $e) {
61  $this->assertEquals('Invalid client id given', $e->getMessage());
62  }
63  }
64  }
65 
67  {
68  $path_only_clientid = $this->webdav_test_helper->getClientId();
70 
71  $this->assertEquals(1, $path_resolver->getRefIdForWebDAVPath($path_only_clientid));
72  }
73 
75  {
76  $path_with_valid_ref_id = $this->webdav_test_helper->getClientId() . '/ref_50';
78 
79  $this->assertEquals(50, $path_resolver->getRefIdForWebDAVPath($path_with_valid_ref_id));
80  }
81 
83  {
84  $invalid_refmount_path = [
85  $this->webdav_test_helper->getClientId() . '/ref_0',
86  $this->webdav_test_helper->getClientId() . '/ref_-23',
87  $this->webdav_test_helper->getClientId() . '/ref_adfadf'
88  ];
90 
91  foreach ($invalid_refmount_path as $current_path) {
92  try {
93  $path_resolver->getRefIdForWebDAVPath($current_path);
94  $this->assertFalse('This should not happen!');
95  } catch (NotFound $e) {
96  $this->assertEquals('Mount point not found', $e->getMessage());
97  }
98  }
99  }
100 
102  {
103  // Arrange
104  $path = $this->webdav_test_helper->getClientId() . '/Last Child/Last Third Child';
105  $expected_ref_id = 2335634322;
106  $path_resolver = $this->getPathResolverWithExpectationForFunctionsInHelper(2, 8);
107 
108  $this->assertEquals($expected_ref_id, $path_resolver->getRefIdForWebDAVPath($path));
109  }
110 
112  {
113  // Arrange
114  $path = $this->webdav_test_helper->getClientId() . '/Second Child/Second First Child';
115  $expected_ref_id = 72;
116  $path_resolver = $this->getPathResolverWithExpectationForFunctionsInHelper(2, 11);
117 
118  $this->assertEquals($expected_ref_id, $path_resolver->getRefIdForWebDAVPath($path));
119  }
120 
122  {
123  // Arrange
124  $pathes = [
125  $this->webdav_test_helper->getClientId() . '/Non exitent First Child/Last Third Child' => [
126  'parameters' => [1, 4],
127  'error_message' => 'Node not found'
128  ],
129  $this->webdav_test_helper->getClientId() . '/Last Child/Non existent Last Child' => [
130  'parameters' => [2, 8],
131  'error_message' => 'Last node not found'
132  ]
133  ];
134 
135  foreach ($pathes as $path => $additional_info) {
137  ...$additional_info['parameters']
138  );
139  try {
140  $path_resolver->getRefIdForWebDAVPath($path);
141  $this->assertFalse('This should not happen!');
142  } catch (NotFound $e) {
143  $this->assertEquals($additional_info['error_message'], $e->getMessage());
144  }
145  }
146  }
147 
149  {
150  $mocked_repo_helper = $this->createMock(ilWebDAVRepositoryHelper::class);
151  return new ilWebDAVLockUriPathResolver($mocked_repo_helper);
152  }
153 
154  protected function getPathResolverWithExpectationForFunctionsInHelper(int $expects_children, int $expects_ref_id): ilWebDAVLockUriPathResolver
155  {
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  function (int $parent_ref) use ($tree): array {
162  return $tree[$parent_ref]['children'];
163  }
164  );
165  $mocked_repo_helper->expects($this->exactly($expects_ref_id))
166  ->method('getObjectTitleFromRefId')->willReturnCallback(
167  function (int $ref_id) use ($tree): string {
168  return $tree[$ref_id]['title'];
169  }
170  );
171  return new ilWebDAVLockUriPathResolver($mocked_repo_helper);
172  }
173 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$path
Definition: ltiservices.php:32
if($format !==null) $name
Definition: metadata.php:247
$ref_id
Definition: ltiauth.php:67
__construct(?string $name=null, array $data=[], $dataName='')
testGetRefIdForWebDAVPathWithPathPointingToElementWithIdenticalTitleReturnsRefIdOfLastIdenticalElement()
getPathResolverWithExpectationForFunctionsInHelper(int $expects_children, int $expects_ref_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...