]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/CardDAV/CardTest.php
removed community home addon
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / CardDAV / CardTest.php
1 <?php
2
3 class Sabre_CardDAV_CardTest extends PHPUnit_Framework_TestCase {
4
5     /**
6      * @var Sabre_CardDAV_Card
7      */
8     protected $card;
9     /**
10      * @var Sabre_CardDAV_MockBackend
11      */
12     protected $backend;
13
14     function setUp() {
15
16         $this->backend = new Sabre_CardDAV_Backend_Mock();
17         $this->card = new Sabre_CardDAV_Card(
18             $this->backend,
19             array(
20                 'uri' => 'book1',
21                 'id' => 'foo',
22                 'principaluri' => 'principals/user1',
23             ),
24             array(
25                 'uri' => 'card1',
26                 'addressbookid' => 'foo',
27                 'carddata' => 'card',
28             )
29         );
30
31     }
32
33     function testGet() {
34
35         $result = $this->card->get();
36         $this->assertEquals('card', $result);
37
38     }
39     function testGet2() {
40
41         $this->card = new Sabre_CardDAV_Card(
42             $this->backend,
43             array(
44                 'uri' => 'book1',
45                 'id' => 'foo',
46                 'principaluri' => 'principals/user1',
47             ),
48             array(
49                 'uri' => 'card1',
50                 'addressbookid' => 'foo',
51             )
52         );
53         $result = $this->card->get();
54         $this->assertEquals("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD", $result);
55
56     }
57
58
59     /**
60      * @depends testGet
61      */
62     function testPut() {
63
64         $file = fopen('php://memory','r+');
65         fwrite($file, 'newdata');
66         rewind($file);
67         $this->card->put($file);
68         $result = $this->card->get();
69         $this->assertEquals('newdata', $result);
70
71     }
72
73
74     function testDelete() {
75
76         $this->card->delete();
77         $this->assertEquals(1, count($this->backend->cards['foo']));
78
79     }
80
81     function testGetContentType() {
82
83         $this->assertEquals('text/x-vcard; charset=utf-8', $this->card->getContentType());
84
85     }
86
87     function testGetETag() {
88
89         $this->assertEquals('"' . md5('card') . '"' , $this->card->getETag());
90
91     }
92
93     function testGetETag2() {
94
95         $card = new Sabre_CardDAV_Card(
96             $this->backend,
97             array(
98                 'uri' => 'book1',
99                 'id' => 'foo',
100                 'principaluri' => 'principals/user1',
101             ),
102             array(
103                 'uri' => 'card1',
104                 'addressbookid' => 'foo',
105                 'carddata' => 'card',
106                 'etag' => '"blabla"',
107             )
108         );
109         $this->assertEquals('"blabla"' , $card->getETag());
110
111     }
112
113     function testGetLastModified() {
114
115         $this->assertEquals(null, $this->card->getLastModified());
116
117     }
118
119     function testGetSize() {
120
121         $this->assertEquals(4, $this->card->getSize());
122         $this->assertEquals(4, $this->card->getSize());
123
124     }
125
126     function testGetSize2() {
127
128         $card = new Sabre_CardDAV_Card(
129             $this->backend,
130             array(
131                 'uri' => 'book1',
132                 'id' => 'foo',
133                 'principaluri' => 'principals/user1',
134             ),
135             array(
136                 'uri' => 'card1',
137                 'addressbookid' => 'foo',
138                 'etag' => '"blabla"',
139                 'size' => 4,
140             )
141         );
142         $this->assertEquals(4, $card->getSize());
143
144     }
145
146     function testACLMethods() {
147
148         $this->assertEquals('principals/user1', $this->card->getOwner());
149         $this->assertNull($this->card->getGroup());
150         $this->assertEquals(array(
151             array(
152                 'privilege' => '{DAV:}read',
153                 'principal' => 'principals/user1',
154                 'protected' => true,
155             ),
156             array(
157                 'privilege' => '{DAV:}write',
158                 'principal' => 'principals/user1',
159                 'protected' => true,
160             ),
161         ), $this->card->getACL());
162
163     }
164
165     /**
166      * @expectedException Sabre_DAV_Exception_MethodNotAllowed
167      */
168     function testSetACL() {
169
170        $this->card->setACL(array());
171
172     }
173
174     function testGetSupportedPrivilegeSet() {
175
176         $this->assertNull(
177             $this->card->getSupportedPrivilegeSet()
178         );
179
180     }
181
182 }