]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/DAV/BasicNodeTest.php
Initial Release of the calendar plugin
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / DAV / BasicNodeTest.php
1 <?php
2
3 class Sabre_DAV_BasicNodeTest extends PHPUnit_Framework_TestCase {
4
5     /**
6      * @expectedException Sabre_DAV_Exception_Forbidden
7      */
8     public function testPut() {
9
10         $file = new Sabre_DAV_FileMock();
11         $file->put('hi');
12
13     }
14
15     /**
16      * @expectedException Sabre_DAV_Exception_Forbidden
17      */
18     public function testGet() {
19
20         $file = new Sabre_DAV_FileMock();
21         $file->get();
22
23     }
24
25     public function testGetSize() {
26
27         $file = new Sabre_DAV_FileMock();
28         $this->assertEquals(0,$file->getSize());
29
30     }
31
32
33     public function testGetETag() {
34
35         $file = new Sabre_DAV_FileMock();
36         $this->assertNull($file->getETag());
37
38     }
39
40     public function testGetContentType() {
41
42         $file = new Sabre_DAV_FileMock();
43         $this->assertNull($file->getContentType());
44
45     }
46
47     /**
48      * @expectedException Sabre_DAV_Exception_Forbidden
49      */
50     public function testDelete() {
51
52         $file = new Sabre_DAV_FileMock();
53         $file->delete();
54
55     }
56
57     /**
58      * @expectedException Sabre_DAV_Exception_Forbidden
59      */
60     public function testSetName() {
61
62         $file = new Sabre_DAV_FileMock();
63         $file->setName('hi');
64
65     }
66
67     public function testGetLastModified() {
68
69         $file = new Sabre_DAV_FileMock();
70         // checking if lastmod is within the range of a few seconds
71         $lastMod = $file->getLastModified();
72         $compareTime = ($lastMod + 1)-time();
73         $this->assertTrue($compareTime < 3);
74
75     }
76
77     public function testGetChild() {
78
79         $dir = new Sabre_DAV_DirectoryMock();
80         $file = $dir->getChild('mockfile');
81         $this->assertTrue($file instanceof Sabre_DAV_FileMock);
82
83     }
84
85     public function testChildExists() {
86
87         $dir = new Sabre_DAV_DirectoryMock();
88         $this->assertTrue($dir->childExists('mockfile'));
89
90     }
91
92     public function testChildExistsFalse() {
93
94         $dir = new Sabre_DAV_DirectoryMock();
95         $this->assertFalse($dir->childExists('mockfile2'));
96
97     }
98
99     /**
100      * @expectedException Sabre_DAV_Exception_NotFound
101      */
102     public function testGetChild404() {
103
104         $dir = new Sabre_DAV_DirectoryMock();
105         $file = $dir->getChild('blabla');
106
107     }
108
109     /**
110      * @expectedException Sabre_DAV_Exception_Forbidden
111      */
112     public function testCreateFile() {
113
114         $dir = new Sabre_DAV_DirectoryMock();
115         $dir->createFile('hello','data');
116
117     }
118
119     /**
120      * @expectedException Sabre_DAV_Exception_Forbidden
121      */
122     public function testCreateDirectory() {
123
124         $dir = new Sabre_DAV_DirectoryMock();
125         $dir->createDirectory('hello');
126
127     }
128
129     public function testSimpleDirectoryConstruct() {
130
131         $dir = new Sabre_DAV_SimpleCollection('simpledir',array());
132
133     }
134
135     /**
136      * @depends testSimpleDirectoryConstruct
137      */
138     public function testSimpleDirectoryConstructChild() {
139
140         $file = new Sabre_DAV_FileMock();
141         $dir = new Sabre_DAV_SimpleCollection('simpledir',array($file));
142         $file2 = $dir->getChild('mockfile');
143
144         $this->assertEquals($file,$file2);
145
146     }
147
148     /**
149      * @expectedException Sabre_DAV_Exception
150      * @depends testSimpleDirectoryConstruct
151      */
152     public function testSimpleDirectoryBadParam() {
153
154         $dir = new Sabre_DAV_SimpleCollection('simpledir',array('string shouldn\'t be here'));
155
156     }
157
158     /**
159      * @depends testSimpleDirectoryConstruct
160      */
161     public function testSimpleDirectoryAddChild() {
162
163         $file = new Sabre_DAV_FileMock();
164         $dir = new Sabre_DAV_SimpleCollection('simpledir');
165         $dir->addChild($file);
166         $file2 = $dir->getChild('mockfile');
167
168         $this->assertEquals($file,$file2);
169
170     }
171
172     /**
173      * @depends testSimpleDirectoryConstruct
174      * @depends testSimpleDirectoryAddChild
175      */
176     public function testSimpleDirectoryGetChildren() {
177
178         $file = new Sabre_DAV_FileMock();
179         $dir = new Sabre_DAV_SimpleCollection('simpledir');
180         $dir->addChild($file);
181
182         $this->assertEquals(array($file),$dir->getChildren());
183
184     }
185
186     /*
187      * @depends testSimpleDirectoryConstruct
188      */
189     public function testSimpleDirectoryGetName() {
190
191         $dir = new Sabre_DAV_SimpleCollection('simpledir');
192         $this->assertEquals('simpledir',$dir->getName());
193
194     }
195
196     /**
197      * @depends testSimpleDirectoryConstruct
198      * @expectedException Sabre_DAV_Exception_NotFound
199      */
200     public function testSimpleDirectoryGetChild404() {
201
202         $dir = new Sabre_DAV_SimpleCollection('simpledir');
203         $dir->getChild('blabla');
204
205     }
206 }
207
208 class Sabre_DAV_DirectoryMock extends Sabre_DAV_Collection {
209
210     function getName() {
211
212         return 'mockdir';
213
214     }
215
216     function getChildren() {
217
218         return array(new Sabre_DAV_FileMock());
219
220     }
221
222 }
223
224 class Sabre_DAV_FileMock extends Sabre_DAV_File {
225
226     function getName() {
227
228         return 'mockfile';
229
230     }
231
232 }