1<?php 2 3namespace Sabre\CalDAV\Xml\Notification; 4 5use Sabre\CalDAV; 6use Sabre\DAV; 7use Sabre\Xml\Writer; 8 9class InviteTest extends DAV\Xml\XmlTest { 10 11 /** 12 * @dataProvider dataProvider 13 */ 14 function testSerializers($notification, $expected) { 15 16 $notification = new Invite($notification); 17 18 $this->assertEquals('foo', $notification->getId()); 19 $this->assertEquals('"1"', $notification->getETag()); 20 21 $simpleExpected = '<cs:invite-notification xmlns:d="DAV:" xmlns:cs="http://calendarserver.org/ns/" />' . "\n"; 22 $this->namespaceMap['http://calendarserver.org/ns/'] = 'cs'; 23 24 $xml = $this->write($notification); 25 26 $this->assertXmlStringEqualsXmlString($simpleExpected, $xml); 27 28 $this->namespaceMap['urn:ietf:params:xml:ns:caldav'] = 'cal'; 29 $xml = $this->writeFull($notification); 30 31 $this->assertXmlStringEqualsXmlString($expected, $xml); 32 33 34 } 35 36 function dataProvider() { 37 38 $dtStamp = new \DateTime('2012-01-01 00:00:00', new \DateTimeZone('GMT')); 39 return array( 40 array( 41 array( 42 'id' => 'foo', 43 'dtStamp' => $dtStamp, 44 'etag' => '"1"', 45 'href' => 'mailto:foo@example.org', 46 'type' => CalDAV\SharingPlugin::STATUS_ACCEPTED, 47 'readOnly' => true, 48 'hostUrl' => 'calendar', 49 'organizer' => 'principal/user1', 50 'commonName' => 'John Doe', 51 'summary' => 'Awesome stuff!' 52 ), 53<<<FOO 54<?xml version="1.0" encoding="UTF-8"?> 55<cs:root xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:" xmlns:cal="urn:ietf:params:xml:ns:caldav"> 56 <cs:dtstamp>20120101T000000Z</cs:dtstamp> 57 <cs:invite-notification> 58 <cs:uid>foo</cs:uid> 59 <d:href>mailto:foo@example.org</d:href> 60 <cs:invite-accepted/> 61 <cs:hosturl> 62 <d:href>/calendar</d:href> 63 </cs:hosturl> 64 <cs:summary>Awesome stuff!</cs:summary> 65 <cs:access> 66 <cs:read/> 67 </cs:access> 68 <cs:organizer> 69 <d:href>/principal/user1</d:href> 70 <cs:common-name>John Doe</cs:common-name> 71 </cs:organizer> 72 <cs:organizer-cn>John Doe</cs:organizer-cn> 73 </cs:invite-notification> 74</cs:root> 75 76FOO 77 ), 78 array( 79 array( 80 'id' => 'foo', 81 'dtStamp' => $dtStamp, 82 'etag' => '"1"', 83 'href' => 'mailto:foo@example.org', 84 'type' => CalDAV\SharingPlugin::STATUS_DECLINED, 85 'readOnly' => true, 86 'hostUrl' => 'calendar', 87 'organizer' => 'principal/user1', 88 'commonName' => 'John Doe', 89 ), 90<<<FOO 91<?xml version="1.0" encoding="UTF-8"?> 92<cs:root xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:" xmlns:cal="urn:ietf:params:xml:ns:caldav"> 93 <cs:dtstamp>20120101T000000Z</cs:dtstamp> 94 <cs:invite-notification> 95 <cs:uid>foo</cs:uid> 96 <d:href>mailto:foo@example.org</d:href> 97 <cs:invite-declined/> 98 <cs:hosturl> 99 <d:href>/calendar</d:href> 100 </cs:hosturl> 101 <cs:access> 102 <cs:read/> 103 </cs:access> 104 <cs:organizer> 105 <d:href>/principal/user1</d:href> 106 <cs:common-name>John Doe</cs:common-name> 107 </cs:organizer> 108 <cs:organizer-cn>John Doe</cs:organizer-cn> 109 </cs:invite-notification> 110</cs:root> 111FOO 112 ), 113 array( 114 array( 115 'id' => 'foo', 116 'dtStamp' => $dtStamp, 117 'etag' => '"1"', 118 'href' => 'mailto:foo@example.org', 119 'type' => CalDAV\SharingPlugin::STATUS_NORESPONSE, 120 'readOnly' => true, 121 'hostUrl' => 'calendar', 122 'organizer' => 'principal/user1', 123 'firstName' => 'Foo', 124 'lastName' => 'Bar', 125 ), 126<<<FOO 127<?xml version="1.0" encoding="UTF-8"?> 128<cs:root xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:" xmlns:cal="urn:ietf:params:xml:ns:caldav"> 129 <cs:dtstamp>20120101T000000Z</cs:dtstamp> 130 <cs:invite-notification> 131 <cs:uid>foo</cs:uid> 132 <d:href>mailto:foo@example.org</d:href> 133 <cs:invite-noresponse/> 134 <cs:hosturl> 135 <d:href>/calendar</d:href> 136 </cs:hosturl> 137 <cs:access> 138 <cs:read/> 139 </cs:access> 140 <cs:organizer> 141 <d:href>/principal/user1</d:href> 142 <cs:first-name>Foo</cs:first-name> 143 <cs:last-name>Bar</cs:last-name> 144 </cs:organizer> 145 <cs:organizer-first>Foo</cs:organizer-first> 146 <cs:organizer-last>Bar</cs:organizer-last> 147 </cs:invite-notification> 148</cs:root> 149 150FOO 151 ), 152 array( 153 array( 154 'id' => 'foo', 155 'dtStamp' => $dtStamp, 156 'etag' => '"1"', 157 'href' => 'mailto:foo@example.org', 158 'type' => CalDAV\SharingPlugin::STATUS_DELETED, 159 'readOnly' => false, 160 'hostUrl' => 'calendar', 161 'organizer' => 'mailto:user1@fruux.com', 162 'supportedComponents' => new CalDAV\Xml\Property\SupportedCalendarComponentSet(['VEVENT','VTODO']), 163 ), 164<<<FOO 165<?xml version="1.0" encoding="UTF-8"?> 166<cs:root xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:" xmlns:cal="urn:ietf:params:xml:ns:caldav"> 167 <cs:dtstamp>20120101T000000Z</cs:dtstamp> 168 <cs:invite-notification> 169 <cs:uid>foo</cs:uid> 170 <d:href>mailto:foo@example.org</d:href> 171 <cs:invite-deleted/> 172 <cs:hosturl> 173 <d:href>/calendar</d:href> 174 </cs:hosturl> 175 <cs:access> 176 <cs:read-write/> 177 </cs:access> 178 <cs:organizer> 179 <d:href>mailto:user1@fruux.com</d:href> 180 </cs:organizer> 181 <cal:supported-calendar-component-set> 182 <cal:comp name="VEVENT"/> 183 <cal:comp name="VTODO"/> 184 </cal:supported-calendar-component-set> 185 </cs:invite-notification> 186</cs:root> 187 188FOO 189 ), 190 191 ); 192 193 } 194 195 /** 196 * @expectedException InvalidArgumentException 197 */ 198 function testMissingArg() { 199 200 new Invite(array()); 201 202 } 203 204 /** 205 * @expectedException InvalidArgumentException 206 */ 207 function testUnknownArg() { 208 209 new Invite(array( 210 'foo-i-will-break' => true, 211 212 'id' => 1, 213 'etag' => '"bla"', 214 'href' => 'abc', 215 'dtStamp' => 'def', 216 'type' => 'ghi', 217 'readOnly' => true, 218 'hostUrl' => 'jkl', 219 'organizer' => 'mno', 220 )); 221 222 } 223 224 function writeFull($input) { 225 226 $writer = new Writer(); 227 $writer->contextUri = '/'; 228 $writer->namespaceMap = $this->namespaceMap; 229 $writer->openMemory(); 230 $writer->startElement('{http://calendarserver.org/ns/}root'); 231 $input->xmlSerializeFull($writer); 232 $writer->endElement(); 233 return $writer->outputMemory(); 234 235 } 236} 237