ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilObjContainerDAVTest Class Reference

Created by PhpStorm. More...

+ Inheritance diagram for ilObjContainerDAVTest:
+ Collaboration diagram for ilObjContainerDAVTest:

Public Member Functions

 GetChildren_OnlyDavableObjects_ReturnAllChildren ()
 
 GetChildren_NoDavableObjects_ReturnEmptyArray ()
 Important parameters: isDAVableObject = true checkAccess = false -> we test the behavior for no access. More...
 
 GetChildren_NoReadAccessToObjects_ReturnEmptyArray ()
 
 GetChildren_MixedWithNonDavableObjects_ReturnOnlyDavableObjects ()
 
 ChildExists_ChildExistsButIsNotDAVable_returnFalse ()
 
 ChildExists_ChildExistsButUserHasNoReadAccess_returnFalse ()
 
 ChildExists_ChildExists_returnTrue ()
 
 GetChild_ChildExistsAndIsDavable_ReturnChild ()
 
 GetChild_ChildExistsButIsNotDavable_ThrowNotFound ()
 
 GetChild_ChildDoesNotExist_ThrowNotFound ()
 
 CreateFile_NoCreateAccess_ThrowForbidden ()
 
 CreateFile_InvalidFileExtension_ThrowForbidden ()
 

Protected Member Functions

 setUp ()
 Setup. More...
 
 setUpContainerDAV ($mocked_obj, $mocked_repo_helper, $mocked_dav_helper)
 Setup instance for ilObjectDAV. More...
 

Protected Attributes

 $ref_id
 
 $mocked_obj
 
 $mocked_repo_helper
 
 $mocked_dav_helper
 
 $container_dav
 

Detailed Description

Created by PhpStorm.

User: adm_her Date: 26.09.18 Time: 12:50

Definition at line 10 of file ilObjContainerDAVTest.php.

Member Function Documentation

◆ ChildExists_ChildExists_returnTrue()

ilObjContainerDAVTest::ChildExists_ChildExists_returnTrue ( )
Test:

Definition at line 231 of file ilObjContainerDAVTest.php.

References $i.

232  {
233  // Arrange
234  $number_of_children = 5;
235  $searched_title = 'dummy';
236 
237  $children_ref_ids = array();
238  for ($i = 101; $i < $number_of_children + 101; $i++) {
239  $children_ref_ids[] = $i;
240  }
241 
242  $this->mocked_repo_helper->shouldReceive('getChildrenOfRefId')->andReturn($children_ref_ids);
243  $this->mocked_dav_helper->shouldReceive('isDAVableObject')->andReturn(true);
244  $this->mocked_repo_helper->shouldReceive('getObjectTitleFromRefId')->andReturn('1', '2', $searched_title, '4', '5');
245  $this->mocked_repo_helper->shouldReceive('checkAccess')->andReturn(true);
246 
247  // Act
248  $child_exists = $this->container_dav->childExists($searched_title);
249 
250  // Assert
251  $this->assertTrue($child_exists
252  && $this->mocked_repo_helper->shouldHaveReceived('checkAccess')->once());
253  }
$i
Definition: disco.tpl.php:19

◆ ChildExists_ChildExistsButIsNotDAVable_returnFalse()

ilObjContainerDAVTest::ChildExists_ChildExistsButIsNotDAVable_returnFalse ( )
Test:

Definition at line 179 of file ilObjContainerDAVTest.php.

References $i.

180  {
181  // Arrange
182  $number_of_children = 5;
183 
184  $children_ref_ids = array();
185  for ($i = 101; $i < $number_of_children + 101; $i++) {
186  $children_ref_ids[] = $i;
187  }
188 
189  $this->mocked_repo_helper->shouldReceive('getChildrenOfRefId')->andReturn($children_ref_ids);
190  $this->mocked_dav_helper->shouldReceive('isDAVableObject')->andReturn(false);
191 
192  // Act
193  $child_exists = $this->container_dav->childExists('dummy');
194 
195  // Assert
196  $this->assertTrue(!$child_exists);
197  }
$i
Definition: disco.tpl.php:19

◆ ChildExists_ChildExistsButUserHasNoReadAccess_returnFalse()

ilObjContainerDAVTest::ChildExists_ChildExistsButUserHasNoReadAccess_returnFalse ( )
Test:

Definition at line 203 of file ilObjContainerDAVTest.php.

References $i.

