1<?php
2
3namespace Sabre\CalDAV\Xml\Request;
4
5use Sabre\DAV\Xml\XmlTest;
6use Sabre\CalDAV\SharingPlugin;
7
8class InviteReplyTest extends XmlTest {
9
10    protected $elementMap = [
11        '{http://calendarserver.org/ns/}invite-reply' => 'Sabre\\CalDAV\\Xml\\Request\\InviteReply',
12    ];
13
14    function testDeserialize() {
15
16        $xml = <<<XML
17<?xml version="1.0"?>
18<cs:invite-reply xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:">
19    <d:href>/principal/1</d:href>
20    <cs:hosturl><d:href>/calendar/1</d:href></cs:hosturl>
21    <cs:invite-accepted />
22    <cs:in-reply-to>blabla</cs:in-reply-to>
23    <cs:summary>Summary</cs:summary>
24</cs:invite-reply>
25XML;
26
27        $result = $this->parse($xml);
28        $inviteReply = new InviteReply('/principal/1', '/calendar/1', 'blabla', 'Summary', SharingPlugin::STATUS_ACCEPTED);
29
30        $this->assertEquals(
31            $inviteReply,
32            $result['value']
33        );
34
35    }
36
37    function testDeserializeDeclined() {
38
39        $xml = <<<XML
40<?xml version="1.0"?>
41<cs:invite-reply xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:">
42    <d:href>/principal/1</d:href>
43    <cs:hosturl><d:href>/calendar/1</d:href></cs:hosturl>
44    <cs:invite-declined />
45    <cs:in-reply-to>blabla</cs:in-reply-to>
46    <cs:summary>Summary</cs:summary>
47</cs:invite-reply>
48XML;
49
50        $result = $this->parse($xml);
51        $inviteReply = new InviteReply('/principal/1', '/calendar/1', 'blabla', 'Summary', SharingPlugin::STATUS_DECLINED);
52
53        $this->assertEquals(
54            $inviteReply,
55            $result['value']
56        );
57
58    }
59
60    /**
61     * @expectedException \Sabre\DAV\Exception\BadRequest
62     */
63    function testDeserializeNoHostUrl() {
64
65        $xml = <<<XML
66<?xml version="1.0"?>
67<cs:invite-reply xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:">
68    <d:href>/principal/1</d:href>
69    <cs:invite-declined />
70    <cs:in-reply-to>blabla</cs:in-reply-to>
71    <cs:summary>Summary</cs:summary>
72</cs:invite-reply>
73XML;
74
75        $this->parse($xml);
76
77    }
78}
79