ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ClientTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Sabre\DAV;
4 
7 
8 require_once 'Sabre/DAV/ClientMock.php';
9 
11 
12  function setUp() {
13 
14  if (!function_exists('curl_init')) {
15  $this->markTestSkipped('CURL must be installed to test the client');
16  }
17 
18  }
19 
20  function testConstruct() {
21 
22  $client = new ClientMock([
23  'baseUri' => '/',
24  ]);
25  $this->assertInstanceOf('Sabre\DAV\ClientMock', $client);
26 
27  }
28 
33 
34  $client = new ClientMock([]);
35 
36  }
37 
38  function testAuth() {
39 
40  $client = new ClientMock([
41  'baseUri' => '/',
42  'userName' => 'foo',
43  'password' => 'bar',
44  ]);
45 
46  $this->assertEquals("foo:bar", $client->curlSettings[CURLOPT_USERPWD]);
47  $this->assertEquals(CURLAUTH_BASIC | CURLAUTH_DIGEST, $client->curlSettings[CURLOPT_HTTPAUTH]);
48 
49  }
50 
51  function testBasicAuth() {
52 
53  $client = new ClientMock([
54  'baseUri' => '/',
55  'userName' => 'foo',
56  'password' => 'bar',
57  'authType' => Client::AUTH_BASIC
58  ]);
59 
60  $this->assertEquals("foo:bar", $client->curlSettings[CURLOPT_USERPWD]);
61  $this->assertEquals(CURLAUTH_BASIC, $client->curlSettings[CURLOPT_HTTPAUTH]);
62 
63  }
64 
65  function testDigestAuth() {
66 
67  $client = new ClientMock([
68  'baseUri' => '/',
69  'userName' => 'foo',
70  'password' => 'bar',
71  'authType' => Client::AUTH_DIGEST
72  ]);
73 
74  $this->assertEquals("foo:bar", $client->curlSettings[CURLOPT_USERPWD]);
75  $this->assertEquals(CURLAUTH_DIGEST, $client->curlSettings[CURLOPT_HTTPAUTH]);
76 
77  }
78 
79  function testNTLMAuth() {
80 
81  $client = new ClientMock([
82  'baseUri' => '/',
83  'userName' => 'foo',
84  'password' => 'bar',
85  'authType' => Client::AUTH_NTLM
86  ]);
87 
88  $this->assertEquals("foo:bar", $client->curlSettings[CURLOPT_USERPWD]);
89  $this->assertEquals(CURLAUTH_NTLM, $client->curlSettings[CURLOPT_HTTPAUTH]);
90 
91  }
92 
93  function testProxy() {
94 
95  $client = new ClientMock([
96  'baseUri' => '/',
97  'proxy' => 'localhost:8888',
98  ]);
99 
100  $this->assertEquals("localhost:8888", $client->curlSettings[CURLOPT_PROXY]);
101 
102  }
103 
104  function testEncoding() {
105 
106  $client = new ClientMock([
107  'baseUri' => '/',
109  ]);
110 
111  $this->assertEquals("identity,deflate,gzip", $client->curlSettings[CURLOPT_ENCODING]);
112 
113  }
114 
115  function testPropFind() {
116 
117  $client = new ClientMock([
118  'baseUri' => '/',
119  ]);
120 
121  $responseBody = <<<XML
122 <?xml version="1.0"?>
123 <multistatus xmlns="DAV:">
124  <response>
125  <href>/foo</href>
126  <propstat>
127  <prop>
128  <displayname>bar</displayname>
129  </prop>
130  <status>HTTP/1.1 200 OK</status>
131  </propstat>
132  </response>
133 </multistatus>
134 XML;
135 
136  $client->response = new Response(207, [], $responseBody);
137  $result = $client->propFind('foo', ['{DAV:}displayname', '{urn:zim}gir']);
138 
139  $this->assertEquals(['{DAV:}displayname' => 'bar'], $result);
140 
141  $request = $client->request;
142  $this->assertEquals('PROPFIND', $request->getMethod());
143  $this->assertEquals('/foo', $request->getUrl());
144  $this->assertEquals([
145  'Depth' => ['0'],
146  'Content-Type' => ['application/xml'],
147  ], $request->getHeaders());
148 
149  }
150 
154  function testPropFindError() {
155 
156  $client = new ClientMock([
157  'baseUri' => '/',
158  ]);
159 
160  $client->response = new Response(405, []);
161  $client->propFind('foo', ['{DAV:}displayname', '{urn:zim}gir']);
162 
163  }
164 
165  function testPropFindDepth1() {
166 
167  $client = new ClientMock([
168  'baseUri' => '/',
169  ]);
170 
171  $responseBody = <<<XML
172 <?xml version="1.0"?>
173 <multistatus xmlns="DAV:">
174  <response>
175  <href>/foo</href>
176  <propstat>
177  <prop>
178  <displayname>bar</displayname>
179  </prop>
180  <status>HTTP/1.1 200 OK</status>
181  </propstat>
182  </response>
183 </multistatus>
184 XML;
185 
186  $client->response = new Response(207, [], $responseBody);
187  $result = $client->propFind('foo', ['{DAV:}displayname', '{urn:zim}gir'], 1);
188 
189  $this->assertEquals([
190  '/foo' => [
191  '{DAV:}displayname' => 'bar'
192  ],
193  ], $result);
194 
195  $request = $client->request;
196  $this->assertEquals('PROPFIND', $request->getMethod());
197  $this->assertEquals('/foo', $request->getUrl());
198  $this->assertEquals([
199  'Depth' => ['1'],
200  'Content-Type' => ['application/xml'],
201  ], $request->getHeaders());
202 
203  }
204 
205  function testPropPatch() {
206 
207  $client = new ClientMock([
208  'baseUri' => '/',
209  ]);
210 
211  $responseBody = <<<XML
212 <?xml version="1.0"?>
213 <multistatus xmlns="DAV:">
214  <response>
215  <href>/foo</href>
216  <propstat>
217  <prop>
218  <displayname>bar</displayname>
219  </prop>
220  <status>HTTP/1.1 200 OK</status>
221  </propstat>
222  </response>
223 </multistatus>
224 XML;
225 
226  $client->response = new Response(207, [], $responseBody);
227  $result = $client->propPatch('foo', ['{DAV:}displayname' => 'hi', '{urn:zim}gir' => null]);
228  $this->assertTrue($result);
229  $request = $client->request;
230  $this->assertEquals('PROPPATCH', $request->getMethod());
231  $this->assertEquals('/foo', $request->getUrl());
232  $this->assertEquals([
233  'Content-Type' => ['application/xml'],
234  ], $request->getHeaders());
235 
236  }
237 
243 
244  $client = new ClientMock([
245  'baseUri' => '/',
246  ]);
247 
248  $client->response = new Response(403, [], '');
249  $client->propPatch('foo', ['{DAV:}displayname' => 'hi', '{urn:zim}gir' => null]);
250 
251  }
252 
258 
259  $client = new ClientMock([
260  'baseUri' => '/',
261  ]);
262 
263  $responseBody = <<<XML
264 <?xml version="1.0"?>
265 <multistatus xmlns="DAV:">
266 <response>
267  <href>/foo</href>
268  <propstat>
269  <prop>
270  <displayname />
271  </prop>
272  <status>HTTP/1.1 403 Forbidden</status>
273  </propstat>
274 </response>
275 </multistatus>
276 XML;
277 
278  $client->response = new Response(207, [], $responseBody);
279  $client->propPatch('foo', ['{DAV:}displayname' => 'hi', '{urn:zim}gir' => null]);
280 
281  }
282 
283  function testOPTIONS() {
284 
285  $client = new ClientMock([
286  'baseUri' => '/',
287  ]);
288 
289  $client->response = new Response(207, [
290  'DAV' => 'calendar-access, extended-mkcol',
291  ]);
292  $result = $client->options();
293 
294  $this->assertEquals(
295  ['calendar-access', 'extended-mkcol'],
296  $result
297  );
298 
299  $request = $client->request;
300  $this->assertEquals('OPTIONS', $request->getMethod());
301  $this->assertEquals('/', $request->getUrl());
302  $this->assertEquals([
303  ], $request->getHeaders());
304 
305  }
306 }
const ENCODING_GZIP
Gzip encoding.
Definition: Client.php:79
$result
foreach($paths as $path) $request
Definition: asyncclient.php:32
if($_SERVER['argc']< 4) $client
Definition: cron.php:12
const AUTH_NTLM
NTLM authentication.
Definition: Client.php:64
testConstructNoBaseUri()
InvalidArgumentException
Definition: ClientTest.php:32
const AUTH_DIGEST
Digest authentication.
Definition: Client.php:59
testPropPatchMultiStatusError()
testPropPatch Sabre
Definition: ClientTest.php:257
This class represents a single HTTP response.
Definition: Response.php:12
testPropPatchHTTPError()
testPropPatch
Definition: ClientTest.php:242
const ENCODING_IDENTITY
Identity encoding, which basically does not nothing.
Definition: Client.php:69
const ENCODING_DEFLATE
Deflate encoding.
Definition: Client.php:74
const AUTH_BASIC
Basic authentication.
Definition: Client.php:54