ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
GetIfConditionsTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Sabre\DAV;
4 
5 use Sabre\HTTP;
6 
7 require_once 'Sabre/HTTP/ResponseMock.php';
8 require_once 'Sabre/DAV/AbstractServer.php';
9 
11 
12  function testNoConditions() {
13 
14  $request = new HTTP\Request();
15 
16  $conditions = $this->server->getIfConditions($request);
17  $this->assertEquals([], $conditions);
18 
19  }
20 
21  function testLockToken() {
22 
23  $request = new HTTP\Request('GET', '/path/', ['If' => '(<opaquelocktoken:token1>)']);
24  $conditions = $this->server->getIfConditions($request);
25 
26  $compare = [
27 
28  [
29  'uri' => 'path',
30  'tokens' => [
31  [
32  'negate' => false,
33  'token' => 'opaquelocktoken:token1',
34  'etag' => '',
35  ],
36  ],
37 
38  ],
39 
40  ];
41 
42  $this->assertEquals($compare, $conditions);
43 
44  }
45 
46  function testNotLockToken() {
47 
48  $serverVars = [
49  'HTTP_IF' => '(Not <opaquelocktoken:token1>)',
50  'REQUEST_URI' => '/bla'
51  ];
52 
54  $conditions = $this->server->getIfConditions($request);
55 
56  $compare = [
57 
58  [
59  'uri' => 'bla',
60  'tokens' => [
61  [
62  'negate' => true,
63  'token' => 'opaquelocktoken:token1',
64  'etag' => '',
65  ],
66  ],
67 
68  ],
69 
70  ];
71  $this->assertEquals($compare, $conditions);
72 
73  }
74 
75  function testLockTokenUrl() {
76 
77  $serverVars = [
78  'HTTP_IF' => '<http://www.example.com/> (<opaquelocktoken:token1>)',
79  ];
80 
82  $conditions = $this->server->getIfConditions($request);
83 
84  $compare = [
85 
86  [
87  'uri' => '',
88  'tokens' => [
89  [
90  'negate' => false,
91  'token' => 'opaquelocktoken:token1',
92  'etag' => '',
93  ],
94  ],
95 
96  ],
97 
98  ];
99  $this->assertEquals($compare, $conditions);
100 
101  }
102 
103  function test2LockTokens() {
104 
105  $serverVars = [
106  'HTTP_IF' => '(<opaquelocktoken:token1>) (Not <opaquelocktoken:token2>)',
107  'REQUEST_URI' => '/bla',
108  ];
109 
111  $conditions = $this->server->getIfConditions($request);
112 
113  $compare = [
114 
115  [
116  'uri' => 'bla',
117  'tokens' => [
118  [
119  'negate' => false,
120  'token' => 'opaquelocktoken:token1',
121  'etag' => '',
122  ],
123  [
124  'negate' => true,
125  'token' => 'opaquelocktoken:token2',
126  'etag' => '',
127  ],
128  ],
129 
130  ],
131 
132  ];
133  $this->assertEquals($compare, $conditions);
134 
135  }
136 
137  function test2UriLockTokens() {
138 
139  $serverVars = [
140  'HTTP_IF' => '<http://www.example.org/node1> (<opaquelocktoken:token1>) <http://www.example.org/node2> (Not <opaquelocktoken:token2>)',
141  ];
142 
144  $conditions = $this->server->getIfConditions($request);
145 
146  $compare = [
147 
148  [
149  'uri' => 'node1',
150  'tokens' => [
151  [
152  'negate' => false,
153  'token' => 'opaquelocktoken:token1',
154  'etag' => '',
155  ],
156  ],
157  ],
158  [
159  'uri' => 'node2',
160  'tokens' => [
161  [
162  'negate' => true,
163  'token' => 'opaquelocktoken:token2',
164  'etag' => '',
165  ],
166  ],
167 
168  ],
169 
170  ];
171  $this->assertEquals($compare, $conditions);
172 
173  }
174 
176 
177  $serverVars = [
178  'HTTP_IF' => '<http://www.example.org/node1> (<opaquelocktoken:token1>) (<opaquelocktoken:token2>) <http://www.example.org/node2> (Not <opaquelocktoken:token3>)',
179  ];
180 
182  $conditions = $this->server->getIfConditions($request);
183 
184  $compare = [
185 
186  [
187  'uri' => 'node1',
188  'tokens' => [
189  [
190  'negate' => false,
191  'token' => 'opaquelocktoken:token1',
192  'etag' => '',
193  ],
194  [
195  'negate' => false,
196  'token' => 'opaquelocktoken:token2',
197  'etag' => '',
198  ],
199  ],
200  ],
201  [
202  'uri' => 'node2',
203  'tokens' => [
204  [
205  'negate' => true,
206  'token' => 'opaquelocktoken:token3',
207  'etag' => '',
208  ],
209  ],
210 
211  ],
212 
213  ];
214  $this->assertEquals($compare, $conditions);
215 
216  }
217 
218  function testEtag() {
219 
220  $serverVars = [
221  'HTTP_IF' => '(["etag1"])',
222  'REQUEST_URI' => '/foo',
223  ];
224 
226  $conditions = $this->server->getIfConditions($request);
227 
228  $compare = [
229 
230  [
231  'uri' => 'foo',
232  'tokens' => [
233  [
234  'negate' => false,
235  'token' => '',
236  'etag' => '"etag1"',
237  ],
238  ],
239  ],
240 
241  ];
242  $this->assertEquals($compare, $conditions);
243 
244  }
245 
246  function test2Etags() {
247 
248  $serverVars = [
249  'HTTP_IF' => '<http://www.example.org/> (["etag1"]) (["etag2"])',
250  ];
251 
253  $conditions = $this->server->getIfConditions($request);
254 
255  $compare = [
256 
257  [
258  'uri' => '',
259  'tokens' => [
260  [
261  'negate' => false,
262  'token' => '',
263  'etag' => '"etag1"',
264  ],
265  [
266  'negate' => false,
267  'token' => '',
268  'etag' => '"etag2"',
269  ],
270  ],
271  ],
272 
273  ];
274  $this->assertEquals($compare, $conditions);
275 
276  }
277 
278  function testComplexIf() {
279 
280  $serverVars = [
281  'HTTP_IF' => '<http://www.example.org/node1> (<opaquelocktoken:token1> ["etag1"]) ' .
282  '(Not <opaquelocktoken:token2>) (["etag2"]) <http://www.example.org/node2> ' .
283  '(<opaquelocktoken:token3>) (Not <opaquelocktoken:token4>) (["etag3"])',
284  ];
285 
287  $conditions = $this->server->getIfConditions($request);
288 
289  $compare = [
290 
291  [
292  'uri' => 'node1',
293  'tokens' => [
294  [
295  'negate' => false,
296  'token' => 'opaquelocktoken:token1',
297  'etag' => '"etag1"',
298  ],
299  [
300  'negate' => true,
301  'token' => 'opaquelocktoken:token2',
302  'etag' => '',
303  ],
304  [
305  'negate' => false,
306  'token' => '',
307  'etag' => '"etag2"',
308  ],
309  ],
310  ],
311  [
312  'uri' => 'node2',
313  'tokens' => [
314  [
315  'negate' => false,
316  'token' => 'opaquelocktoken:token3',
317  'etag' => '',
318  ],
319  [
320  'negate' => true,
321  'token' => 'opaquelocktoken:token4',
322  'etag' => '',
323  ],
324  [
325  'negate' => false,
326  'token' => '',
327  'etag' => '"etag3"',
328  ],
329  ],
330  ],
331 
332  ];
333  $this->assertEquals($compare, $conditions);
334 
335  }
336 
337 }
static createFromServerArray(array $serverArray)
This static method will create a new Request object, based on a PHP $_SERVER array.
Definition: Sapi.php:107