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