204  {
205  // Arrange
206  $number_of_children = 5;
207  $searched_title = 'dummy';
208 
209  $children_ref_ids = array();
210  for ($i = 101; $i < $number_of_children + 101; $i++) {
211  $children_ref_ids[] = $i;
212  }
213 
214  $this->mocked_repo_helper->shouldReceive('getChildrenOfRefId')->andReturn($children_ref_ids);
215  $this->mocked_dav_helper->shouldReceive('isDAVableObject')->andReturn(true);
216  $this->mocked_repo_helper->shouldReceive('getObjectTitleFromRefId')->andReturn('1', '2', $searched_title, '4', '5');
217  $this->mocked_repo_helper->shouldReceive('checkAccess')->andReturn(false);
218 
219  // Act
220  $child_exists = $this->container_dav->childExists($searched_title);
221 
222  // Assert
223  $this->assertTrue(!$child_exists
224  && $this->mocked_repo_helper->shouldHaveReceived('checkAccess')->once());
225  }
$i
Definition: disco.tpl.php:19

◆ CreateFile_InvalidFileExtension_ThrowForbidden()

ilObjContainerDAVTest::CreateFile_InvalidFileExtension_ThrowForbidden ( )
Test:

Definition at line 373 of file ilObjContainerDAVTest.php.

374  {
375  // Arrange
376  $file_title = 'some_file.exe';
377 
378  $this->mocked_repo_helper->shouldReceive('checkCreateAccessForType')->andReturn(true);
379  $this->mocked_dav_helper->shouldReceive('isValidFileNameWithValidFileExtension')->andReturn(false);
380 
381  // Act
382  try {
383  $this->container_dav->createFile($file_title);
384  } catch (\Sabre\DAV\Exception\Forbidden $e) {
385  if ($e->getMessage() == 'Invalid file extension') {
386  $exception_thrown = true;
387  }
388  }
389 
390  // Assert
391  $this->assertTrue($exception_thrown);
392  }

◆ CreateFile_NoCreateAccess_ThrowForbidden()

ilObjContainerDAVTest::CreateFile_NoCreateAccess_ThrowForbidden ( )
Test:

Definition at line 349 of file ilObjContainerDAVTest.php.

350  {
351  // Arrange
352  $file_title = 'some_file.txt';
353 
354  $this->mocked_repo_helper->shouldReceive('checkCreateAccessForType')->andReturn(false);
355 
356  // Act
357  try {
358  $this->container_dav->createFile($file_title);
359  } catch (\Sabre\DAV\Exception\Forbidden $e) {
360  if ($e->getMessage() == 'No write access') {
361  $exception_thrown = true;
362  }
363  }
364 
365  // Assert
366  $this->assertTrue($exception_thrown);
367  }

◆ GetChild_ChildDoesNotExist_ThrowNotFound()

ilObjContainerDAVTest::GetChild_ChildDoesNotExist_ThrowNotFound ( )
Test:

Definition at line 318 of file ilObjContainerDAVTest.php.

References $i.

319  {
320  // Arrange
321  $number_of_children = 5;
322  $searched_title = 'dummy';
323  $dummy_obj_dav = new ilObjDummyDAV();
324 
325  $children_ref_ids = array();
326  for ($i = 101; $i < $number_of_children + 101; $i++) {
327  $children_ref_ids[] = $i;
328  }
329 
330  $this->mocked_repo_helper->shouldReceive('getChildrenOfRefId')->andReturn($children_ref_ids);
331  $this->mocked_dav_helper->shouldReceive('isDAVableObject')->andReturn(true);
332  $this->mocked_repo_helper->shouldReceive('getObjectTitleFromRefId')->andReturn('1', '2', '3', '4', '5');
333 
334  // Act
335  try {
336  $this->container_dav->getChild($searched_title);
337  } catch (\Sabre\DAV\Exception\NotFound $e) {
338  $exception_thrown = true;
339  }
340 
341  // Assert
342  $this->assertTrue($exception_thrown);
343  }
This is just a dummy class for unit testing.
$i
Definition: disco.tpl.php:19

◆ GetChild_ChildExistsAndIsDavable_ReturnChild()

ilObjContainerDAVTest::GetChild_ChildExistsAndIsDavable_ReturnChild ( )
Test:

Definition at line 259 of file ilObjContainerDAVTest.php.

References $i.

260  {
261  // Arrange
262  $number_of_children = 5;
263  $searched_title = 'dummy';
264  $dummy_obj_dav = new ilObjDummyDAV();
265 
266  $children_ref_ids = array();
267  for ($i = 101; $i < $number_of_children + 101; $i++) {
268  $children_ref_ids[] = $i;
269  }
270 
271  $this->mocked_repo_helper->shouldReceive('getChildrenOfRefId')->andReturn($children_ref_ids);
272  $this->mocked_dav_helper->shouldReceive('isDAVableObject')->andReturn(true);
273  $this->mocked_repo_helper->shouldReceive('getObjectTitleFromRefId')->andReturn('1', '2', $searched_title, '4', '5');
274  $this->mocked_repo_helper->shouldReceive('checkAccess')->andReturn(true);
275  $this->mocked_dav_helper->shouldReceive('createDAVObjectForRefId')->andReturn($dummy_obj_dav);
276 
277  // Act
278  $returned_child = $this->container_dav->getChild($searched_title);
279 
280  // Assert
281  $this->assertTrue($returned_child === $dummy_obj_dav && $this->mocked_repo_helper->shouldHaveReceived('checkAccess')->once());
282  }
This is just a dummy class for unit testing.
$i
Definition: disco.tpl.php:19

