1<?php 2 3namespace Sabre\CalDAV\Xml\Property; 4 5use Sabre\CalDAV; 6use Sabre\DAV; 7 8class SupportedCalendarComponentSetTest 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 function testSimple() { 18 19 $prop = new SupportedCalendarComponentSet(['VEVENT']); 20 $this->assertEquals( 21 ['VEVENT'], 22 $prop->getValue() 23 ); 24 25 } 26 27 function testMultiple() { 28 29 $prop = new SupportedCalendarComponentSet(['VEVENT', 'VTODO']); 30 $this->assertEquals( 31 ['VEVENT', 'VTODO'], 32 $prop->getValue() 33 ); 34 35 } 36 37 /** 38 * @depends testSimple 39 * @depends testMultiple 40 */ 41 function testSerialize() { 42 43 $property = new SupportedCalendarComponentSet(['VEVENT', 'VTODO']); 44 $xml = $this->write(['{DAV:}root' => $property]); 45 46 $this->assertXmlStringEqualsXmlString( 47'<?xml version="1.0"?> 48<d:root xmlns:d="DAV:" xmlns:cal="' . CalDAV\Plugin::NS_CALDAV . '" xmlns:cs="' . CalDAV\Plugin::NS_CALENDARSERVER . '"> 49 <cal:comp name="VEVENT"/> 50 <cal:comp name="VTODO"/> 51</d:root> 52', $xml); 53 54 } 55 56 function testUnserialize() { 57 58 $cal = CalDAV\Plugin::NS_CALDAV; 59 $cs = CalDAV\Plugin::NS_CALENDARSERVER; 60 61$xml = <<<XML 62<?xml version="1.0"?> 63 <d:root xmlns:cal="$cal" xmlns:cs="$cs" xmlns:d="DAV:"> 64 <cal:comp name="VEVENT"/> 65 <cal:comp name="VTODO"/> 66 </d:root> 67XML; 68 69 $result = $this->parse( 70 $xml, 71 ['{DAV:}root' => 'Sabre\\CalDAV\\Xml\\Property\\SupportedCalendarComponentSet'] 72 ); 73 74 $this->assertEquals( 75 new SupportedCalendarComponentSet(['VEVENT', 'VTODO']), 76 $result['value'] 77 ); 78 79 } 80 81 /** 82 * @expectedException \Sabre\Xml\ParseException 83 */ 84 function testUnserializeEmpty() { 85 86 $cal = CalDAV\Plugin::NS_CALDAV; 87 $cs = CalDAV\Plugin::NS_CALENDARSERVER; 88 89$xml = <<<XML 90<?xml version="1.0"?> 91 <d:root xmlns:cal="$cal" xmlns:cs="$cs" xmlns:d="DAV:"> 92 </d:root> 93XML; 94 95 $result = $this->parse( 96 $xml, 97 ['{DAV:}root' => 'Sabre\\CalDAV\\Xml\\Property\\SupportedCalendarComponentSet'] 98 ); 99 100 $this->assertEquals( 101 new SupportedCalendarComponentSet([]), 102 $result['value'] 103 ); 104 105 } 106 107} 108