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

TestCase for the ilObjectDAVTest. More...

+ Inheritance diagram for ilObjectDAVTest:
+ Collaboration diagram for ilObjectDAVTest:

Public Member Functions

 setName_NoWriteAccess_ThrowForbidden ()
 
 setName_ForbiddenCharacters_ThrowForbidden ()
 
 setName_EverythingFine_SetTitleForObject ()
 Requirements: More...
 
 delete_WithoutPermission_ThrowForbidden ()
 

Protected Member Functions

 setUp ()
 Setup. More...
 
 setUpObjectDAV ($mocked_obj, $mocked_repo_helper, $mockes_dav_helper)
 Setup instance for ilObjectDAV. More...
 

Protected Attributes

 $ref_id
 
 $mocked_obj
 
 $mocked_dav_repo_helper
 
 $mocked_dav_obj_helper
 
 $dav_obj
 

Detailed Description

TestCase for the ilObjectDAVTest.

I name the test-methods like this: MethodName_TestedBehavior_Expectation

For example setName_NoWriteAccess_ThrowForbidden means:

  • I test the method setName
  • I will test the behavior if I dont have write access to this object
  • I expect a Forbidden-Exception
Author
Raphael Heer rapha.nosp@m.el.h.nosp@m.eer@h.nosp@m.slu..nosp@m.ch
Version
1.0.0

needsInstalledILIAS

disabled disabled disabled

Definition at line 27 of file ilObjectDAVTest.php.

Member Function Documentation

◆ delete_WithoutPermission_ThrowForbidden()

ilObjectDAVTest::delete_WithoutPermission_ThrowForbidden ( )
Test:

Definition at line 160 of file ilObjectDAVTest.php.

161  {
162  // Arrange
163  $exception_thrown = false;
164 
165  $this->mocked_dav_repo_helper->shouldReceive('checkAccess')->withAnyArgs()->andReturn(false);
166 
167  // Act
168  try {
169  $this->dav_obj->delete();
170  } catch (Forbidden $e) {
171  $exception_thrown = $e->getMessage() == "Permission denied";
172  }
173 
174  // Assert
175  $this->assertTrue($exception_thrown);
176  }

◆ setName_EverythingFine_SetTitleForObject()

ilObjectDAVTest::setName_EverythingFine_SetTitleForObject ( )

Requirements:

  • Write permission for this object
  • No forbidden characters in title
Test:

Definition at line 137 of file ilObjectDAVTest.php.

References $title.

138  {
139  // Arrange
140  $title = 'Test';
141 
142  $this->mocked_dav_repo_helper->shouldReceive('checkAccess')->withAnyArgs()->andReturn(true);
143  $this->mocked_dav_obj_helper->shouldReceive('isDAVableObjTitle')->with($title)->andReturn(true);
144 
145  $this->mocked_obj->shouldReceive('setTitle')->withArgs([$title]);
146  $this->mocked_obj->shouldReceive('update');
147 
148  // Act
149  $this->dav_obj->setName($title);
150 
151  // Assert
152  $this->assertTrue($this->mocked_obj->shouldHaveReceived('setTitle')->withArgs([$title])
153  && $this->mocked_obj->shouldHaveReceived('update'));
154  }

◆ setName_ForbiddenCharacters_ThrowForbidden()

ilObjectDAVTest::setName_ForbiddenCharacters_ThrowForbidden ( )
Test:

Definition at line 106 of file ilObjectDAVTest.php.

References $title.

107  {
108  // Arrange
109  $exception_thrown = false;
110  $title = 'Test';
111 
112  $this->mocked_dav_repo_helper->shouldReceive('checkAccess')->withAnyArgs()->andReturn(true);
113  $this->mocked_dav_obj_helper->shouldReceive('isDAVableObjTitle')->with($title)->andReturn(false);
114 
115  $this->mocked_obj = \Mockery::mock('ilObject');
116  $this->mocked_obj->shouldNotReceive('setTitle');
117 
118  // Act
119  try {
120  $this->dav_obj->setName($title);
121  } catch (Forbidden $e) {
122  $exception_thrown = $e->getMessage() == 'Forbidden characters in title';
123  }
124 
125  // Assert
126  $this->assertTrue($exception_thrown);
127  }

