]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/DAV/Property/ResponseTest.php
Merge branch 'master' of git://github.com/friendica/friendica-addons
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / DAV / Property / ResponseTest.php
1 <?php
2
3 class Sabre_DAV_Property_ResponseTest extends PHPUnit_Framework_TestCase {
4
5     function testSimple() {
6
7         $innerProps = array(
8             200 => array(
9                 '{DAV:}displayname' => 'my file',
10             ),
11             404 => array(
12                 '{DAV:}owner' => null,
13             )
14         );
15
16         $property = new Sabre_DAV_Property_Response('uri',$innerProps);
17
18         $this->assertEquals('uri',$property->getHref());
19         $this->assertEquals($innerProps,$property->getResponseProperties());
20
21
22     }
23
24     /**
25      * @depends testSimple
26      */
27     function testSerialize() {
28
29         $innerProps = array(
30             200 => array(
31                 '{DAV:}displayname' => 'my file',
32             ),
33             404 => array(
34                 '{DAV:}owner' => null,
35             )
36         );
37
38         $property = new Sabre_DAV_Property_Response('uri',$innerProps);
39
40         $doc = new DOMDocument();
41         $root = $doc->createElement('d:root');
42         $root->setAttribute('xmlns:d','DAV:');
43
44         $doc->appendChild($root);
45         $objectTree = new Sabre_DAV_ObjectTree(new Sabre_DAV_SimpleCollection('rootdir'));
46         $server = new Sabre_DAV_Server($objectTree);
47
48         $property->serialize($server, $root);
49
50         $xml = $doc->saveXML();
51
52         $this->assertEquals(
53 '<?xml version="1.0"?>
54 <d:root xmlns:d="DAV:">' .
55 '<d:response>' .
56 '<d:href>/uri</d:href>' .
57 '<d:propstat>' .
58 '<d:prop>' .
59 '<d:displayname>my file</d:displayname>' .
60 '</d:prop>' .
61 '<d:status>HTTP/1.1 200 OK</d:status>' .
62 '</d:propstat>' .
63 '<d:propstat>' .
64 '<d:prop>' .
65 '<d:owner/>' .
66 '</d:prop>' .
67 '<d:status>HTTP/1.1 404 Not Found</d:status>' .
68 '</d:propstat>' .
69 '</d:response>' .
70 '</d:root>
71 ', $xml);
72
73     }
74
75     /**
76      * This one is specifically for testing properties with no namespaces, which is legal xml
77      *
78      * @depends testSerialize
79      */
80     function testSerializeEmptyNamespace() {
81
82         $innerProps = array(
83             200 => array(
84                 '{}propertyname' => 'value',
85             ),
86         );
87
88         $property = new Sabre_DAV_Property_Response('uri',$innerProps);
89
90         $doc = new DOMDocument();
91         $root = $doc->createElement('d:root');
92         $root->setAttribute('xmlns:d','DAV:');
93
94         $doc->appendChild($root);
95         $objectTree = new Sabre_DAV_ObjectTree(new Sabre_DAV_SimpleCollection('rootdir'));
96         $server = new Sabre_DAV_Server($objectTree);
97
98         $property->serialize($server, $root);
99
100         $xml = $doc->saveXML();
101
102         $this->assertEquals(
103 '<?xml version="1.0"?>
104 <d:root xmlns:d="DAV:">' .
105 '<d:response>' .
106 '<d:href>/uri</d:href>' .
107 '<d:propstat>' .
108 '<d:prop>' .
109 '<propertyname xmlns="">value</propertyname>' .
110 '</d:prop>' .
111 '<d:status>HTTP/1.1 200 OK</d:status>' .
112 '</d:propstat>' .
113 '</d:response>' .
114 '</d:root>
115 ', $xml);
116
117     }
118
119     /**
120      * This one is specifically for testing properties with no namespaces, which is legal xml
121      *
122      * @depends testSerialize
123      */
124     function testSerializeCustomNamespace() {
125
126         $innerProps = array(
127             200 => array(
128                 '{http://sabredav.org/NS/example}propertyname' => 'value',
129             ),
130         );
131
132         $property = new Sabre_DAV_Property_Response('uri',$innerProps);
133
134         $doc = new DOMDocument();
135         $root = $doc->createElement('d:root');
136         $root->setAttribute('xmlns:d','DAV:');
137
138         $doc->appendChild($root);
139         $objectTree = new Sabre_DAV_ObjectTree(new Sabre_DAV_SimpleCollection('rootdir'));
140         $server = new Sabre_DAV_Server($objectTree);
141
142         $property->serialize($server, $root);
143
144         $xml = $doc->saveXML();
145
146         $this->assertEquals(
147 '<?xml version="1.0"?>
148 <d:root xmlns:d="DAV:">' .
149 '<d:response>' .
150 '<d:href>/uri</d:href>' .
151 '<d:propstat>' .
152 '<d:prop>' .
153 '<x2:propertyname xmlns:x2="http://sabredav.org/NS/example">value</x2:propertyname>' .
154 '</d:prop>' .
155 '<d:status>HTTP/1.1 200 OK</d:status>' .
156 '</d:propstat>' .
157 '</d:response>' .
158 '</d:root>
159 ', $xml);
160
161     }
162
163     /**
164      * @depends testSerialize
165      */
166     function testSerializeComplexProperty() {
167
168         $innerProps = array(
169             200 => array(
170                 '{DAV:}link' => new Sabre_DAV_Property_Href('http://sabredav.org/', false)
171             ),
172         );
173
174         $property = new Sabre_DAV_Property_Response('uri',$innerProps);
175
176         $doc = new DOMDocument();
177         $root = $doc->createElement('d:root');
178         $root->setAttribute('xmlns:d','DAV:');
179
180         $doc->appendChild($root);
181         $objectTree = new Sabre_DAV_ObjectTree(new Sabre_DAV_SimpleCollection('rootdir'));
182         $server = new Sabre_DAV_Server($objectTree);
183
184         $property->serialize($server, $root);
185
186         $xml = $doc->saveXML();
187
188         $this->assertEquals(
189 '<?xml version="1.0"?>
190 <d:root xmlns:d="DAV:">' .
191 '<d:response>' .
192 '<d:href>/uri</d:href>' .
193 '<d:propstat>' .
194 '<d:prop>' .
195 '<d:link><d:href>http://sabredav.org/</d:href></d:link>' .
196 '</d:prop>' .
197 '<d:status>HTTP/1.1 200 OK</d:status>' .
198 '</d:propstat>' .
199 '</d:response>' .
200 '</d:root>
201 ', $xml);
202
203     }
204
205     /**
206      * @depends testSerialize
207      * @expectedException Sabre_DAV_Exception
208      */
209     function testSerializeBreak() {
210
211         $innerProps = array(
212             200 => array(
213                 '{DAV:}link' => new STDClass()
214             ),
215         );
216
217         $property = new Sabre_DAV_Property_Response('uri',$innerProps);
218
219         $doc = new DOMDocument();
220         $root = $doc->createElement('d:root');
221         $root->setAttribute('xmlns:d','DAV:');
222
223         $doc->appendChild($root);
224         $objectTree = new Sabre_DAV_ObjectTree(new Sabre_DAV_SimpleCollection('rootdir'));
225         $server = new Sabre_DAV_Server($objectTree);
226
227         $property->serialize($server, $root);
228
229     }
230
231 }