1<?php 2 3namespace Sabre\CalDAV\Schedule; 4use Sabre\CalDAV; 5use Sabre\DAV; 6 7class InboxTest extends \PHPUnit_Framework_TestCase { 8 9 function testSetup() { 10 11 $inbox = new Inbox( 12 new CalDAV\Backend\MockScheduling(), 13 'principals/user1' 14 ); 15 $this->assertEquals('inbox', $inbox->getName()); 16 $this->assertEquals(array(), $inbox->getChildren()); 17 $this->assertEquals('principals/user1', $inbox->getOwner()); 18 $this->assertEquals(null, $inbox->getGroup()); 19 20 $this->assertEquals(array( 21 array( 22 'privilege' => '{DAV:}read', 23 'principal' => 'principals/user1', 24 'protected' => true, 25 ), 26 array( 27 'privilege' => '{DAV:}write-properties', 28 'principal' => 'principals/user1', 29 'protected' => true, 30 ), 31 array( 32 'privilege' => '{DAV:}unbind', 33 'principal' => 'principals/user1', 34 'protected' => true, 35 ), 36 array( 37 'privilege' => '{DAV:}read', 38 'principal' => 'principals/user1/calendar-proxy-read', 39 'protected' => true, 40 ), 41 array( 42 'privilege' => '{DAV:}read', 43 'principal' => 'principals/user1/calendar-proxy-write', 44 'protected' => true, 45 ), 46 array( 47 'privilege' => '{DAV:}unbind', 48 'principal' => 'principals/user1/calendar-proxy-write', 49 'protected' => true, 50 ), 51 array( 52 'privilege' => '{urn:ietf:params:xml:ns:caldav}schedule-deliver-invite', 53 'principal' => '{DAV:}authenticated', 54 'protected' => true, 55 ), 56 array( 57 'privilege' => '{urn:ietf:params:xml:ns:caldav}schedule-deliver-reply', 58 'principal' => '{DAV:}authenticated', 59 'protected' => true, 60 ), 61 ), $inbox->getACL()); 62 63 $ok = false; 64 try { 65 $inbox->setACL(array()); 66 } catch (DAV\Exception\MethodNotAllowed $e) { 67 $ok = true; 68 } 69 if (!$ok) { 70 $this->fail('Exception was not emitted'); 71 } 72 73 } 74 75 function testGetSupportedPrivilegeSet() { 76 77 $inbox = new Inbox( 78 new CalDAV\Backend\MockScheduling(), 79 'principals/user1' 80 ); 81 $r = $inbox->getSupportedPrivilegeSet(); 82 83 $ok = 0; 84 foreach($r['aggregates'] as $priv) { 85 86 if ($priv['privilege'] == '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-deliver') { 87 $ok++; 88 foreach($priv['aggregates'] as $subpriv) { 89 if ($subpriv['privilege'] == '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-deliver-invite') { 90 $ok++; 91 } 92 if ($subpriv['privilege'] == '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-deliver-reply') { 93 $ok++; 94 } 95 } 96 } 97 } 98 99 $this->assertEquals(3, $ok, "We're missing one or more privileges"); 100 101 } 102 103 /** 104 * @depends testSetup 105 */ 106 function testGetChildren() { 107 108 $backend = new CalDAV\Backend\MockScheduling(); 109 $inbox = new Inbox( 110 $backend, 111 'principals/user1' 112 ); 113 114 $this->assertEquals( 115 0, 116 count($inbox->getChildren()) 117 ); 118 $backend->createSchedulingObject('principals/user1', 'schedule1.ics', "BEGIN:VCALENDAR\r\nEND:VCALENDAR"); 119 $this->assertEquals( 120 1, 121 count($inbox->getChildren()) 122 ); 123 $this->assertInstanceOf('Sabre\CalDAV\Schedule\SchedulingObject', $inbox->getChildren()[0]); 124 $this->assertEquals( 125 'schedule1.ics', 126 $inbox->getChildren()[0]->getName() 127 ); 128 129 } 130 131 /** 132 * @depends testGetChildren 133 */ 134 function testCreateFile() { 135 136 $backend = new CalDAV\Backend\MockScheduling(); 137 $inbox = new Inbox( 138 $backend, 139 'principals/user1' 140 ); 141 142 $this->assertEquals( 143 0, 144 count($inbox->getChildren()) 145 ); 146 $inbox->createFile('schedule1.ics', "BEGIN:VCALENDAR\r\nEND:VCALENDAR"); 147 $this->assertEquals( 148 1, 149 count($inbox->getChildren()) 150 ); 151 $this->assertInstanceOf('Sabre\CalDAV\Schedule\SchedulingObject', $inbox->getChildren()[0]); 152 $this->assertEquals( 153 'schedule1.ics', 154 $inbox->getChildren()[0]->getName() 155 ); 156 157 } 158 159 /** 160 * @depends testSetup 161 */ 162 function testCalendarQuery() { 163 164 $backend = new CalDAV\Backend\MockScheduling(); 165 $inbox = new Inbox( 166 $backend, 167 'principals/user1' 168 ); 169 170 $this->assertEquals( 171 0, 172 count($inbox->getChildren()) 173 ); 174 $backend->createSchedulingObject('principals/user1', 'schedule1.ics', "BEGIN:VCALENDAR\r\nEND:VCALENDAR"); 175 $this->assertEquals( 176 ['schedule1.ics'], 177 $inbox->calendarQuery([ 178 'name' => 'VCALENDAR', 179 'comp-filters' => [], 180 'prop-filters' => [], 181 'is-not-defined' => false 182 ]) 183 ); 184 185 } 186} 187