1<?php
2
3namespace Sabre\CalDAV\Schedule;
4
5use Sabre\CalDAV;
6use Sabre\DAV;
7
8class InboxTest extends \PHPUnit_Framework_TestCase {
9
10    function testSetup() {
11
12        $inbox = new Inbox(
13            new CalDAV\Backend\MockScheduling(),
14            'principals/user1'
15        );
16        $this->assertEquals('inbox', $inbox->getName());
17        $this->assertEquals([], $inbox->getChildren());
18        $this->assertEquals('principals/user1', $inbox->getOwner());
19        $this->assertEquals(null, $inbox->getGroup());
20
21        $this->assertEquals([
22            [
23                'privilege' => '{DAV:}read',
24                'principal' => '{DAV:}authenticated',
25                'protected' => true,
26            ],
27            [
28                'privilege' => '{DAV:}write-properties',
29                'principal' => 'principals/user1',
30                'protected' => true,
31            ],
32            [
33                'privilege' => '{DAV:}unbind',
34                'principal' => 'principals/user1',
35                'protected' => true,
36            ],
37            [
38                'privilege' => '{DAV:}unbind',
39                'principal' => 'principals/user1/calendar-proxy-write',
40                'protected' => true,
41            ],
42            [
43                'privilege' => '{urn:ietf:params:xml:ns:caldav}schedule-deliver',
44                'principal' => '{DAV:}authenticated',
45                'protected' => true,
46            ],
47        ], $inbox->getACL());
48
49        $ok = false;
50
51    }
52
53    /**
54     * @depends testSetup
55     */
56    function testGetChildren() {
57
58        $backend = new CalDAV\Backend\MockScheduling();
59        $inbox = new Inbox(
60            $backend,
61            'principals/user1'
62        );
63
64        $this->assertEquals(
65            0,
66            count($inbox->getChildren())
67        );
68        $backend->createSchedulingObject('principals/user1', 'schedule1.ics', "BEGIN:VCALENDAR\r\nEND:VCALENDAR");
69        $this->assertEquals(
70            1,
71            count($inbox->getChildren())
72        );
73        $this->assertInstanceOf('Sabre\CalDAV\Schedule\SchedulingObject', $inbox->getChildren()[0]);
74        $this->assertEquals(
75            'schedule1.ics',
76            $inbox->getChildren()[0]->getName()
77        );
78
79    }
80
81    /**
82     * @depends testGetChildren
83     */
84    function testCreateFile() {
85
86        $backend = new CalDAV\Backend\MockScheduling();
87        $inbox = new Inbox(
88            $backend,
89            'principals/user1'
90        );
91
92        $this->assertEquals(
93            0,
94            count($inbox->getChildren())
95        );
96        $inbox->createFile('schedule1.ics', "BEGIN:VCALENDAR\r\nEND:VCALENDAR");
97        $this->assertEquals(
98            1,
99            count($inbox->getChildren())
100        );
101        $this->assertInstanceOf('Sabre\CalDAV\Schedule\SchedulingObject', $inbox->getChildren()[0]);
102        $this->assertEquals(
103            'schedule1.ics',
104            $inbox->getChildren()[0]->getName()
105        );
106
107    }
108
109    /**
110     * @depends testSetup
111     */
112    function testCalendarQuery() {
113
114        $backend = new CalDAV\Backend\MockScheduling();
115        $inbox = new Inbox(
116            $backend,
117            'principals/user1'
118        );
119
120        $this->assertEquals(
121            0,
122            count($inbox->getChildren())
123        );
124        $backend->createSchedulingObject('principals/user1', 'schedule1.ics', "BEGIN:VCALENDAR\r\nEND:VCALENDAR");
125        $this->assertEquals(
126            ['schedule1.ics'],
127            $inbox->calendarQuery([
128                'name'           => 'VCALENDAR',
129                'comp-filters'   => [],
130                'prop-filters'   => [],
131                'is-not-defined' => false
132            ])
133        );
134
135    }
136}
137