1<?php 2 3namespace Sabre\CalDAV\Xml\Notification; 4 5use Sabre\CalDAV; 6use Sabre\DAV; 7use Sabre\Xml\Writer; 8 9class InviteReplyTest extends \PHPUnit_Framework_TestCase { 10 11 /** 12 * @dataProvider dataProvider 13 */ 14 function testSerializers($notification, $expected) { 15 16 $notification = new InviteReply($notification); 17 18 $this->assertEquals('foo', $notification->getId()); 19 $this->assertEquals('"1"', $notification->getETag()); 20 21 $simpleExpected = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<cs:root xmlns:cs="http://calendarserver.org/ns/"><cs:invite-reply/></cs:root>'; 22 23 $writer = new Writer(); 24 $writer->namespaceMap = [ 25 'http://calendarserver.org/ns/' => 'cs', 26 ]; 27 $writer->openMemory(); 28 $writer->startDocument('1.0', 'UTF-8'); 29 $writer->startElement('{http://calendarserver.org/ns/}root'); 30 $writer->write($notification); 31 $writer->endElement(); 32 33 $this->assertEquals($simpleExpected, $writer->outputMemory()); 34 35 $writer = new Writer(); 36 $writer->contextUri = '/'; 37 $writer->namespaceMap = [ 38 'http://calendarserver.org/ns/' => 'cs', 39 'DAV:' => 'd', 40 ]; 41 $writer->openMemory(); 42 $writer->startDocument('1.0', 'UTF-8'); 43 $writer->startElement('{http://calendarserver.org/ns/}root'); 44 $notification->xmlSerializeFull($writer); 45 $writer->endElement(); 46 47 $this->assertXmlStringEqualsXmlString($expected, $writer->outputMemory()); 48 49 50 } 51 52 function dataProvider() { 53 54 $dtStamp = new \DateTime('2012-01-01 00:00:00 GMT'); 55 return array( 56 array( 57 array( 58 'id' => 'foo', 59 'dtStamp' => $dtStamp, 60 'etag' => '"1"', 61 'inReplyTo' => 'bar', 62 'href' => 'mailto:foo@example.org', 63 'type' => CalDAV\SharingPlugin::STATUS_ACCEPTED, 64 'hostUrl' => 'calendar' 65 ), 66<<<FOO 67<?xml version="1.0" encoding="UTF-8"?> 68<cs:root xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:"> 69 <cs:dtstamp>20120101T000000Z</cs:dtstamp> 70 <cs:invite-reply> 71 <cs:uid>foo</cs:uid> 72 <cs:in-reply-to>bar</cs:in-reply-to> 73 <d:href>mailto:foo@example.org</d:href> 74 <cs:invite-accepted/> 75 <cs:hosturl> 76 <d:href>/calendar</d:href> 77 </cs:hosturl> 78 </cs:invite-reply> 79</cs:root> 80 81FOO 82 ), 83 array( 84 array( 85 'id' => 'foo', 86 'dtStamp' => $dtStamp, 87 'etag' => '"1"', 88 'inReplyTo' => 'bar', 89 'href' => 'mailto:foo@example.org', 90 'type' => CalDAV\SharingPlugin::STATUS_DECLINED, 91 'hostUrl' => 'calendar', 92 'summary' => 'Summary!' 93 ), 94<<<FOO 95<?xml version="1.0" encoding="UTF-8"?> 96<cs:root xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:"> 97 <cs:dtstamp>20120101T000000Z</cs:dtstamp> 98 <cs:invite-reply> 99 <cs:uid>foo</cs:uid> 100 <cs:in-reply-to>bar</cs:in-reply-to> 101 <d:href>mailto:foo@example.org</d:href> 102 <cs:invite-declined/> 103 <cs:hosturl> 104 <d:href>/calendar</d:href> 105 </cs:hosturl> 106 <cs:summary>Summary!</cs:summary> 107 </cs:invite-reply> 108</cs:root> 109 110FOO 111 ), 112 113 ); 114 115 } 116 117 /** 118 * @expectedException InvalidArgumentException 119 */ 120 function testMissingArg() { 121 122 new InviteReply(array()); 123 124 } 125 126 /** 127 * @expectedException InvalidArgumentException 128 */ 129 function testUnknownArg() { 130 131 new InviteReply(array( 132 'foo-i-will-break' => true, 133 134 'id' => 1, 135 'etag' => '"bla"', 136 'href' => 'abc', 137 'dtStamp' => 'def', 138 'inReplyTo' => 'qrs', 139 'type' => 'ghi', 140 'hostUrl' => 'jkl', 141 )); 142 143 } 144 145} 146