ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PrincipalSearchPropertySetTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Sabre\DAVACL;
4 
5 use Sabre\DAV;
6 use Sabre\HTTP;
7 
8 require_once 'Sabre/HTTP/ResponseMock.php';
9 
11 
12  function getServer() {
13 
14  $backend = new PrincipalBackend\Mock();
15 
16  $dir = new DAV\SimpleCollection('root');
17  $principals = new PrincipalCollection($backend);
18  $dir->addChild($principals);
19 
20  $fakeServer = new DAV\Server($dir);
21  $fakeServer->sapi = new HTTP\SapiMock();
22  $fakeServer->httpResponse = new HTTP\ResponseMock();
23  $plugin = new Plugin();
24  $plugin->allowUnauthenticatedAccess = false;
25  $this->assertTrue($plugin instanceof Plugin);
26  $fakeServer->addPlugin($plugin);
27  $this->assertEquals($plugin, $fakeServer->getPlugin('acl'));
28 
29  return $fakeServer;
30 
31  }
32 
33  function testDepth1() {
34 
35  $xml = '<?xml version="1.0"?>
36 <d:principal-search-property-set xmlns:d="DAV:" />';
37 
38  $serverVars = [
39  'REQUEST_METHOD' => 'REPORT',
40  'HTTP_DEPTH' => '1',
41  'REQUEST_URI' => '/principals',
42  ];
43 
45  $request->setBody($xml);
46 
47  $server = $this->getServer();
48  $server->httpRequest = $request;
49 
50  $server->exec();
51 
52  $this->assertEquals(400, $server->httpResponse->status);
53  $this->assertEquals([
54  'X-Sabre-Version' => [DAV\Version::VERSION],
55  'Content-Type' => ['application/xml; charset=utf-8'],
56  ], $server->httpResponse->getHeaders());
57 
58  }
59 
60  function testDepthIncorrectXML() {
61 
62  $xml = '<?xml version="1.0"?>
63 <d:principal-search-property-set xmlns:d="DAV:"><d:ohell /></d:principal-search-property-set>';
64 
65  $serverVars = [
66  'REQUEST_METHOD' => 'REPORT',
67  'HTTP_DEPTH' => '0',
68  'REQUEST_URI' => '/principals',
69  ];
70 
72  $request->setBody($xml);
73 
74  $server = $this->getServer();
75  $server->httpRequest = $request;
76 
77  $server->exec();
78 
79  $this->assertEquals(400, $server->httpResponse->status, $server->httpResponse->body);
80  $this->assertEquals([
81  'X-Sabre-Version' => [DAV\Version::VERSION],
82  'Content-Type' => ['application/xml; charset=utf-8'],
83  ], $server->httpResponse->getHeaders());
84 
85  }
86 
87  function testCorrect() {
88 
89  $xml = '<?xml version="1.0"?>
90 <d:principal-search-property-set xmlns:d="DAV:"/>';
91 
92  $serverVars = [
93  'REQUEST_METHOD' => 'REPORT',
94  'HTTP_DEPTH' => '0',
95  'REQUEST_URI' => '/principals',
96  ];
97 
99  $request->setBody($xml);
100 
101  $server = $this->getServer();
102  $server->httpRequest = $request;
103 
104  $server->exec();
105 
106  $this->assertEquals(200, $server->httpResponse->status, $server->httpResponse->body);
107  $this->assertEquals([
108  'X-Sabre-Version' => [DAV\Version::VERSION],
109  'Content-Type' => ['application/xml; charset=utf-8'],
110  ], $server->httpResponse->getHeaders());
111 
112 
113  $check = [
114  '/d:principal-search-property-set',
115  '/d:principal-search-property-set/d:principal-search-property' => 2,
116  '/d:principal-search-property-set/d:principal-search-property/d:prop' => 2,
117  '/d:principal-search-property-set/d:principal-search-property/d:prop/d:displayname' => 1,
118  '/d:principal-search-property-set/d:principal-search-property/d:prop/s:email-address' => 1,
119  '/d:principal-search-property-set/d:principal-search-property/d:description' => 2,
120  ];
121 
122  $xml = simplexml_load_string($server->httpResponse->body);
123  $xml->registerXPathNamespace('d', 'DAV:');
124  $xml->registerXPathNamespace('s', 'http://sabredav.org/ns');
125  foreach ($check as $v1 => $v2) {
126 
127  $xpath = is_int($v1) ? $v2 : $v1;
128 
129  $result = $xml->xpath($xpath);
130 
131  $count = 1;
132  if (!is_int($v1)) $count = $v2;
133 
134  $this->assertEquals($count, count($result), 'we expected ' . $count . ' appearances of ' . $xpath . ' . We found ' . count($result) . '. Full response body: ' . $server->httpResponse->body);
135 
136  }
137 
138  }
139 
140 }
$result
foreach($paths as $path) $request
Definition: asyncclient.php:32
$server
Definition: sabredav.php:48
const VERSION
Full version number.
Definition: Version.php:17
Main DAV server class.
Definition: Server.php:23
static createFromServerArray(array $serverArray)
This static method will create a new Request object, based on a PHP $_SERVER array.
Definition: Sapi.php:107
SabreDAV ACL Plugin.
Definition: Plugin.php:31