ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ServerPropsInfiniteDepthTest.php
Go to the documentation of this file.
1<?php
2
3namespace Sabre\DAV;
4
5use Sabre\HTTP;
6
7require_once 'Sabre/DAV/AbstractServer.php';
8
10
11 protected function getRootNode() {
12
13 return new FSExt\Directory(SABRE_TEMPDIR);
14
15 }
16
17 function setUp() {
18
19 if (file_exists(SABRE_TEMPDIR . '../.sabredav')) unlink(SABRE_TEMPDIR . '../.sabredav');
20 parent::setUp();
21 file_put_contents(SABRE_TEMPDIR . '/test2.txt', 'Test contents2');
22 mkdir(SABRE_TEMPDIR . '/col');
23 mkdir(SABRE_TEMPDIR . '/col/col');
24 file_put_contents(SABRE_TEMPDIR . 'col/col/test.txt', 'Test contents');
25 $this->server->addPlugin(new Locks\Plugin(new Locks\Backend\File(SABRE_TEMPDIR . '/.locksdb')));
26 $this->server->enablePropfindDepthInfinity = true;
27
28 }
29
30 function tearDown() {
31
33 if (file_exists(SABRE_TEMPDIR . '../.locksdb')) unlink(SABRE_TEMPDIR . '../.locksdb');
34
35 }
36
37 private function sendRequest($body) {
38
39 $request = new HTTP\Request('PROPFIND', '/', ['Depth' => 'infinity']);
40 $request->setBody($body);
41
42 $this->server->httpRequest = $request;
43 $this->server->exec();
44
45 }
46
48
49 $this->sendRequest("");
50
51 $this->assertEquals(207, $this->response->status, 'Incorrect status received. Full response body: ' . $this->response->getBodyAsString());
52
53 $this->assertEquals([
54 'X-Sabre-Version' => [Version::VERSION],
55 'Content-Type' => ['application/xml; charset=utf-8'],
56 'DAV' => ['1, 3, extended-mkcol, 2'],
57 'Vary' => ['Brief,Prefer'],
58 ],
59 $this->response->getHeaders()
60 );
61
62 $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", "xmlns\\1=\"urn:DAV\"", $this->response->body);
63 $xml = simplexml_load_string($body);
64 $xml->registerXPathNamespace('d', 'urn:DAV');
65
66 list($data) = $xml->xpath('/d:multistatus/d:response/d:href');
67 $this->assertEquals('/', (string)$data, 'href element should have been /');
68
69 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:resourcetype');
70 // 8 resources are to be returned: /, col, col/col, col/col/test.txt, dir, dir/child.txt, test.txt and test2.txt
71 $this->assertEquals(8, count($data));
72
73 }
74
75 function testSupportedLocks() {
76
77 $xml = '<?xml version="1.0"?>
78<d:propfind xmlns:d="DAV:">
79 <d:prop>
80 <d:supportedlock />
81 </d:prop>
82</d:propfind>';
83
84 $this->sendRequest($xml);
85
86 $body = $this->response->getBodyAsString();
87 $this->assertEquals(207, $this->response->getStatus(), $body);
88
89 $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", "xmlns\\1=\"urn:DAV\"", $body);
90 $xml = simplexml_load_string($body);
91 $xml->registerXPathNamespace('d', 'urn:DAV');
92
93 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry');
94 $this->assertEquals(16, count($data), 'We expected sixteen \'d:lockentry\' tags');
95
96 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry/d:lockscope');
97 $this->assertEquals(16, count($data), 'We expected sixteen \'d:lockscope\' tags');
98
99 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry/d:locktype');
100 $this->assertEquals(16, count($data), 'We expected sixteen \'d:locktype\' tags');
101
102 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry/d:lockscope/d:shared');
103 $this->assertEquals(8, count($data), 'We expected eight \'d:shared\' tags');
104
105 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry/d:lockscope/d:exclusive');
106 $this->assertEquals(8, count($data), 'We expected eight \'d:exclusive\' tags');
107
108 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry/d:locktype/d:write');
109 $this->assertEquals(16, count($data), 'We expected sixteen \'d:write\' tags');
110 }
111
112 function testLockDiscovery() {
113
114 $xml = '<?xml version="1.0"?>
115<d:propfind xmlns:d="DAV:">
116 <d:prop>
117 <d:lockdiscovery />
118 </d:prop>
119</d:propfind>';
120
121 $this->sendRequest($xml);
122
123 $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", "xmlns\\1=\"urn:DAV\"", $this->response->body);
124 $xml = simplexml_load_string($body);
125 $xml->registerXPathNamespace('d', 'urn:DAV');
126
127 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:lockdiscovery');
128 $this->assertEquals(8, count($data), 'We expected eight \'d:lockdiscovery\' tags');
129
130 }
131
133
134 $xml = '<?xml version="1.0"?>
135<d:propfind xmlns:d="DAV:">
136 <d:prop>
137 <d:macaroni />
138 </d:prop>
139</d:propfind>';
140
141 $this->sendRequest($xml);
142 $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", "xmlns\\1=\"urn:DAV\"", $this->response->body);
143 $xml = simplexml_load_string($body);
144 $xml->registerXPathNamespace('d', 'urn:DAV');
145 $pathTests = [
146 '/d:multistatus',
147 '/d:multistatus/d:response',
148 '/d:multistatus/d:response/d:propstat',
149 '/d:multistatus/d:response/d:propstat/d:status',
150 '/d:multistatus/d:response/d:propstat/d:prop',
151 '/d:multistatus/d:response/d:propstat/d:prop/d:macaroni',
152 ];
153 foreach ($pathTests as $test) {
154 $this->assertTrue(count($xml->xpath($test)) == true, 'We expected the ' . $test . ' element to appear in the response, we got: ' . $body);
155 }
156
157 $val = $xml->xpath('/d:multistatus/d:response/d:propstat/d:status');
158 $this->assertEquals(8, count($val), $body);
159 $this->assertEquals('HTTP/1.1 404 Not Found', (string)$val[0]);
160
161 }
162
163}
$test
Definition: Utf8Test.php:84
An exception for terminatinating execution or to throw for unit testing.
Directory class.
Definition: Directory.php:15
File class.
Definition: File.php:15
const VERSION
Full version number.
Definition: Version.php:17
$data
Definition: bench.php:6