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