3 require_once 'Sabre/HTTP/ResponseMock.php';
5 class Sabre_DAVACL_ExpandPropertiesTest extends PHPUnit_Framework_TestCase {
10 new Sabre_DAVACL_MockPropertyNode('node1', array(
11 '{http://sabredav.org/ns}simple' => 'foo',
12 '{http://sabredav.org/ns}href' => new Sabre_DAV_Property_Href('node2'),
13 '{DAV:}displayname' => 'Node 1',
15 new Sabre_DAVACL_MockPropertyNode('node2', array(
16 '{http://sabredav.org/ns}simple' => 'simple',
17 '{http://sabredav.org/ns}hreflist' => new Sabre_DAV_Property_HrefList(array('node1','node3')),
18 '{DAV:}displayname' => 'Node 2',
20 new Sabre_DAVACL_MockPropertyNode('node3', array(
21 '{http://sabredav.org/ns}simple' => 'simple',
22 '{DAV:}displayname' => 'Node 3',
26 $fakeServer = new Sabre_DAV_Server($tree);
27 $fakeServer->debugExceptions = true;
28 $fakeServer->httpResponse = new Sabre_HTTP_ResponseMock();
29 $plugin = new Sabre_DAVACL_Plugin();
30 $plugin->allowAccessToNodesWithoutACL = true;
32 $this->assertTrue($plugin instanceof Sabre_DAVACL_Plugin);
33 $fakeServer->addPlugin($plugin);
34 $this->assertEquals($plugin, $fakeServer->getPlugin('acl'));
40 function testSimple() {
42 $xml = '<?xml version="1.0"?>
43 <d:expand-property xmlns:d="DAV:">
44 <d:property name="displayname" />
45 <d:property name="foo" namespace="http://www.sabredav.org/NS/2010/nonexistant" />
46 <d:property name="simple" namespace="http://sabredav.org/ns" />
47 <d:property name="href" namespace="http://sabredav.org/ns" />
48 </d:expand-property>';
51 'REQUEST_METHOD' => 'REPORT',
53 'REQUEST_URI' => '/node1',
56 $request = new Sabre_HTTP_Request($serverVars);
57 $request->setBody($xml);
59 $server = $this->getServer();
60 $server->httpRequest = $request;
64 $this->assertEquals('HTTP/1.1 207 Multi-Status', $server->httpResponse->status,'Incorrect status code received. Full body: ' . $server->httpResponse->body);
65 $this->assertEquals(array(
66 'Content-Type' => 'application/xml; charset=utf-8',
67 ), $server->httpResponse->headers);
72 '/d:multistatus/d:response' => 1,
73 '/d:multistatus/d:response/d:href' => 1,
74 '/d:multistatus/d:response/d:propstat' => 2,
75 '/d:multistatus/d:response/d:propstat/d:prop' => 2,
76 '/d:multistatus/d:response/d:propstat/d:prop/d:displayname' => 1,
77 '/d:multistatus/d:response/d:propstat/d:prop/s:simple' => 1,
78 '/d:multistatus/d:response/d:propstat/d:prop/s:href' => 1,
79 '/d:multistatus/d:response/d:propstat/d:prop/s:href/d:href' => 1,
82 $xml = simplexml_load_string($server->httpResponse->body);
83 $xml->registerXPathNamespace('d','DAV:');
84 $xml->registerXPathNamespace('s','http://sabredav.org/ns');
85 foreach($check as $v1=>$v2) {
87 $xpath = is_int($v1)?$v2:$v1;
89 $result = $xml->xpath($xpath);
92 if (!is_int($v1)) $count = $v2;
94 $this->assertEquals($count,count($result), 'we expected ' . $count . ' appearances of ' . $xpath . ' . We found ' . count($result) . '. Full response: ' . $server->httpResponse->body);
101 * @depends testSimple
103 function testExpand() {
105 $xml = '<?xml version="1.0"?>
106 <d:expand-property xmlns:d="DAV:">
107 <d:property name="href" namespace="http://sabredav.org/ns">
108 <d:property name="displayname" />
110 </d:expand-property>';
113 'REQUEST_METHOD' => 'REPORT',
115 'REQUEST_URI' => '/node1',
118 $request = new Sabre_HTTP_Request($serverVars);
119 $request->setBody($xml);
121 $server = $this->getServer();
122 $server->httpRequest = $request;
126 $this->assertEquals('HTTP/1.1 207 Multi-Status', $server->httpResponse->status, 'Incorrect response status received. Full response body: ' . $server->httpResponse->body);
127 $this->assertEquals(array(
128 'Content-Type' => 'application/xml; charset=utf-8',
129 ), $server->httpResponse->headers);
134 '/d:multistatus/d:response' => 1,
135 '/d:multistatus/d:response/d:href' => 1,
136 '/d:multistatus/d:response/d:propstat' => 1,
137 '/d:multistatus/d:response/d:propstat/d:prop' => 1,
138 '/d:multistatus/d:response/d:propstat/d:prop/s:href' => 1,
139 '/d:multistatus/d:response/d:propstat/d:prop/s:href/d:response' => 1,
140 '/d:multistatus/d:response/d:propstat/d:prop/s:href/d:response/d:href' => 1,
141 '/d:multistatus/d:response/d:propstat/d:prop/s:href/d:response/d:propstat' => 1,
142 '/d:multistatus/d:response/d:propstat/d:prop/s:href/d:response/d:propstat/d:prop' => 1,
143 '/d:multistatus/d:response/d:propstat/d:prop/s:href/d:response/d:propstat/d:prop/d:displayname' => 1,
146 $xml = simplexml_load_string($server->httpResponse->body);
147 $xml->registerXPathNamespace('d','DAV:');
148 $xml->registerXPathNamespace('s','http://sabredav.org/ns');
149 foreach($check as $v1=>$v2) {
151 $xpath = is_int($v1)?$v2:$v1;
153 $result = $xml->xpath($xpath);
156 if (!is_int($v1)) $count = $v2;
158 $this->assertEquals($count,count($result), 'we expected ' . $count . ' appearances of ' . $xpath . ' . We found ' . count($result));
165 * @depends testSimple
167 function testExpandHrefList() {
169 $xml = '<?xml version="1.0"?>
170 <d:expand-property xmlns:d="DAV:">
171 <d:property name="hreflist" namespace="http://sabredav.org/ns">
172 <d:property name="displayname" />
174 </d:expand-property>';
177 'REQUEST_METHOD' => 'REPORT',
179 'REQUEST_URI' => '/node2',
182 $request = new Sabre_HTTP_Request($serverVars);
183 $request->setBody($xml);
185 $server = $this->getServer();
186 $server->httpRequest = $request;
190 $this->assertEquals('HTTP/1.1 207 Multi-Status', $server->httpResponse->status);
191 $this->assertEquals(array(
192 'Content-Type' => 'application/xml; charset=utf-8',
193 ), $server->httpResponse->headers);
198 '/d:multistatus/d:response' => 1,
199 '/d:multistatus/d:response/d:href' => 1,
200 '/d:multistatus/d:response/d:propstat' => 1,
201 '/d:multistatus/d:response/d:propstat/d:prop' => 1,
202 '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist' => 1,
203 '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist/d:response' => 2,
204 '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist/d:response/d:href' => 2,
205 '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist/d:response/d:propstat' => 2,
206 '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist/d:response/d:propstat/d:prop' => 2,
207 '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist/d:response/d:propstat/d:prop/d:displayname' => 2,
210 $xml = simplexml_load_string($server->httpResponse->body);
211 $xml->registerXPathNamespace('d','DAV:');
212 $xml->registerXPathNamespace('s','http://sabredav.org/ns');
213 foreach($check as $v1=>$v2) {
215 $xpath = is_int($v1)?$v2:$v1;
217 $result = $xml->xpath($xpath);
220 if (!is_int($v1)) $count = $v2;
222 $this->assertEquals($count,count($result), 'we expected ' . $count . ' appearances of ' . $xpath . ' . We found ' . count($result));
229 * @depends testExpand
231 function testExpandDeep() {
233 $xml = '<?xml version="1.0"?>
234 <d:expand-property xmlns:d="DAV:">
235 <d:property name="hreflist" namespace="http://sabredav.org/ns">
236 <d:property name="href" namespace="http://sabredav.org/ns">
237 <d:property name="displayname" />
239 <d:property name="displayname" />
241 </d:expand-property>';
244 'REQUEST_METHOD' => 'REPORT',
246 'REQUEST_URI' => '/node2',
249 $request = new Sabre_HTTP_Request($serverVars);
250 $request->setBody($xml);
252 $server = $this->getServer();
253 $server->httpRequest = $request;
257 $this->assertEquals('HTTP/1.1 207 Multi-Status', $server->httpResponse->status);
258 $this->assertEquals(array(
259 'Content-Type' => 'application/xml; charset=utf-8',
260 ), $server->httpResponse->headers);
265 '/d:multistatus/d:response' => 1,
266 '/d:multistatus/d:response/d:href' => 1,
267 '/d:multistatus/d:response/d:propstat' => 1,
268 '/d:multistatus/d:response/d:propstat/d:prop' => 1,
269 '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist' => 1,
270 '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist/d:response' => 2,
271 '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist/d:response/d:href' => 2,
272 '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist/d:response/d:propstat' => 3,
273 '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist/d:response/d:propstat/d:prop' => 3,
274 '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist/d:response/d:propstat/d:prop/d:displayname' => 2,
275 '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist/d:response/d:propstat/d:prop/s:href' => 2,
276 '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist/d:response/d:propstat/d:prop/s:href/d:response' => 1,
277 '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist/d:response/d:propstat/d:prop/s:href/d:response/d:href' => 1,
278 '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist/d:response/d:propstat/d:prop/s:href/d:response/d:propstat' => 1,
279 '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist/d:response/d:propstat/d:prop/s:href/d:response/d:propstat/d:prop' => 1,
280 '/d:multistatus/d:response/d:propstat/d:prop/s:hreflist/d:response/d:propstat/d:prop/s:href/d:response/d:propstat/d:prop/d:displayname' => 1,
283 $xml = simplexml_load_string($server->httpResponse->body);
284 $xml->registerXPathNamespace('d','DAV:');
285 $xml->registerXPathNamespace('s','http://sabredav.org/ns');
286 foreach($check as $v1=>$v2) {
288 $xpath = is_int($v1)?$v2:$v1;
290 $result = $xml->xpath($xpath);
293 if (!is_int($v1)) $count = $v2;
295 $this->assertEquals($count,count($result), 'we expected ' . $count . ' appearances of ' . $xpath . ' . We found ' . count($result));
301 class Sabre_DAVACL_MockPropertyNode implements Sabre_DAV_INode, Sabre_DAV_IProperties {
303 function __construct($name, array $properties) {
306 $this->properties = $properties;
316 function getProperties($requestedProperties) {
318 $returnedProperties = array();
319 foreach($requestedProperties as $requestedProperty) {
320 if (isset($this->properties[$requestedProperty])) {
321 $returnedProperties[$requestedProperty] =
322 $this->properties[$requestedProperty];
325 return $returnedProperties;
331 throw new Sabre_DAV_Exception('Not implemented');
335 function setName($name) {
337 throw new Sabre_DAV_Exception('Not implemented');
341 function getLastModified() {
347 function updateProperties($properties) {
349 throw new Sabre_DAV_Exception('Not implemented');