xref: /plugin/davcal/vendor/sabre/dav/tests/Sabre/CalDAV/CalendarHomeTest.php (revision a1a3b6794e0e143a4a8b51d3185ce2d339be61ab)
1*a1a3b679SAndreas Boehler<?php
2*a1a3b679SAndreas Boehler
3*a1a3b679SAndreas Boehlernamespace Sabre\CalDAV;
4*a1a3b679SAndreas Boehler
5*a1a3b679SAndreas Boehleruse
6*a1a3b679SAndreas Boehler    Sabre\DAV,
7*a1a3b679SAndreas Boehler    Sabre\DAV\MkCol,
8*a1a3b679SAndreas Boehler    Sabre\DAVACL;
9*a1a3b679SAndreas Boehler
10*a1a3b679SAndreas Boehler
11*a1a3b679SAndreas Boehlerclass CalendarHomeTest extends \PHPUnit_Framework_TestCase {
12*a1a3b679SAndreas Boehler
13*a1a3b679SAndreas Boehler    /**
14*a1a3b679SAndreas Boehler     * @var Sabre\CalDAV\CalendarHome
15*a1a3b679SAndreas Boehler     */
16*a1a3b679SAndreas Boehler    protected $usercalendars;
17*a1a3b679SAndreas Boehler    /**
18*a1a3b679SAndreas Boehler     * @var Sabre\CalDAV\Backend\PDO
19*a1a3b679SAndreas Boehler     */
20*a1a3b679SAndreas Boehler    protected $backend;
21*a1a3b679SAndreas Boehler
22*a1a3b679SAndreas Boehler    function setup() {
23*a1a3b679SAndreas Boehler
24*a1a3b679SAndreas Boehler        if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available');
25*a1a3b679SAndreas Boehler        $this->backend = TestUtil::getBackend();
26*a1a3b679SAndreas Boehler        $this->usercalendars = new CalendarHome($this->backend, array(
27*a1a3b679SAndreas Boehler            'uri' => 'principals/user1'
28*a1a3b679SAndreas Boehler        ));
29*a1a3b679SAndreas Boehler
30*a1a3b679SAndreas Boehler    }
31*a1a3b679SAndreas Boehler
32*a1a3b679SAndreas Boehler    function testSimple() {
33*a1a3b679SAndreas Boehler
34*a1a3b679SAndreas Boehler        $this->assertEquals('user1',$this->usercalendars->getName());
35*a1a3b679SAndreas Boehler
36*a1a3b679SAndreas Boehler    }
37*a1a3b679SAndreas Boehler
38*a1a3b679SAndreas Boehler    /**
39*a1a3b679SAndreas Boehler     * @expectedException Sabre\DAV\Exception\NotFound
40*a1a3b679SAndreas Boehler     * @depends testSimple
41*a1a3b679SAndreas Boehler     */
42*a1a3b679SAndreas Boehler    function testGetChildNotFound() {
43*a1a3b679SAndreas Boehler
44*a1a3b679SAndreas Boehler        $this->usercalendars->getChild('randomname');
45*a1a3b679SAndreas Boehler
46*a1a3b679SAndreas Boehler    }
47*a1a3b679SAndreas Boehler
48*a1a3b679SAndreas Boehler    function testChildExists() {
49*a1a3b679SAndreas Boehler
50*a1a3b679SAndreas Boehler        $this->assertFalse($this->usercalendars->childExists('foo'));
51*a1a3b679SAndreas Boehler        $this->assertTrue($this->usercalendars->childExists('UUID-123467'));
52*a1a3b679SAndreas Boehler
53*a1a3b679SAndreas Boehler    }
54*a1a3b679SAndreas Boehler
55*a1a3b679SAndreas Boehler    function testGetOwner() {
56*a1a3b679SAndreas Boehler
57*a1a3b679SAndreas Boehler        $this->assertEquals('principals/user1', $this->usercalendars->getOwner());
58*a1a3b679SAndreas Boehler
59*a1a3b679SAndreas Boehler    }
60*a1a3b679SAndreas Boehler
61*a1a3b679SAndreas Boehler    function testGetGroup() {
62*a1a3b679SAndreas Boehler
63*a1a3b679SAndreas Boehler        $this->assertNull($this->usercalendars->getGroup());
64*a1a3b679SAndreas Boehler
65*a1a3b679SAndreas Boehler    }
66*a1a3b679SAndreas Boehler
67*a1a3b679SAndreas Boehler    function testGetACL() {
68*a1a3b679SAndreas Boehler
69*a1a3b679SAndreas Boehler        $expected = array(
70*a1a3b679SAndreas Boehler            array(
71*a1a3b679SAndreas Boehler                'privilege' => '{DAV:}read',
72*a1a3b679SAndreas Boehler                'principal' => 'principals/user1',
73*a1a3b679SAndreas Boehler                'protected' => true,
74*a1a3b679SAndreas Boehler            ),
75*a1a3b679SAndreas Boehler            array(
76*a1a3b679SAndreas Boehler                'privilege' => '{DAV:}write',
77*a1a3b679SAndreas Boehler                'principal' => 'principals/user1',
78*a1a3b679SAndreas Boehler                'protected' => true,
79*a1a3b679SAndreas Boehler            ),
80*a1a3b679SAndreas Boehler            array(
81*a1a3b679SAndreas Boehler                'privilege' => '{DAV:}read',
82*a1a3b679SAndreas Boehler                'principal' => 'principals/user1/calendar-proxy-write',
83*a1a3b679SAndreas Boehler                'protected' => true,
84*a1a3b679SAndreas Boehler            ),
85*a1a3b679SAndreas Boehler            array(
86*a1a3b679SAndreas Boehler                'privilege' => '{DAV:}write',
87*a1a3b679SAndreas Boehler                'principal' => 'principals/user1/calendar-proxy-write',
88*a1a3b679SAndreas Boehler                'protected' => true,
89*a1a3b679SAndreas Boehler            ),
90*a1a3b679SAndreas Boehler            array(
91*a1a3b679SAndreas Boehler                'privilege' => '{DAV:}read',
92*a1a3b679SAndreas Boehler                'principal' => 'principals/user1/calendar-proxy-read',
93*a1a3b679SAndreas Boehler                'protected' => true,
94*a1a3b679SAndreas Boehler            ),
95*a1a3b679SAndreas Boehler        );
96*a1a3b679SAndreas Boehler        $this->assertEquals($expected, $this->usercalendars->getACL());
97*a1a3b679SAndreas Boehler
98*a1a3b679SAndreas Boehler    }
99*a1a3b679SAndreas Boehler
100*a1a3b679SAndreas Boehler    /**
101*a1a3b679SAndreas Boehler     * @expectedException Sabre\DAV\Exception\MethodNotAllowed
102*a1a3b679SAndreas Boehler     */
103*a1a3b679SAndreas Boehler    function testSetACL() {
104*a1a3b679SAndreas Boehler
105*a1a3b679SAndreas Boehler        $this->usercalendars->setACL(array());
106*a1a3b679SAndreas Boehler
107*a1a3b679SAndreas Boehler    }
108*a1a3b679SAndreas Boehler
109*a1a3b679SAndreas Boehler    /**
110*a1a3b679SAndreas Boehler     * @expectedException Sabre\DAV\Exception\Forbidden
111*a1a3b679SAndreas Boehler     * @depends testSimple
112*a1a3b679SAndreas Boehler     */
113*a1a3b679SAndreas Boehler    function testSetName() {
114*a1a3b679SAndreas Boehler
115*a1a3b679SAndreas Boehler        $this->usercalendars->setName('bla');
116*a1a3b679SAndreas Boehler
117*a1a3b679SAndreas Boehler    }
118*a1a3b679SAndreas Boehler
119*a1a3b679SAndreas Boehler    /**
120*a1a3b679SAndreas Boehler     * @expectedException Sabre\DAV\Exception\Forbidden
121*a1a3b679SAndreas Boehler     * @depends testSimple
122*a1a3b679SAndreas Boehler     */
123*a1a3b679SAndreas Boehler    function testDelete() {
124*a1a3b679SAndreas Boehler
125*a1a3b679SAndreas Boehler        $this->usercalendars->delete();
126*a1a3b679SAndreas Boehler
127*a1a3b679SAndreas Boehler    }
128*a1a3b679SAndreas Boehler
129*a1a3b679SAndreas Boehler    /**
130*a1a3b679SAndreas Boehler     * @depends testSimple
131*a1a3b679SAndreas Boehler     */
132*a1a3b679SAndreas Boehler    function testGetLastModified() {
133*a1a3b679SAndreas Boehler
134*a1a3b679SAndreas Boehler        $this->assertNull($this->usercalendars->getLastModified());
135*a1a3b679SAndreas Boehler
136*a1a3b679SAndreas Boehler    }
137*a1a3b679SAndreas Boehler
138*a1a3b679SAndreas Boehler    /**
139*a1a3b679SAndreas Boehler     * @expectedException Sabre\DAV\Exception\MethodNotAllowed
140*a1a3b679SAndreas Boehler     * @depends testSimple
141*a1a3b679SAndreas Boehler     */
142*a1a3b679SAndreas Boehler    function testCreateFile() {
143*a1a3b679SAndreas Boehler
144*a1a3b679SAndreas Boehler        $this->usercalendars->createFile('bla');
145*a1a3b679SAndreas Boehler
146*a1a3b679SAndreas Boehler    }
147*a1a3b679SAndreas Boehler
148*a1a3b679SAndreas Boehler
149*a1a3b679SAndreas Boehler    /**
150*a1a3b679SAndreas Boehler     * @expectedException Sabre\DAV\Exception\MethodNotAllowed
151*a1a3b679SAndreas Boehler     * @depends testSimple
152*a1a3b679SAndreas Boehler     */
153*a1a3b679SAndreas Boehler    function testCreateDirectory() {
154*a1a3b679SAndreas Boehler
155*a1a3b679SAndreas Boehler        $this->usercalendars->createDirectory('bla');
156*a1a3b679SAndreas Boehler
157*a1a3b679SAndreas Boehler    }
158*a1a3b679SAndreas Boehler
159*a1a3b679SAndreas Boehler    /**
160*a1a3b679SAndreas Boehler     * @depends testSimple
161*a1a3b679SAndreas Boehler     */
162*a1a3b679SAndreas Boehler    function testCreateExtendedCollection() {
163*a1a3b679SAndreas Boehler
164*a1a3b679SAndreas Boehler        $mkCol = new MkCol(
165*a1a3b679SAndreas Boehler            ['{DAV:}collection', '{urn:ietf:params:xml:ns:caldav}calendar'],
166*a1a3b679SAndreas Boehler            []
167*a1a3b679SAndreas Boehler        );
168*a1a3b679SAndreas Boehler        $result = $this->usercalendars->createExtendedCollection('newcalendar', $mkCol);
169*a1a3b679SAndreas Boehler        $this->assertNull($result);
170*a1a3b679SAndreas Boehler        $cals = $this->backend->getCalendarsForUser('principals/user1');
171*a1a3b679SAndreas Boehler        $this->assertEquals(3,count($cals));
172*a1a3b679SAndreas Boehler
173*a1a3b679SAndreas Boehler    }
174*a1a3b679SAndreas Boehler
175*a1a3b679SAndreas Boehler    /**
176*a1a3b679SAndreas Boehler     * @expectedException Sabre\DAV\Exception\InvalidResourceType
177*a1a3b679SAndreas Boehler     * @depends testSimple
178*a1a3b679SAndreas Boehler     */
179*a1a3b679SAndreas Boehler    function testCreateExtendedCollectionBadResourceType() {
180*a1a3b679SAndreas Boehler
181*a1a3b679SAndreas Boehler        $mkCol = new MkCol(
182*a1a3b679SAndreas Boehler            ['{DAV:}collection', '{DAV:}blabla'],
183*a1a3b679SAndreas Boehler            []
184*a1a3b679SAndreas Boehler        );
185*a1a3b679SAndreas Boehler        $this->usercalendars->createExtendedCollection('newcalendar', $mkCol);
186*a1a3b679SAndreas Boehler
187*a1a3b679SAndreas Boehler    }
188*a1a3b679SAndreas Boehler
189*a1a3b679SAndreas Boehler    /**
190*a1a3b679SAndreas Boehler     * @expectedException Sabre\DAV\Exception\InvalidResourceType
191*a1a3b679SAndreas Boehler     * @depends testSimple
192*a1a3b679SAndreas Boehler     */
193*a1a3b679SAndreas Boehler    function testCreateExtendedCollectionNotACalendar() {
194*a1a3b679SAndreas Boehler
195*a1a3b679SAndreas Boehler        $mkCol = new MkCol(
196*a1a3b679SAndreas Boehler            ['{DAV:}collection'],
197*a1a3b679SAndreas Boehler            []
198*a1a3b679SAndreas Boehler        );
199*a1a3b679SAndreas Boehler        $this->usercalendars->createExtendedCollection('newcalendar', $mkCol);
200*a1a3b679SAndreas Boehler
201*a1a3b679SAndreas Boehler    }
202*a1a3b679SAndreas Boehler
203*a1a3b679SAndreas Boehler    function testGetSupportedPrivilegesSet() {
204*a1a3b679SAndreas Boehler
205*a1a3b679SAndreas Boehler        $this->assertNull($this->usercalendars->getSupportedPrivilegeSet());
206*a1a3b679SAndreas Boehler
207*a1a3b679SAndreas Boehler    }
208*a1a3b679SAndreas Boehler
209*a1a3b679SAndreas Boehler    /**
210*a1a3b679SAndreas Boehler     * @expectedException Sabre\DAV\Exception\NotImplemented
211*a1a3b679SAndreas Boehler     */
212*a1a3b679SAndreas Boehler    function testShareReplyFail() {
213*a1a3b679SAndreas Boehler
214*a1a3b679SAndreas Boehler        $this->usercalendars->shareReply('uri', SharingPlugin::STATUS_DECLINED, 'curi', '1');
215*a1a3b679SAndreas Boehler
216*a1a3b679SAndreas Boehler    }
217*a1a3b679SAndreas Boehler
218*a1a3b679SAndreas Boehler}
219