ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ServerPropsTest.php
Go to the documentation of this file.
1<?php
2
3namespace Sabre\DAV;
4
5use Sabre\HTTP;
6
7require_once 'Sabre/HTTP/ResponseMock.php';
8require_once 'Sabre/DAV/AbstractServer.php';
9
11
12 protected function getRootNode() {
13
14 return new FSExt\Directory(SABRE_TEMPDIR);
15
16 }
17
18 function setUp() {
19
20 if (file_exists(SABRE_TEMPDIR . '../.sabredav')) unlink(SABRE_TEMPDIR . '../.sabredav');
21 parent::setUp();
22 file_put_contents(SABRE_TEMPDIR . '/test2.txt', 'Test contents2');
23 mkdir(SABRE_TEMPDIR . '/col');
24 file_put_contents(SABRE_TEMPDIR . 'col/test.txt', 'Test contents');
25 $this->server->addPlugin(new Locks\Plugin(new Locks\Backend\File(SABRE_TEMPDIR . '/.locksdb')));
26
27 }
28
29 function tearDown() {
30
32 if (file_exists(SABRE_TEMPDIR . '../.locksdb')) unlink(SABRE_TEMPDIR . '../.locksdb');
33
34 }
35
36 private function sendRequest($body, $path = '/', $headers = ['Depth' => '0']) {
37
38 $request = new HTTP\Request('PROPFIND', $path, $headers, $body);
39
40 $this->server->httpRequest = $request;
41 $this->server->exec();
42
43 }
44
46
47 $this->sendRequest("");
48 $this->assertEquals(207, $this->response->status);
49
50 $this->assertEquals([
51 'X-Sabre-Version' => [Version::VERSION],
52 'Content-Type' => ['application/xml; charset=utf-8'],
53 'DAV' => ['1, 3, extended-mkcol, 2'],
54 'Vary' => ['Brief,Prefer'],
55 ],
56 $this->response->getHeaders()
57 );
58
59 $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", "xmlns\\1=\"urn:DAV\"", $this->response->body);
60 $xml = simplexml_load_string($body);
61 $xml->registerXPathNamespace('d', 'urn:DAV');
62
63 list($data) = $xml->xpath('/d:multistatus/d:response/d:href');
64 $this->assertEquals('/', (string)$data, 'href element should have been /');
65
66 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:resourcetype');
67 $this->assertEquals(1, count($data));
68
69 }
70
72
73 $this->sendRequest("", '/test2.txt', []);
74 $this->assertEquals(207, $this->response->status);
75
76 $this->assertEquals([
77 'X-Sabre-Version' => [Version::VERSION],
78 'Content-Type' => ['application/xml; charset=utf-8'],
79 'DAV' => ['1, 3, extended-mkcol, 2'],
80 'Vary' => ['Brief,Prefer'],
81 ],
82 $this->response->getHeaders()
83 );
84
85 $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", "xmlns\\1=\"urn:DAV\"", $this->response->body);
86 $xml = simplexml_load_string($body);
87 $xml->registerXPathNamespace('d', 'urn:DAV');
88
89 list($data) = $xml->xpath('/d:multistatus/d:response/d:href');
90 $this->assertEquals('/test2.txt', (string)$data, 'href element should have been /test2.txt');
91
92 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:getcontentlength');
93 $this->assertEquals(1, count($data));
94
95 }
96
97 function testSupportedLocks() {
98
99 $xml = '<?xml version="1.0"?>
100<d:propfind xmlns:d="DAV:">
101 <d:prop>
102 <d:supportedlock />
103 </d:prop>
104</d:propfind>';
105
106 $this->sendRequest($xml);
107
108 $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", "xmlns\\1=\"urn:DAV\"", $this->response->body);
109 $xml = simplexml_load_string($body);
110 $xml->registerXPathNamespace('d', 'urn:DAV');
111
112 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry');
113 $this->assertEquals(2, count($data), 'We expected two \'d:lockentry\' tags');
114
115 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry/d:lockscope');
116 $this->assertEquals(2, count($data), 'We expected two \'d:lockscope\' tags');
117
118 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry/d:locktype');
119 $this->assertEquals(2, count($data), 'We expected two \'d:locktype\' tags');
120
121 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry/d:lockscope/d:shared');
122 $this->assertEquals(1, count($data), 'We expected a \'d:shared\' tag');
123
124 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry/d:lockscope/d:exclusive');
125 $this->assertEquals(1, count($data), 'We expected a \'d:exclusive\' tag');
126
127 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry/d:locktype/d:write');
128 $this->assertEquals(2, count($data), 'We expected two \'d:write\' tags');
129 }
130
131 function testLockDiscovery() {
132
133 $xml = '<?xml version="1.0"?>
134<d:propfind xmlns:d="DAV:">
135 <d:prop>
136 <d:lockdiscovery />
137 </d:prop>
138</d:propfind>';
139
140 $this->sendRequest($xml);
141
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
146 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:lockdiscovery');
147 $this->assertEquals(1, count($data), 'We expected a \'d:lockdiscovery\' tag');
148
149 }
150
152
153 $xml = '<?xml version="1.0"?>
154<d:propfind xmlns:d="DAV:">
155 <d:prop>
156 <d:macaroni />
157 </d:prop>
158</d:propfind>';
159
160 $this->sendRequest($xml);
161 $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", "xmlns\\1=\"urn:DAV\"", $this->response->body);
162 $xml = simplexml_load_string($body);
163 $xml->registerXPathNamespace('d', 'urn:DAV');
164 $pathTests = [
165 '/d:multistatus',
166 '/d:multistatus/d:response',
167 '/d:multistatus/d:response/d:propstat',
168 '/d:multistatus/d:response/d:propstat/d:status',
169 '/d:multistatus/d:response/d:propstat/d:prop',
170 '/d:multistatus/d:response/d:propstat/d:prop/d:macaroni',
171 ];
172 foreach ($pathTests as $test) {
173 $this->assertTrue(count($xml->xpath($test)) == true, 'We expected the ' . $test . ' element to appear in the response, we got: ' . $body);
174 }
175
176 $val = $xml->xpath('/d:multistatus/d:response/d:propstat/d:status');
177 $this->assertEquals(1, count($val), $body);
178 $this->assertEquals('HTTP/1.1 404 Not Found', (string)$val[0]);
179
180 }
181
183
184 $body = '<?xml version="1.0"?>
185<d:propertyupdate xmlns:d="DAV:" xmlns:s="http://sabredav.org/NS/test">
186 <d:set><d:prop><s:someprop>somevalue</s:someprop></d:prop></d:set>
187 <d:remove><d:prop><s:someprop2 /></d:prop></d:remove>
188 <d:set><d:prop><s:someprop3>removeme</s:someprop3></d:prop></d:set>
189 <d:remove><d:prop><s:someprop3 /></d:prop></d:remove>
190</d:propertyupdate>';
191
192 $result = $this->server->xml->parse($body);
193 $this->assertEquals([
194 '{http://sabredav.org/NS/test}someprop' => 'somevalue',
195 '{http://sabredav.org/NS/test}someprop2' => null,
196 '{http://sabredav.org/NS/test}someprop3' => null,
197 ], $result->properties);
198
199 }
200
201}
$result
$test
Definition: Utf8Test.php:84
$path
Definition: aliased.php:25
An exception for terminatinating execution or to throw for unit testing.
Directory class.
Definition: Directory.php:15
File class.
Definition: File.php:15
sendRequest($body, $path='/', $headers=['Depth'=> '0'])
const VERSION
Full version number.
Definition: Version.php:17
$data
Definition: bench.php:6