ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilWebDAVUriPathResolverTest.php
Go to the documentation of this file.
1 <?php
2 
4 {
6  protected $mocked_repo_helper;
7 
11  protected function setUp()
12  {
13  require_once('./Services/WebDAV/classes/tree/class.ilWebDAVUriPathResolver.php');
14  require_once('./Services/WebDAV/classes/class.ilWebDAVRepositoryHelper.php');
15 
16  $this->mocked_repo_helper = \Mockery::mock('ilWebDAVRepositoryHelper');
17 
18  parent::setUp();
19  }
20 
21 
27  {
28  $path_resolver = new ilWebDAVUriPathResolver($this->mocked_repo_helper);
29  $too_short_path = "some_string_without_a_slash";
30  $correct_exception_thrown = false;
31 
32  try {
33  $path_resolver->getRefIdForWebDAVPath($too_short_path);
34  } catch (\Sabre\DAV\Exception\BadRequest $e) {
35  $correct_exception_thrown = $e->getMessage() == 'Path too short';
36  }
37 
38  $this->assertTrue($correct_exception_thrown);
39  }
40 
46  {
47  // Arrange
48  $too_short_path = "some_string_with_a_slash/and_stuff";
49  $correct_exception_thrown = false;
50 
51  $path_resolver = \Mockery::mock('ilWebDAVUriPathResolver')->makePartial();
52  $path_resolver->shouldAllowMockingProtectedMethods();
53 
54  // Assert
55  try {
56  $ref_id = $path_resolver->getRefIdForWebDAVPath($too_short_path);
57  } catch (\Sabre\DAV\Exception\BadRequest $e) {
58  $correct_exception_thrown = $e->getMessage() == 'Invalid mountpoint given';
59  }
60 
61  // Act
62  $this->assertTrue($correct_exception_thrown);
63  }
64 
70  {
71  // Arrange
72  $too_short_path = "some_string_with_a_slash/ILIAS";
73  $expected_ref_id = 40;
74 
75  $path_resolver = \Mockery::mock('ilWebDAVUriPathResolver')->makePartial();
76  $path_resolver->shouldAllowMockingProtectedMethods();
77  $path_resolver->shouldReceive('getRefIdFromPathInRepositoryMount')->andReturn($expected_ref_id);
78 
79  // Assert
80  $received_ref_id = $path_resolver->getRefIdForWebDAVPath($too_short_path);
81 
82  // Act
83  $this->assertEquals($expected_ref_id, $received_ref_id);
84  }
85 
86 
94  {
95  // Arrange
96  $searched_ref_id = 40;
97  $path_title_array = explode('/', "ref30/ref35/ref$searched_ref_id/");
98 
99  $path_resolver = \Mockery::mock('ilWebDAVUriPathResolver')->makePartial();
100  $path_resolver->shouldAllowMockingProtectedMethods();
101  $path_resolver->shouldReceive('getChildRefIdByGivenTitle')->andReturn(30, 35, $searched_ref_id);
102 
103  // Act
104  $result_ref = $path_resolver->getRefIdFromGivenParentRefAndTitlePath(25, $path_title_array);
105 
106  // Assert
107  $this->assertEquals($searched_ref_id, $result_ref);
108  }
109 
117  {
118  // Arrange
119  $searched_ref_id = 40;
120  $path_title_array = explode('/', "ref30/ref35/ref$searched_ref_id");
121  $path_resolver = \Mockery::mock('ilWebDAVUriPathResolver')->makePartial();
122  $path_resolver->shouldAllowMockingProtectedMethods();
123  $path_resolver->shouldReceive('getChildRefIdByGivenTitle')->andReturn(30, 35, $searched_ref_id);
124 
125  // Act
126  $result_ref = $path_resolver->getRefIdFromGivenParentRefAndTitlePath(25, $path_title_array);
127 
128  // Assert
129  $this->assertEquals($searched_ref_id, $result_ref);
130  }
131 
139  {
140  // Arrange
141  $searched_ref_id = 40;
142  $path_title_array = explode('/', "ref30///ref35/ref$searched_ref_id");
143  $path_resolver = \Mockery::mock('ilWebDAVUriPathResolver')->makePartial();
144  $path_resolver->shouldAllowMockingProtectedMethods();
145  $path_resolver->shouldReceive('getChildRefIdByGivenTitle')->andReturn(30, 35, $searched_ref_id);
146 
147  // Act
148  $result_ref = $path_resolver->getRefIdFromGivenParentRefAndTitlePath(25, $path_title_array);
149 
150  // Assert
151  $this->assertEquals($searched_ref_id, $result_ref);
152  }
153 
161  {
162  // Arrange
163  $searched_ref_id = 40;
164  $path_title_array = explode('/', "ref30//ref35/ref$searched_ref_id");
165  $path_resolver = \Mockery::mock('ilWebDAVUriPathResolver')->makePartial();
166  $path_resolver->shouldAllowMockingProtectedMethods();
167  $path_resolver->shouldReceive('getChildRefIdByGivenTitle')->andReturn(30, 35, $searched_ref_id);
168 
169  // Act
170  $result_ref = $path_resolver->getRefIdFromGivenParentRefAndTitlePath(25, $path_title_array);
171 
172  // Assert
173  $this->assertEquals($searched_ref_id, $result_ref);
174  }
175 
183  {
184  // Arrange
185  $searched_ref_id = 40;
186  $path_title_array = explode('/', "ref30///ref35/ref$searched_ref_id");
187  $path_resolver = \Mockery::mock('ilWebDAVUriPathResolver')->makePartial();
188  $path_resolver->shouldAllowMockingProtectedMethods();
189  $path_resolver->shouldReceive('getChildRefIdByGivenTitle')->andReturn(30, 35, $searched_ref_id);
190 
191  // Act
192  $result_ref = $path_resolver->getRefIdFromGivenParentRefAndTitlePath(25, $path_title_array);
193 
194  // Assert
195  $this->assertEquals($searched_ref_id, $result_ref);
196  }
197 }
getRefIdFromGivenParentRefAndTitlePath_pathEndsWithoutSlash_returnLastElement()
If a path like foo/bar/last is given, the return should be the ref_id of &#39;last&#39;.
getRefIdFromGivenParentRefAndTitlePath_pathWithTrippleSlashInBetween_returnLastElement()
If a path like foo///bar/last is given, the return should be the ref_id of &#39;last&#39;.
getRefIdForWebDAVPath_repoRootAsMountGiven_callAndReturnValueOfGetRefIdFromPathInRepositoryMount()
getRefIdFromGivenParentRefAndTitlePath_pathStartsWithSlash_returnLastElement()
If a path like /foo//bar/last is given, the return should be the ref_id of &#39;last&#39;.
getRefIdFromGivenParentRefAndTitlePath_pathWithDoubleSlashInBetween_returnLastElement()
If a path like foo//bar/last is given, the return should be the ref_id of &#39;last&#39;. ...
getRefIdFromGivenParentRefAndTitlePath_pathEndsWithSlash_returnElementBeforeSlash()
If a path like foo/bar/last/ is given, the return should be the ref_id of &#39;last&#39;. ...
Class ilWebDAVUriPathResolver.