ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PropPatchTest.php
Go to the documentation of this file.
1<?php
2
3namespace Sabre\DAV;
4
6
7 protected $propPatch;
8
9 function setUp() {
10
11 $this->propPatch = new PropPatch([
12 '{DAV:}displayname' => 'foo',
13 ]);
14 $this->assertEquals(['{DAV:}displayname' => 'foo'], $this->propPatch->getMutations());
15
16 }
17
19
20 $hasRan = false;
21
22 $this->propPatch->handle('{DAV:}displayname', function($value) use (&$hasRan) {
23 $hasRan = true;
24 $this->assertEquals('foo', $value);
25 return true;
26 });
27
28 $this->assertTrue($this->propPatch->commit());
29 $result = $this->propPatch->getResult();
30 $this->assertEquals(['{DAV:}displayname' => 200], $result);
31
32 $this->assertTrue($hasRan);
33
34 }
35
37
38 $hasRan = false;
39
40 $this->propPatch->handle('{DAV:}displayname', function($value) use (&$hasRan) {
41 $hasRan = true;
42 $this->assertEquals('foo', $value);
43 return false;
44 });
45
46 $this->assertFalse($this->propPatch->commit());
47 $result = $this->propPatch->getResult();
48 $this->assertEquals(['{DAV:}displayname' => 403], $result);
49
50 $this->assertTrue($hasRan);
51
52 }
53
55
56 $hasRan = false;
57
58 $this->propPatch->handle('{DAV:}displayname', function($value) use (&$hasRan) {
59 $hasRan = true;
60 $this->assertEquals('foo', $value);
61 return 201;
62 });
63
64 $this->assertTrue($this->propPatch->commit());
65 $result = $this->propPatch->getResult();
66 $this->assertEquals(['{DAV:}displayname' => 201], $result);
67
68 $this->assertTrue($hasRan);
69
70 }
71
73
74 $hasRan = false;
75
76 $this->propPatch = new PropPatch(['{DAV:}displayname' => null]);
77 $this->propPatch->handle('{DAV:}displayname', function($value) use (&$hasRan) {
78 $hasRan = true;
79 $this->assertNull($value);
80 return true;
81 });
82
83 $this->assertTrue($this->propPatch->commit());
84 $result = $this->propPatch->getResult();
85 $this->assertEquals(['{DAV:}displayname' => 204], $result);
86
87 $this->assertTrue($hasRan);
88
89 }
90
91
92 function testHandleNothing() {
93
94 $hasRan = false;
95
96 $this->propPatch->handle('{DAV:}foobar', function($value) use (&$hasRan) {
97 $hasRan = true;
98 });
99
100 $this->assertFalse($hasRan);
101
102 }
103
108
109 $hasRan = false;
110
111 $this->propPatch->handleRemaining(function($mutations) use (&$hasRan) {
112 $hasRan = true;
113 $this->assertEquals(['{DAV:}displayname' => 'foo'], $mutations);
114 return true;
115 });
116
117 $this->assertTrue($this->propPatch->commit());
118 $result = $this->propPatch->getResult();
119 $this->assertEquals(['{DAV:}displayname' => 200], $result);
120
121 $this->assertTrue($hasRan);
122
123 }
125
126 $hasRan = false;
127
128 $this->propPatch->handle('{DAV:}displayname', function() {});
129 $this->propPatch->handleRemaining(function($mutations) use (&$hasRan) {
130 $hasRan = true;
131 });
132
133 $this->assertFalse($hasRan);
134
135 }
136
137 function testSetResultCode() {
138
139 $this->propPatch->setResultCode('{DAV:}displayname', 201);
140 $this->assertTrue($this->propPatch->commit());
141 $result = $this->propPatch->getResult();
142 $this->assertEquals(['{DAV:}displayname' => 201], $result);
143
144 }
145
147
148 $this->propPatch->setResultCode('{DAV:}displayname', 402);
149 $this->assertFalse($this->propPatch->commit());
150 $result = $this->propPatch->getResult();
151 $this->assertEquals(['{DAV:}displayname' => 402], $result);
152
153 }
154
156
157 $this->propPatch->setRemainingResultCode(204);
158 $this->assertTrue($this->propPatch->commit());
159 $result = $this->propPatch->getResult();
160 $this->assertEquals(['{DAV:}displayname' => 204], $result);
161
162 }
163
165
166 $this->assertFalse($this->propPatch->commit());
167 $result = $this->propPatch->getResult();
168 $this->assertEquals(['{DAV:}displayname' => 403], $result);
169
170 }
171
173
174 $hasRan = false;
175
176 $this->propPatch->setResultCode('{DAV:}displayname', 402);
177 $this->propPatch->handle('{DAV:}displayname', function($value) use (&$hasRan) {
178 $hasRan = true;
179 });
180
181 $this->propPatch->commit();
182
183 // The handler is not supposed to have ran
184 $this->assertFalse($hasRan);
185
186 }
187
189
190 $propPatch = new PropPatch([
191 '{DAV:}a' => 'foo',
192 '{DAV:}b' => 'bar',
193 ]);
194
195 $calledA = false;
196 $calledB = false;
197
198 $propPatch->handle('{DAV:}a', function() use (&$calledA) {
199 $calledA = true;
200 return false;
201 });
202 $propPatch->handle('{DAV:}b', function() use (&$calledB) {
203 $calledB = true;
204 return false;
205 });
206
207 $result = $propPatch->commit();
208 $this->assertTrue($calledA);
209 $this->assertFalse($calledB);
210
211 $this->assertFalse($result);
212
213 $this->assertEquals([
214 '{DAV:}a' => 403,
215 '{DAV:}b' => 424,
216 ], $propPatch->getResult());
217
218 }
219
224
225 $propPatch = new PropPatch([
226 '{DAV:}a' => 'foo',
227 ]);
228
229 $propPatch->handle('{DAV:}a', function() {
230 return [];
231 });
232 $propPatch->commit();
233
234 }
235
237
238 $propPatch = new PropPatch([
239 '{DAV:}a' => 'foo',
240 '{DAV:}b' => 'bar',
241 '{DAV:}c' => null,
242 ]);
243
244 $calledA = false;
245
246 $propPatch->handle(['{DAV:}a', '{DAV:}b', '{DAV:}c'], function($properties) use (&$calledA) {
247 $calledA = true;
248 $this->assertEquals([
249 '{DAV:}a' => 'foo',
250 '{DAV:}b' => 'bar',
251 '{DAV:}c' => null,
252 ], $properties);
253 return true;
254 });
255 $result = $propPatch->commit();
256 $this->assertTrue($calledA);
257 $this->assertTrue($result);
258
259 $this->assertEquals([
260 '{DAV:}a' => 200,
261 '{DAV:}b' => 200,
262 '{DAV:}c' => 204,
263 ], $propPatch->getResult());
264
265 }
266
267
269
270 $propPatch = new PropPatch([
271 '{DAV:}a' => 'foo',
272 '{DAV:}b' => 'bar',
273 '{DAV:}c' => null,
274 ]);
275
276 $calledA = false;
277
278 $propPatch->handle(['{DAV:}a', '{DAV:}b', '{DAV:}c'], function($properties) use (&$calledA) {
279 $calledA = true;
280 $this->assertEquals([
281 '{DAV:}a' => 'foo',
282 '{DAV:}b' => 'bar',
283 '{DAV:}c' => null,
284 ], $properties);
285 return false;
286 });
287 $result = $propPatch->commit();
288 $this->assertTrue($calledA);
289 $this->assertFalse($result);
290
291 $this->assertEquals([
292 '{DAV:}a' => 403,
293 '{DAV:}b' => 403,
294 '{DAV:}c' => 403,
295 ], $propPatch->getResult());
296
297 }
298
300
301 $propPatch = new PropPatch([
302 '{DAV:}a' => 'foo',
303 '{DAV:}b' => 'bar',
304 '{DAV:}c' => null,
305 ]);
306
307 $calledA = false;
308
309 $propPatch->handle(['{DAV:}a', '{DAV:}b', '{DAV:}c'], function($properties) use (&$calledA) {
310 $calledA = true;
311 $this->assertEquals([
312 '{DAV:}a' => 'foo',
313 '{DAV:}b' => 'bar',
314 '{DAV:}c' => null,
315 ], $properties);
316
317 return [
318 '{DAV:}a' => 201,
319 '{DAV:}b' => 204,
320 ];
321 });
322 $result = $propPatch->commit();
323 $this->assertTrue($calledA);
324 $this->assertFalse($result);
325
326 $this->assertEquals([
327 '{DAV:}a' => 201,
328 '{DAV:}b' => 204,
329 '{DAV:}c' => 500,
330 ], $propPatch->getResult());
331
332 }
333
338
339 $propPatch = new PropPatch([
340 '{DAV:}a' => 'foo',
341 '{DAV:}b' => 'bar',
342 '{DAV:}c' => null,
343 ]);
344
345 $propPatch->handle(['{DAV:}a', '{DAV:}b', '{DAV:}c'], function($properties) {
346 return 'hi';
347 });
348 $propPatch->commit();
349
350 }
351}
$result
An exception for terminatinating execution or to throw for unit testing.
testHandleRemaining()
@depends testHandleSingleSuccess
testHandleMultiValueBroken()
@expectedException \UnexpectedValueException
testHandleSingleBrokenResult()
@expectedException \UnexpectedValueException
This class represents a set of properties that are going to be updated.
Definition: PropPatch.php:20