ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilObjectDAVTest.php
Go to the documentation of this file.
1<?php
2use\PHPUnit\Framework\TestCase;
3use Sabre\DAV\Exception\Forbidden;
4
5require_once('./libs/composer/vendor/autoload.php');
6
28{
30 protected $ref_id;
31
33 protected $mocked_obj;
34
37
40
42 protected $dav_obj;
43
44
48 protected function setUp()
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 }
66
70 protected function setUpObjectDAV($mocked_obj, $mocked_repo_helper, $mockes_dav_helper)
71 {
72 return new class($mocked_obj, $mocked_repo_helper, $mockes_dav_helper) extends ilObjectDAV {
73 };
74 }
75
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 }
101
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 }
128
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 }
155
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 }
177}
An exception for terminatinating execution or to throw for unit testing.
TestCase for the ilObjectDAVTest.
setName_EverythingFine_SetTitleForObject()
Requirements:
setName_ForbiddenCharacters_ThrowForbidden()
setUpObjectDAV($mocked_obj, $mocked_repo_helper, $mockes_dav_helper)
Setup instance for ilObjectDAV.
delete_WithoutPermission_ThrowForbidden()
setName_NoWriteAccess_ThrowForbidden()
Class ilObjectDAV.