3 require_once 'Sabre/HTTP/ResponseMock.php';
4 require_once 'Sabre/DAV/Auth/MockBackend.php';
5 require_once 'Sabre/DAVACL/MockPrincipalBackend.php';
7 class Sabre_DAVACL_PrincipalPropertySearchTest extends PHPUnit_Framework_TestCase {
11 $backend = new Sabre_DAVACL_MockPrincipalBackend();
13 $dir = new Sabre_DAV_SimpleCollection('root');
14 $principals = new Sabre_DAVACL_PrincipalCollection($backend);
15 $dir->addChild($principals);
17 $fakeServer = new Sabre_DAV_Server(new Sabre_DAV_ObjectTree($dir));
18 $fakeServer->httpResponse = new Sabre_HTTP_ResponseMock();
19 $fakeServer->debugExceptions = true;
20 $plugin = new Sabre_DAVACL_MockPlugin($backend,'realm');
21 $plugin->allowAccessToNodesWithoutACL = true;
23 $this->assertTrue($plugin instanceof Sabre_DAVACL_Plugin);
24 $fakeServer->addPlugin($plugin);
25 $this->assertEquals($plugin, $fakeServer->getPlugin('acl'));
31 function testDepth1() {
33 $xml = '<?xml version="1.0"?>
34 <d:principal-property-search xmlns:d="DAV:">
39 <d:match>user</d:match>
43 <d:getcontentlength />
45 </d:principal-property-search>';
48 'REQUEST_METHOD' => 'REPORT',
50 'REQUEST_URI' => '/principals',
53 $request = new Sabre_HTTP_Request($serverVars);
54 $request->setBody($xml);
56 $server = $this->getServer();
57 $server->httpRequest = $request;
61 $this->assertEquals('HTTP/1.1 400 Bad request', $server->httpResponse->status);
62 $this->assertEquals(array(
63 'Content-Type' => 'application/xml; charset=utf-8',
64 ), $server->httpResponse->headers);
69 function testUnknownSearchField() {
71 $xml = '<?xml version="1.0"?>
72 <d:principal-property-search xmlns:d="DAV:">
77 <d:match>user</d:match>
81 <d:getcontentlength />
83 </d:principal-property-search>';
86 'REQUEST_METHOD' => 'REPORT',
88 'REQUEST_URI' => '/principals',
91 $request = new Sabre_HTTP_Request($serverVars);
92 $request->setBody($xml);
94 $server = $this->getServer();
95 $server->httpRequest = $request;
99 $this->assertEquals('HTTP/1.1 207 Multi-Status', $server->httpResponse->status);
100 $this->assertEquals(array(
101 'Content-Type' => 'application/xml; charset=utf-8',
102 ), $server->httpResponse->headers);
106 function testCorrect() {
108 $xml = '<?xml version="1.0"?>
109 <d:principal-property-search xmlns:d="DAV:">
110 <d:apply-to-principal-collection-set />
115 <d:match>user</d:match>
119 <d:getcontentlength />
121 </d:principal-property-search>';
124 'REQUEST_METHOD' => 'REPORT',
126 'REQUEST_URI' => '/',
129 $request = new Sabre_HTTP_Request($serverVars);
130 $request->setBody($xml);
132 $server = $this->getServer();
133 $server->httpRequest = $request;
137 $this->assertEquals('HTTP/1.1 207 Multi-Status', $server->httpResponse->status, $server->httpResponse->body);
138 $this->assertEquals(array(
139 'Content-Type' => 'application/xml; charset=utf-8',
140 ), $server->httpResponse->headers);
145 '/d:multistatus/d:response' => 2,
146 '/d:multistatus/d:response/d:href' => 2,
147 '/d:multistatus/d:response/d:propstat' => 4,
148 '/d:multistatus/d:response/d:propstat/d:prop' => 4,
149 '/d:multistatus/d:response/d:propstat/d:prop/d:displayname' => 2,
150 '/d:multistatus/d:response/d:propstat/d:prop/d:getcontentlength' => 2,
151 '/d:multistatus/d:response/d:propstat/d:status' => 4,
154 $xml = simplexml_load_string($server->httpResponse->body);
155 $xml->registerXPathNamespace('d','DAV:');
156 foreach($check as $v1=>$v2) {
158 $xpath = is_int($v1)?$v2:$v1;
160 $result = $xml->xpath($xpath);
163 if (!is_int($v1)) $count = $v2;
165 $this->assertEquals($count,count($result), 'we expected ' . $count . ' appearances of ' . $xpath . ' . We found ' . count($result) . '. Full response body: ' . $server->httpResponse->body);
170 function testWrongUri() {
172 $xml = '<?xml version="1.0"?>
173 <d:principal-property-search xmlns:d="DAV:">
178 <d:match>user</d:match>
182 <d:getcontentlength />
184 </d:principal-property-search>';
187 'REQUEST_METHOD' => 'REPORT',
189 'REQUEST_URI' => '/',
192 $request = new Sabre_HTTP_Request($serverVars);
193 $request->setBody($xml);
195 $server = $this->getServer();
196 $server->httpRequest = $request;
200 $this->assertEquals('HTTP/1.1 207 Multi-Status', $server->httpResponse->status, $server->httpResponse->body);
201 $this->assertEquals(array(
202 'Content-Type' => 'application/xml; charset=utf-8',
203 ), $server->httpResponse->headers);
208 '/d:multistatus/d:response' => 0,
211 $xml = simplexml_load_string($server->httpResponse->body);
212 $xml->registerXPathNamespace('d','DAV:');
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) . '. Full response body: ' . $server->httpResponse->body);
229 class Sabre_DAVACL_MockPlugin extends Sabre_DAVACL_Plugin {
231 function getCurrentUserPrivilegeSet($node) {