◆ setName_NoWriteAccess_ThrowForbidden()

ilObjectDAVTest::setName_NoWriteAccess_ThrowForbidden ( )
Test:

Definition at line 80 of file ilObjectDAVTest.php.

References $title.

81  {
82  // Arrange
83  $exception_thrown = false;
84  $title = 'Test';
85 
86  $this->mocked_dav_repo_helper->shouldReceive('checkAccess')->withArgs(['write', $this->ref_id])->andReturn(false);
87 
88  $this->mocked_obj->shouldNotReceive('setTitle');
89 
90 
91  // Act
92  try {
93  $this->dav_obj->setName($title);
94  } catch (Forbidden $e) {
95  $exception_thrown = $e->getMessage() == 'Permission denied';
96  }
97 
98  // Assert
99  $this->assertTrue($exception_thrown);
100  }

◆ setUp()

ilObjectDAVTest::setUp ( )
protected

Setup.

Definition at line 48 of file ilObjectDAVTest.php.

References setUpObjectDAV().

49  {
50  require_once('./Services/WebDAV/classes/dav/class.ilObjectDAV.php');
51  require_once('./Services/WebDAV/classes/class.ilWebDAVRepositoryHelper.php');
52  require_once('./Services/WebDAV/classes/class.ilWebDAVObjDAVHelper.php');
53 
54  $this->ref_id = 100;
55  $this->mocked_obj = \Mockery::mock('ilObject');
56  $this->mocked_obj->shouldReceive(['getRefId' => $this->ref_id]);
57 
58  $this->mocked_dav_obj_helper = \Mockery::mock('ilWebDAVObjDAVHelper');
59 
60  $this->mocked_dav_repo_helper = \Mockery::mock('ilWebDAVRepositoryHelper');
61 
62  $this->dav_obj = $this->setUpObjectDAV($this->mocked_obj, $this->mocked_dav_repo_helper, $this->mocked_dav_obj_helper);
63 
64  parent::setUp();
65  }
setUpObjectDAV($mocked_obj, $mocked_repo_helper, $mockes_dav_helper)
Setup instance for ilObjectDAV.
+ Here is the call graph for this function:

◆ setUpObjectDAV()

ilObjectDAVTest::setUpObjectDAV (   $mocked_obj,
  $mocked_repo_helper,
  $mockes_dav_helper 
)
protected

Setup instance for ilObjectDAV.

Definition at line 70 of file ilObjectDAVTest.php.

References $mocked_obj.

Referenced by setUp().

71  {
72  return new class($mocked_obj, $mocked_repo_helper, $mockes_dav_helper) extends ilObjectDAV {
73  };
74  }
Class ilObjectDAV.
+ Here is the caller graph for this function:

Field Documentation

◆ $dav_obj

ilObjectDAVTest::$dav_obj
protected

Definition at line 42 of file ilObjectDAVTest.php.

◆ $mocked_dav_obj_helper

ilObjectDAVTest::$mocked_dav_obj_helper
protected

Definition at line 39 of file ilObjectDAVTest.php.

◆ $mocked_dav_repo_helper

ilObjectDAVTest::$mocked_dav_repo_helper
protected

Definition at line 36 of file ilObjectDAVTest.php.

◆ $mocked_obj

ilObjectDAVTest::$mocked_obj
protected

Definition at line 33 of file ilObjectDAVTest.php.

Referenced by setUpObjectDAV().

◆ $ref_id

ilObjectDAVTest::$ref_id
protected

Definition at line 30 of file ilObjectDAVTest.php.


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