◆ GetChild_ChildExistsButIsNotDavable_ThrowNotFound()

ilObjContainerDAVTest::GetChild_ChildExistsButIsNotDavable_ThrowNotFound ( )
Test:

Definition at line 288 of file ilObjContainerDAVTest.php.

References $i.

289  {
290  // Arrange
291  $number_of_children = 5;
292  $searched_title = 'dummy';
293  $exception_thrown = false;
294 
295  $children_ref_ids = array();
296  for ($i = 101; $i < $number_of_children + 101; $i++) {
297  $children_ref_ids[] = $i;
298  }
299 
300  $this->mocked_repo_helper->shouldReceive('getChildrenOfRefId')->andReturn($children_ref_ids);
301  $this->mocked_dav_helper->shouldReceive('isDAVableObject')->andReturn(false);
302 
303  // Act
304  try {
305  $this->container_dav->getChild($searched_title);
306  } catch (\Sabre\DAV\Exception\NotFound $e) {
307  $exception_thrown = true;
308  }
309 
310  // Assert
311  $this->assertTrue($exception_thrown);
312  }
$i
Definition: disco.tpl.php:19

◆ GetChildren_MixedWithNonDavableObjects_ReturnOnlyDavableObjects()

ilObjContainerDAVTest::GetChildren_MixedWithNonDavableObjects_ReturnOnlyDavableObjects ( )
Test:

Definition at line 150 of file ilObjContainerDAVTest.php.

References $i.

151  {
152  // Arrange
153  $number_of_children = 5;
154  $number_of_davable_children = 1;
155 
156  $children_ref_ids = array();
157  for ($i = 101; $i < $number_of_children + 101; $i++) {
158  $children_ref_ids[] = $i;
159  }
160 
161  $this->mocked_repo_helper->shouldReceive('getChildrenOfRefId')->andReturn($children_ref_ids);
162  $this->mocked_dav_helper->shouldReceive('isDAVableObject')->andReturn(true, true, true, false, false);
163  $this->mocked_repo_helper->shouldReceive('checkAccess')->andReturn(false, true, false);
164  $this->mocked_dav_helper->shouldReceive('createDAVObjectForRefId')->andReturn(new ilObjDummyDAV());
165 
166  // Act
167  $dav_children = $this->container_dav->getChildren();
168 
169  // Assert
170  $this->assertTrue(count($dav_children) == $number_of_davable_children
171  && $this->mocked_dav_helper->shouldHaveReceived('isDAVableObject')->times(5)
172  && $this->mocked_repo_helper->shouldHaveReceived('checkAccess')->times(3));
173  }
This is just a dummy class for unit testing.
$i
Definition: disco.tpl.php:19

◆ GetChildren_NoDavableObjects_ReturnEmptyArray()

ilObjContainerDAVTest::GetChildren_NoDavableObjects_ReturnEmptyArray ( )

Important parameters: isDAVableObject = true checkAccess = false -> we test the behavior for no access.

Test:

Definition at line 99 of file ilObjContainerDAVTest.php.

References $i.

100  {
101  // Arrange
102  $number_of_children = 5;
103  $number_of_davable_children = 0;
104 
105  $children_ref_ids = array();
106  for ($i = 101; $i < $number_of_children + 101; $i++) {
107  $children_ref_ids[] = $i;
108  }
109 
110  $this->mocked_repo_helper->shouldReceive('getChildrenOfRefId')->andReturn($children_ref_ids);
111  $this->mocked_dav_helper->shouldReceive('isDAVableObject')->andReturn(false);
112 
113  // Act
114  $dav_children = $this->container_dav->getChildren();
115 
116  // Assert
117  $this->assertTrue(count($dav_children) == $number_of_davable_children);
118  }
$i
Definition: disco.tpl.php:19

◆ GetChildren_NoReadAccessToObjects_ReturnEmptyArray()

ilObjContainerDAVTest::GetChildren_NoReadAccessToObjects_ReturnEmptyArray ( )
Test:

Definition at line 124 of file ilObjContainerDAVTest.php.

References $i.

