ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PluginTest.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use Sabre\DAV;
6 use Sabre\HTTP;
7 
8 require_once 'Sabre/DAV/PartialUpdate/FileMock.php';
9 
11 
12  protected $node;
13  protected $plugin;
14 
15  function setUp() {
16 
17  $this->node = new FileMock();
18  $this->tree[] = $this->node;
19 
20  parent::setUp();
21 
22  $this->plugin = new Plugin();
23  $this->server->addPlugin($this->plugin);
24 
25 
26 
27  }
28 
29  function testInit() {
30 
31  $this->assertEquals('partialupdate', $this->plugin->getPluginName());
32  $this->assertEquals(['sabredav-partialupdate'], $this->plugin->getFeatures());
33  $this->assertEquals([
34  'PATCH'
35  ], $this->plugin->getHTTPMethods('partial'));
36  $this->assertEquals([
37  ], $this->plugin->getHTTPMethods(''));
38 
39  }
40 
41  function testPatchNoRange() {
42 
43  $this->node->put('aaaaaaaa');
45  'REQUEST_METHOD' => 'PATCH',
46  'REQUEST_URI' => '/partial',
47  ]);
48  $response = $this->request($request);
49 
50  $this->assertEquals(400, $response->status, 'Full response body:' . $response->body);
51 
52  }
53 
54  function testPatchNotSupported() {
55 
56  $this->node->put('aaaaaaaa');
57  $request = new HTTP\Request('PATCH', '/', ['X-Update-Range' => '3-4']);
58  $request->setBody(
59  'bbb'
60  );
61  $response = $this->request($request);
62 
63  $this->assertEquals(405, $response->status, 'Full response body:' . $response->body);
64 
65  }
66 
68 
69  $this->node->put('aaaaaaaa');
70  $request = new HTTP\Request('PATCH', '/partial', ['X-Update-Range' => 'bytes=3-4']);
71  $request->setBody(
72  'bbb'
73  );
74  $response = $this->request($request);
75 
76  $this->assertEquals(415, $response->status, 'Full response body:' . $response->body);
77 
78  }
79 
80  function testPatchBadRange() {
81 
82  $this->node->put('aaaaaaaa');
83  $request = new HTTP\Request('PATCH', '/partial', ['X-Update-Range' => 'bytes=3-4', 'Content-Type' => 'application/x-sabredav-partialupdate', 'Content-Length' => '3']);
84  $request->setBody(
85  'bbb'
86  );
87  $response = $this->request($request);
88 
89  $this->assertEquals(416, $response->status, 'Full response body:' . $response->body);
90 
91  }
92 
93  function testPatchNoLength() {
94 
95  $this->node->put('aaaaaaaa');
96  $request = new HTTP\Request('PATCH', '/partial', ['X-Update-Range' => 'bytes=3-5', 'Content-Type' => 'application/x-sabredav-partialupdate']);
97  $request->setBody(
98  'bbb'
99  );
100  $response = $this->request($request);
101 
102  $this->assertEquals(411, $response->status, 'Full response body:' . $response->body);
103 
104  }
105 
106  function testPatchSuccess() {
107 
108  $this->node->put('aaaaaaaa');
109  $request = new HTTP\Request('PATCH', '/partial', ['X-Update-Range' => 'bytes=3-5', 'Content-Type' => 'application/x-sabredav-partialupdate', 'Content-Length' => 3]);
110  $request->setBody(
111  'bbb'
112  );
113  $response = $this->request($request);
114 
115  $this->assertEquals(204, $response->status, 'Full response body:' . $response->body);
116  $this->assertEquals('aaabbbaa', $this->node->get());
117 
118  }
119 
120  function testPatchNoEndRange() {
121 
122  $this->node->put('aaaaa');
123  $request = new HTTP\Request('PATCH', '/partial', ['X-Update-Range' => 'bytes=3-', 'Content-Type' => 'application/x-sabredav-partialupdate', 'Content-Length' => '3']);
124  $request->setBody(
125  'bbb'
126  );
127 
128  $response = $this->request($request);
129 
130  $this->assertEquals(204, $response->getStatus(), 'Full response body:' . $response->getBodyAsString());
131  $this->assertEquals('aaabbb', $this->node->get());
132 
133  }
134 
135 }
foreach($paths as $path) $request
Definition: asyncclient.php:32
Partial update plugin (Patch method)
Definition: Plugin.php:23
This class may be used as a basis for other webdav-related unittests.
request($request, $expectedStatus=null)
Makes a request, and returns a response object.
static createFromServerArray(array $serverArray)
This static method will create a new Request object, based on a PHP $_SERVER array.
Definition: Sapi.php:107
$response