1<?php 2 3namespace Sabre\CalDAV\Xml\Property; 4 5use Sabre\CalDAV; 6use Sabre\DAV; 7 8class InviteTest extends DAV\Xml\XmlTest { 9 10 function setUp() { 11 12 $this->namespaceMap[CalDAV\Plugin::NS_CALDAV] = 'cal'; 13 $this->namespaceMap[CalDAV\Plugin::NS_CALENDARSERVER] = 'cs'; 14 15 16 } 17 18 function testSimple() { 19 20 $sccs = new Invite([]); 21 $this->assertInstanceOf('Sabre\CalDAV\Xml\Property\Invite', $sccs); 22 23 } 24 25 /** 26 * @depends testSimple 27 */ 28 function testSerialize() { 29 30 $property = new Invite([ 31 [ 32 'href' => 'mailto:user1@example.org', 33 'status' => CalDAV\SharingPlugin::STATUS_ACCEPTED, 34 'readOnly' => false, 35 ], 36 [ 37 'href' => 'mailto:user2@example.org', 38 'commonName' => 'John Doe', 39 'status' => CalDAV\SharingPlugin::STATUS_DECLINED, 40 'readOnly' => true, 41 ], 42 [ 43 'href' => 'mailto:user3@example.org', 44 'commonName' => 'Joe Shmoe', 45 'status' => CalDAV\SharingPlugin::STATUS_NORESPONSE, 46 'readOnly' => true, 47 'summary' => 'Something, something', 48 ], 49 [ 50 'href' => 'mailto:user4@example.org', 51 'commonName' => 'Hoe Boe', 52 'status' => CalDAV\SharingPlugin::STATUS_INVALID, 53 'readOnly' => true, 54 ], 55 ], [ 56 'href' => 'mailto:thedoctor@example.org', 57 'commonName' => 'The Doctor', 58 'firstName' => 'The', 59 'lastName' => 'Doctor', 60 ]); 61 62 $xml = $this->write(['{DAV:}root' => $property]); 63 64 $this->assertXmlStringEqualsXmlString( 65'<?xml version="1.0"?> 66<d:root xmlns:d="DAV:" xmlns:cal="' . CalDAV\Plugin::NS_CALDAV . '" xmlns:cs="' . CalDAV\Plugin::NS_CALENDARSERVER . '"> 67 <cs:organizer> 68 <d:href>mailto:thedoctor@example.org</d:href> 69 <cs:common-name>The Doctor</cs:common-name> 70 <cs:first-name>The</cs:first-name> 71 <cs:last-name>Doctor</cs:last-name> 72 </cs:organizer> 73 <cs:user> 74 <d:href>mailto:user1@example.org</d:href> 75 <cs:invite-accepted/> 76 <cs:access> 77 <cs:read-write/> 78 </cs:access> 79 </cs:user> 80 <cs:user> 81 <d:href>mailto:user2@example.org</d:href> 82 <cs:common-name>John Doe</cs:common-name> 83 <cs:invite-declined/> 84 <cs:access> 85 <cs:read/> 86 </cs:access> 87 </cs:user> 88 <cs:user> 89 <d:href>mailto:user3@example.org</d:href> 90 <cs:common-name>Joe Shmoe</cs:common-name> 91 <cs:invite-noresponse/> 92 <cs:access> 93 <cs:read/> 94 </cs:access> 95 <cs:summary>Something, something</cs:summary> 96 </cs:user> 97 <cs:user> 98 <d:href>mailto:user4@example.org</d:href> 99 <cs:common-name>Hoe Boe</cs:common-name> 100 <cs:invite-invalid/> 101 <cs:access> 102 <cs:read/> 103 </cs:access> 104 </cs:user> 105</d:root> 106', $xml); 107 108 } 109 110 /** 111 * @depends testSerialize 112 */ 113 function testUnserialize() { 114 115 $input = [ 116 [ 117 'href' => 'mailto:user1@example.org', 118 'status' => CalDAV\SharingPlugin::STATUS_ACCEPTED, 119 'readOnly' => false, 120 'commonName' => '', 121 'summary' => '', 122 ], 123 [ 124 'href' => 'mailto:user2@example.org', 125 'commonName' => 'John Doe', 126 'status' => CalDAV\SharingPlugin::STATUS_DECLINED, 127 'readOnly' => true, 128 'summary' => '', 129 ], 130 [ 131 'href' => 'mailto:user3@example.org', 132 'commonName' => 'Joe Shmoe', 133 'status' => CalDAV\SharingPlugin::STATUS_NORESPONSE, 134 'readOnly' => true, 135 'summary' => 'Something, something', 136 ], 137 [ 138 'href' => 'mailto:user4@example.org', 139 'commonName' => 'Hoe Boe', 140 'status' => CalDAV\SharingPlugin::STATUS_INVALID, 141 'readOnly' => true, 142 'summary' => '', 143 ], 144 ]; 145 146 // Creating the xml 147 $inputProperty = new Invite($input); 148 $xml = $this->write(['{DAV:}root' => $inputProperty]); 149 // Parsing it again 150 151 $doc2 = $this->parse( 152 $xml, 153 ['{DAV:}root' => 'Sabre\\CalDAV\\Xml\\Property\\Invite'] 154 ); 155 156 $outputProperty = $doc2['value']; 157 158 $this->assertEquals($input, $outputProperty->getValue()); 159 160 } 161 162 /** 163 * @expectedException InvalidArgumentException 164 */ 165 function testUnserializeNoStatus() { 166 167$xml = '<?xml version="1.0"?> 168<d:root xmlns:d="DAV:" xmlns:cal="' . CalDAV\Plugin::NS_CALDAV . '" xmlns:cs="' . CalDAV\Plugin::NS_CALENDARSERVER . '"> 169 <cs:user> 170 <d:href>mailto:user1@example.org</d:href> 171 <!-- <cs:invite-accepted/> --> 172 <cs:access> 173 <cs:read-write/> 174 </cs:access> 175 </cs:user> 176</d:root>'; 177 178 $this->parse( 179 $xml, 180 ['{DAV:}root' => 'Sabre\\CalDAV\\Xml\\Property\\Invite'] 181 ); 182 183 } 184 185} 186