ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
SpecificationTest.php
Go to the documentation of this file.
1 <?php
2 
4 
7 use Sabre\HTTP;
8 
16 
17  protected $server;
18 
19  function setUp() {
20 
21  $tree = [
22  new File(SABRE_TEMPDIR . '/foobar.txt')
23  ];
24  $server = new Server($tree);
25  $server->debugExceptions = true;
26  $server->addPlugin(new Plugin());
27 
28  $tree[0]->put('1234567890');
29 
30  $this->server = $server;
31 
32  }
33 
34  function tearDown() {
35 
37 
38  }
39 
48  function testUpdateRange($headerValue, $httpStatus, $endResult, $contentLength = 4) {
49 
50  $headers = [
51  'Content-Type' => 'application/x-sabredav-partialupdate',
52  'X-Update-Range' => $headerValue,
53  ];
54 
55  if ($contentLength) {
56  $headers['Content-Length'] = (string)$contentLength;
57  }
58 
59  $request = new HTTP\Request('PATCH', '/foobar.txt', $headers, '----');
60 
61  $request->setBody('----');
62  $this->server->httpRequest = $request;
63  $this->server->httpResponse = new HTTP\ResponseMock();
64  $this->server->sapi = new HTTP\SapiMock();
65  $this->server->exec();
66 
67  $this->assertEquals($httpStatus, $this->server->httpResponse->status, 'Incorrect http status received: ' . $this->server->httpResponse->body);
68  if (!is_null($endResult)) {
69  $this->assertEquals($endResult, file_get_contents(SABRE_TEMPDIR . '/foobar.txt'));
70  }
71 
72  }
73 
74  function data() {
75 
76  return [
77  // Problems
78  ['foo', 400, null],
79  ['bytes=0-3', 411, null, 0],
80  ['bytes=4-1', 416, null],
81 
82  ['bytes=0-3', 204, '----567890'],
83  ['bytes=1-4', 204, '1----67890'],
84  ['bytes=0-', 204, '----567890'],
85  ['bytes=-4', 204, '123456----'],
86  ['bytes=-2', 204, '12345678----'],
87  ['bytes=2-', 204, '12----7890'],
88  ['append', 204, '1234567890----'],
89 
90  ];
91 
92  }
93 
94 }
foreach($paths as $path) $request
Definition: asyncclient.php:32
Partial update plugin (Patch method)
Definition: Plugin.php:23
if(preg_match('#\.( $contentLength[^/\.]+)$#D', $path, $type)) if($contentType===null)
Definition: module.php:165
Main DAV server class.
Definition: Server.php:23
testUpdateRange($headerValue, $httpStatus, $endResult, $contentLength=4)
This test is an end-to-end sabredav test that goes through all the cases in the specification.
static clearTempDir()
This function deletes all the contents of the temporary directory.
Definition: TestUtil.php:12