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