1<?php
2
3namespace Sabre\CalDAV\Principal;
4use Sabre\DAVACL;
5
6class UserTest extends \PHPUnit_Framework_TestCase {
7
8    function getInstance() {
9
10        $backend = new DAVACL\PrincipalBackend\Mock();
11        $backend->addPrincipal(array(
12            'uri' => 'principals/user/calendar-proxy-read',
13        ));
14        $backend->addPrincipal(array(
15            'uri' => 'principals/user/calendar-proxy-write',
16        ));
17        $backend->addPrincipal(array(
18            'uri' => 'principals/user/random',
19        ));
20        return new User($backend, array(
21            'uri' => 'principals/user',
22        ));
23
24    }
25
26    /**
27     * @expectedException Sabre\DAV\Exception\Forbidden
28     */
29    function testCreateFile() {
30
31        $u = $this->getInstance();
32        $u->createFile('test');
33
34    }
35
36    /**
37     * @expectedException Sabre\DAV\Exception\Forbidden
38     */
39    function testCreateDirectory() {
40
41        $u = $this->getInstance();
42        $u->createDirectory('test');
43
44    }
45
46    function testGetChildProxyRead() {
47
48        $u = $this->getInstance();
49        $child = $u->getChild('calendar-proxy-read');
50        $this->assertInstanceOf('Sabre\\CalDAV\\Principal\\ProxyRead', $child);
51
52    }
53
54    function testGetChildProxyWrite() {
55
56        $u = $this->getInstance();
57        $child = $u->getChild('calendar-proxy-write');
58        $this->assertInstanceOf('Sabre\\CalDAV\\Principal\\ProxyWrite', $child);
59
60    }
61
62    /**
63     * @expectedException Sabre\DAV\Exception\NotFound
64     */
65    function testGetChildNotFound() {
66
67        $u = $this->getInstance();
68        $child = $u->getChild('foo');
69
70    }
71
72    /**
73     * @expectedException Sabre\DAV\Exception\NotFound
74     */
75    function testGetChildNotFound2() {
76
77        $u = $this->getInstance();
78        $child = $u->getChild('random');
79
80    }
81
82    function testGetChildren() {
83
84        $u = $this->getInstance();
85        $children = $u->getChildren();
86        $this->assertEquals(2, count($children));
87        $this->assertInstanceOf('Sabre\\CalDAV\\Principal\\ProxyRead', $children[0]);
88        $this->assertInstanceOf('Sabre\\CalDAV\\Principal\\ProxyWrite', $children[1]);
89
90    }
91
92    function testChildExist() {
93
94        $u = $this->getInstance();
95        $this->assertTrue($u->childExists('calendar-proxy-read'));
96        $this->assertTrue($u->childExists('calendar-proxy-write'));
97        $this->assertFalse($u->childExists('foo'));
98
99    }
100
101    function testGetACL() {
102
103        $expected = array(
104            array(
105                'privilege' => '{DAV:}read',
106                'principal' => '{DAV:}authenticated',
107                'protected' => true,
108            ),
109            array(
110                'privilege' => '{DAV:}read',
111                'principal' => 'principals/user/calendar-proxy-read',
112                'protected' => true,
113            ),
114            array(
115                'privilege' => '{DAV:}read',
116                'principal' => 'principals/user/calendar-proxy-write',
117                'protected' => true,
118            ),
119        );
120
121        $u = $this->getInstance();
122        $this->assertEquals($expected, $u->getACL());
123
124    }
125
126}
127