]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/CardDAV/UserAddressBooksTest.php
f4183ce31b25e27d5eed2c90f6c053c75305929e
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / CardDAV / UserAddressBooksTest.php
1 <?php
2
3 class Sabre_CardDAV_UserAddressBooksTest extends PHPUnit_Framework_TestCase {
4
5     /**
6      * @var Sabre_CardDAV_UserAddressBooks
7      */
8     protected $s;
9     protected $backend;
10
11     function setUp() {
12
13         $this->backend = new Sabre_CardDAV_Backend_Mock();
14         $this->s = new Sabre_CardDAV_UserAddressBooks(
15             $this->backend,
16             'principals/user1'
17         );
18
19     }
20
21     function testGetName() {
22
23         $this->assertEquals('user1', $this->s->getName());
24
25     }
26
27     /**
28      * @expectedException Sabre_DAV_Exception_MethodNotAllowed
29      */
30     function testSetName() {
31
32         $this->s->setName('user2');
33
34     }
35
36     /**
37      * @expectedException Sabre_DAV_Exception_MethodNotAllowed
38      */
39     function testDelete() {
40
41         $this->s->delete();
42
43     }
44
45     function testGetLastModified() {
46
47         $this->assertNull($this->s->getLastModified());
48
49     }
50
51     /**
52      * @expectedException Sabre_DAV_Exception_MethodNotAllowed
53      */
54     function testCreateFile() {
55
56         $this->s->createFile('bla');
57
58     }
59
60     /**
61      * @expectedException Sabre_DAV_Exception_MethodNotAllowed
62      */
63     function testCreateDirectory() {
64
65         $this->s->createDirectory('bla');
66
67     }
68
69     function testGetChild() {
70
71         $child = $this->s->getChild('book1');
72         $this->assertInstanceOf('Sabre_CardDAV_AddressBook', $child);
73         $this->assertEquals('book1', $child->getName());
74
75     }
76
77     /**
78      * @expectedException Sabre_DAV_Exception_NotFound
79      */
80     function testGetChild404() {
81
82         $this->s->getChild('book2');
83
84     }
85
86     function testGetChildren() {
87
88         $children = $this->s->getChildren();
89         $this->assertEquals(1, count($children));
90         $this->assertInstanceOf('Sabre_CardDAV_AddressBook', $children[0]);
91         $this->assertEquals('book1', $children[0]->getName());
92
93     }
94
95     function testCreateExtendedCollection() {
96
97         $resourceType = array(
98             '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook',
99             '{DAV:}collection',
100         );
101         $this->s->createExtendedCollection('book2', $resourceType, array('{DAV:}displayname' => 'a-book 2'));
102
103         $this->assertEquals(array(
104             'id' => 'book2',
105             'uri' => 'book2',
106             '{DAV:}displayname' => 'a-book 2',
107             'principaluri' => 'principals/user1',
108         ), $this->backend->addressBooks[1]);
109
110     }
111
112     /**
113      * @expectedException Sabre_DAV_Exception_InvalidResourceType
114      */
115     function testCreateExtendedCollectionInvalid() {
116
117         $resourceType = array(
118             '{DAV:}collection',
119         );
120         $this->s->createExtendedCollection('book2', $resourceType, array('{DAV:}displayname' => 'a-book 2'));
121
122     }
123
124
125     function testACLMethods() {
126
127         $this->assertEquals('principals/user1', $this->s->getOwner());
128         $this->assertNull($this->s->getGroup());
129         $this->assertEquals(array(
130             array(
131                 'privilege' => '{DAV:}read',
132                 'principal' => 'principals/user1',
133                 'protected' => true,
134             ),
135             array(
136                 'privilege' => '{DAV:}write',
137                 'principal' => 'principals/user1',
138                 'protected' => true,
139             ),
140         ), $this->s->getACL());
141
142     }
143
144     /**
145      * @expectedException Sabre_DAV_Exception_MethodNotAllowed
146      */
147     function testSetACL() {
148
149        $this->s->setACL(array());
150
151     }
152
153     function testGetSupportedPrivilegeSet() {
154
155         $this->assertNull(
156             $this->s->getSupportedPrivilegeSet()
157         );
158
159     }
160 }