aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/dav/tests/Sabre/CalDAV/SharedCalendarTest.php
blob: 9558319170d623b21e26a38779259fd65bf29804 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php

namespace Sabre\CalDAV;

use Sabre\DAVACL;

class SharedCalendarTest extends \PHPUnit_Framework_TestCase {

    protected $backend;

    function getInstance(array $props = null) {

        if (is_null($props)) {
            $props = array(
                'id' => 1,
                '{http://calendarserver.org/ns/}shared-url' => 'calendars/owner/original',
                '{http://sabredav.org/ns}owner-principal' => 'principals/owner',
                '{http://sabredav.org/ns}read-only' => false,
                'principaluri' => 'principals/sharee',
            );
        }

        $this->backend = new Backend\Mock(
            array($props),
            array(),
            array()
        );
        $this->backend->updateShares(1, array(
            array(
                'href' => 'mailto:removeme@example.org',
                'commonName' => 'To be removed',
                'readOnly' => true,
            ),
        ), array());

        return new SharedCalendar($this->backend, $props);

    }

    function testGetSharedUrl() {
        $this->assertEquals('calendars/owner/original', $this->getInstance()->getSharedUrl());
    }

    function testGetShares() {

        $this->assertEquals(array(array(
            'href' => 'mailto:removeme@example.org',
            'commonName' => 'To be removed',
            'readOnly' => true,
            'status' => SharingPlugin::STATUS_NORESPONSE,
        )), $this->getInstance()->getShares());

    }

    function testGetOwner() {
        $this->assertEquals('principals/owner', $this->getInstance()->getOwner());
    }

    function testGetACL() {

        $expected = array(
            array(
                'privilege' => '{DAV:}read',
                'principal' => 'principals/owner',
                'protected' => true,
            ),
            array(
                'privilege' => '{DAV:}write',
                'principal' => 'principals/owner',
                'protected' => true,
            ),
            array(
                'privilege' => '{DAV:}read',
                'principal' => 'principals/owner/calendar-proxy-write',
                'protected' => true,
            ),
            array(
                'privilege' => '{DAV:}write',
                'principal' => 'principals/owner/calendar-proxy-write',
                'protected' => true,
            ),
            array(
                'privilege' => '{DAV:}read',
                'principal' => 'principals/owner/calendar-proxy-read',
                'protected' => true,
            ),
            array(
                'privilege' => '{' . Plugin::NS_CALDAV . '}read-free-busy',
                'principal' => '{DAV:}authenticated',
                'protected' => true,
            ),
            array(
                'privilege' => '{DAV:}read',
                'principal' => 'principals/sharee',
                'protected' => true,
            ),
            array(
                'privilege' => '{DAV:}write',
                'principal' => 'principals/sharee',
                'protected' => true,
            ),
        );

        $this->assertEquals($expected, $this->getInstance()->getACL());

    }

    /**
     * @expectedException InvalidArgumentException
     */
    public function testCreateInstanceMissingArg() {

        $this->getInstance(array(
            'id' => 1,
            '{http://calendarserver.org/ns/}shared-url' => 'calendars/owner/original',
            '{http://sabredav.org/ns}read-only' => false,
            'principaluri' => 'principals/sharee',
        ));

    }

}