1<?php 2 3namespace Sabre\CalDAV; 4 5use Sabre\DAVACL; 6 7class SharedCalendarTest extends \PHPUnit_Framework_TestCase { 8 9 protected $backend; 10 11 function getInstance(array $props = null) { 12 13 if (is_null($props)) { 14 $props = array( 15 'id' => 1, 16 '{http://calendarserver.org/ns/}shared-url' => 'calendars/owner/original', 17 '{http://sabredav.org/ns}owner-principal' => 'principals/owner', 18 '{http://sabredav.org/ns}read-only' => false, 19 'principaluri' => 'principals/sharee', 20 ); 21 } 22 23 $this->backend = new Backend\MockSharing( 24 array($props), 25 array(), 26 array() 27 ); 28 $this->backend->updateShares(1, array( 29 array( 30 'href' => 'mailto:removeme@example.org', 31 'commonName' => 'To be removed', 32 'readOnly' => true, 33 ), 34 ), array()); 35 36 return new SharedCalendar($this->backend, $props); 37 38 } 39 40 function testGetSharedUrl() { 41 $this->assertEquals('calendars/owner/original', $this->getInstance()->getSharedUrl()); 42 } 43 44 function testGetShares() { 45 46 $this->assertEquals(array(array( 47 'href' => 'mailto:removeme@example.org', 48 'commonName' => 'To be removed', 49 'readOnly' => true, 50 'status' => SharingPlugin::STATUS_NORESPONSE, 51 )), $this->getInstance()->getShares()); 52 53 } 54 55 function testGetOwner() { 56 $this->assertEquals('principals/owner', $this->getInstance()->getOwner()); 57 } 58 59 function testGetACL() { 60 61 $expected = array( 62 array( 63 'privilege' => '{DAV:}read', 64 'principal' => 'principals/owner', 65 'protected' => true, 66 ), 67 68 array( 69 'privilege' => '{DAV:}read', 70 'principal' => 'principals/owner/calendar-proxy-write', 71 'protected' => true, 72 ), 73 array( 74 'privilege' => '{DAV:}read', 75 'principal' => 'principals/owner/calendar-proxy-read', 76 'protected' => true, 77 ), 78 array( 79 'privilege' => '{' . Plugin::NS_CALDAV . '}read-free-busy', 80 'principal' => '{DAV:}authenticated', 81 'protected' => true, 82 ), 83 array( 84 'privilege' => '{DAV:}write', 85 'principal' => 'principals/owner', 86 'protected' => true, 87 ), 88 array( 89 'privilege' => '{DAV:}write', 90 'principal' => 'principals/owner/calendar-proxy-write', 91 'protected' => true, 92 ), 93 array( 94 'privilege' => '{DAV:}read', 95 'principal' => 'principals/sharee', 96 'protected' => true, 97 ), 98 array( 99 'privilege' => '{DAV:}write', 100 'principal' => 'principals/sharee', 101 'protected' => true, 102 ), 103 ); 104 105 $this->assertEquals($expected, $this->getInstance()->getACL()); 106 107 } 108 109 function testGetChildACL() { 110 111 $expected = array( 112 array( 113 'privilege' => '{DAV:}read', 114 'principal' => 'principals/owner', 115 'protected' => true, 116 ), 117 array( 118 'privilege' => '{DAV:}read', 119 'principal' => 'principals/owner/calendar-proxy-write', 120 'protected' => true, 121 ), 122 array( 123 'privilege' => '{DAV:}read', 124 'principal' => 'principals/owner/calendar-proxy-read', 125 'protected' => true, 126 ), 127 array( 128 'privilege' => '{DAV:}write', 129 'principal' => 'principals/owner', 130 'protected' => true, 131 ), 132 array( 133 'privilege' => '{DAV:}write', 134 'principal' => 'principals/owner/calendar-proxy-write', 135 'protected' => true, 136 ), 137 array( 138 'privilege' => '{DAV:}read', 139 'principal' => 'principals/sharee', 140 'protected' => true, 141 ), 142 array( 143 'privilege' => '{DAV:}write', 144 'principal' => 'principals/sharee', 145 'protected' => true, 146 ), 147 ); 148 149 $this->assertEquals($expected, $this->getInstance()->getChildACL()); 150 151 } 152 153 function testGetChildACLReadOnly() { 154 155 $expected = array( 156 array( 157 'privilege' => '{DAV:}read', 158 'principal' => 'principals/owner', 159 'protected' => true, 160 ), 161 array( 162 'privilege' => '{DAV:}read', 163 'principal' => 'principals/owner/calendar-proxy-write', 164 'protected' => true, 165 ), 166 array( 167 'privilege' => '{DAV:}read', 168 'principal' => 'principals/owner/calendar-proxy-read', 169 'protected' => true, 170 ), 171 array( 172 'privilege' => '{DAV:}read', 173 'principal' => 'principals/sharee', 174 'protected' => true, 175 ), 176 ); 177 178 $props = array( 179 'id' => 1, 180 '{http://calendarserver.org/ns/}shared-url' => 'calendars/owner/original', 181 '{http://sabredav.org/ns}owner-principal' => 'principals/owner', 182 '{http://sabredav.org/ns}read-only' => true, 183 'principaluri' => 'principals/sharee', 184 ); 185 $this->assertEquals($expected, $this->getInstance($props)->getChildACL()); 186 187 } 188 189 /** 190 * @expectedException InvalidArgumentException 191 */ 192 public function testCreateInstanceMissingArg() { 193 194 $this->getInstance(array( 195 'id' => 1, 196 '{http://calendarserver.org/ns/}shared-url' => 'calendars/owner/original', 197 '{http://sabredav.org/ns}read-only' => false, 198 'principaluri' => 'principals/sharee', 199 )); 200 201 } 202 203} 204