125  {
126  // Arrange
127  $number_of_children = 5;
128  $number_of_davable_children = 0;
129 
130  $children_ref_ids = array();
131  for ($i = 101; $i < $number_of_children + 101; $i++) {
132  $children_ref_ids[] = $i;
133  }
134 
135  $this->mocked_repo_helper->shouldReceive('getChildrenOfRefId')->andReturn($children_ref_ids);
136  $this->mocked_dav_helper->shouldReceive('isDAVableObject')->andReturn(true);
137  $this->mocked_repo_helper->shouldReceive('checkAccess')->andReturn(false);
138 
139  // Act
140  $dav_children = $this->container_dav->getChildren();
141 
142  // Assert
143  $this->assertTrue(count($dav_children) == $number_of_davable_children);
144  }
$i
Definition: disco.tpl.php:19

◆ GetChildren_OnlyDavableObjects_ReturnAllChildren()

ilObjContainerDAVTest::GetChildren_OnlyDavableObjects_ReturnAllChildren ( )
Test:

Definition at line 68 of file ilObjContainerDAVTest.php.

References $i.

69  {
70  // Arrange
71  $number_of_children = 5;
72  $number_of_davable_children = $number_of_children;
73 
74  $children_ref_ids = array();
75  for ($i = 101; $i < $number_of_children + 101; $i++) {
76  $children_ref_ids[] = $i;
77  }
78 
79  $this->mocked_repo_helper->shouldReceive('getChildrenOfRefId')->andReturn($children_ref_ids);
80  $this->mocked_dav_helper->shouldReceive('isDAVableObject')->andReturn(true);
81  $this->mocked_repo_helper->shouldReceive('checkAccess')->andReturn(true);
82  $this->mocked_dav_helper->shouldReceive('createDAVObjectForRefId')->andReturn(new ilObjDummyDAV());
83 
84  // Act
85  $dav_children = $this->container_dav->getChildren();
86 
87  // Assert
88  $this->assertTrue(count($dav_children) == $number_of_children);
89  }
This is just a dummy class for unit testing.
$i
Definition: disco.tpl.php:19

◆ setUp()

ilObjContainerDAVTest::setUp ( )
protected

Setup.

Definition at line 30 of file ilObjContainerDAVTest.php.

References setUpContainerDAV().

31  {
32  require_once('./Services/WebDAV/classes/dav/class.ilObjContainerDAV.php');
33  require_once('./Services/WebDAV/classes/class.ilWebDAVRepositoryHelper.php');
34  require_once('./Services/WebDAV/classes/class.ilWebDAVObjDAVHelper.php');
35  require_once('./Services/WebDAV/test/dav/ilObjDummyDAV.php');
36 
37  $this->ref_id = 100;
38  $this->mocked_obj = \Mockery::mock('ilContainer');
39  $this->mocked_obj->shouldReceive(['getRefId' => $this->ref_id]);
40 
41  $this->mocked_repo_helper = \Mockery::mock('ilWebDAVRepositoryHelper');
42 
43  $this->mocked_dav_helper = \Mockery::mock('ilWebDAVObjDAVHelper');
44 
45  $this->container_dav = $this->setUpContainerDAV($this->mocked_obj, $this->mocked_repo_helper, $this->mocked_dav_helper);
46 
47  parent::setUp();
48  }
setUpContainerDAV($mocked_obj, $mocked_repo_helper, $mocked_dav_helper)
Setup instance for ilObjectDAV.
+ Here is the call graph for this function:

◆ setUpContainerDAV()

ilObjContainerDAVTest::setUpContainerDAV (   $mocked_obj,
  $mocked_repo_helper,
  $mocked_dav_helper 
)
protected

Setup instance for ilObjectDAV.

Definition at line 53 of file ilObjContainerDAVTest.php.

References $mocked_dav_helper, $mocked_obj, and $mocked_repo_helper.

Referenced by setUp().

54  {
56  // Dummy implementation
57  public function getChildCollectionType()
58  {
59  return null;
60  }
61  };
62  }
Class ilObjContainerDAV.
+ Here is the caller graph for this function:

Field Documentation

◆ $container_dav

ilObjContainerDAVTest::$container_dav
protected

Definition at line 25 of file ilObjContainerDAVTest.php.

◆ $mocked_dav_helper

ilObjContainerDAVTest::$mocked_dav_helper
protected

Definition at line 22 of file ilObjContainerDAVTest.php.

Referenced by setUpContainerDAV().

◆ $mocked_obj

ilObjContainerDAVTest::$mocked_obj
protected

Definition at line 16 of file ilObjContainerDAVTest.php.

Referenced by setUpContainerDAV().

◆ $mocked_repo_helper

ilObjContainerDAVTest::$mocked_repo_helper
protected

Definition at line 19 of file ilObjContainerDAVTest.php.

Referenced by setUpContainerDAV().

◆ $ref_id

ilObjContainerDAVTest::$ref_id
protected

Definition at line 13 of file ilObjContainerDAVTest.php.


The documentation for this class was generated from the following file: