* Corrected and improved FileBackend::getFileList() comments.
[lhc/web/wiklou.git] / tests / phpunit / includes / filerepo / FileBackendTest.php
1 <?php
2
3 /**
4 * @group FileRepo
5 * @group FileBackend
6 */
7 class FileBackendTest extends MediaWikiTestCase {
8 private $backend, $multiBackend;
9 private $filesToPrune = array();
10 private $dirsToPrune = array();
11 private static $backendToUse;
12
13 function setUp() {
14 global $wgFileBackends;
15 parent::setUp();
16 $tmpPrefix = wfTempDir() . '/filebackend-unittest-' . time() . '-' . mt_rand();
17 if ( $this->getCliArg( 'use-filebackend=' ) ) {
18 if ( self::$backendToUse ) {
19 $this->singleBackend = self::$backendToUse;
20 } else {
21 $name = $this->getCliArg( 'use-filebackend=' );
22 $useConfig = array();
23 foreach ( $wgFileBackends as $conf ) {
24 if ( $conf['name'] == $name ) {
25 $useConfig = $conf;
26 }
27 }
28 $useConfig['name'] = 'localtesting'; // swap name
29 $class = $conf['class'];
30 self::$backendToUse = new $class( $useConfig );
31 $this->singleBackend = self::$backendToUse;
32 }
33 } else {
34 $this->singleBackend = new FSFileBackend( array(
35 'name' => 'localtesting',
36 'lockManager' => 'fsLockManager',
37 'containerPaths' => array(
38 'unittest-cont1' => "{$tmpPrefix}-localtesting-cont1",
39 'unittest-cont2' => "{$tmpPrefix}-localtesting-cont2" )
40 ) );
41 }
42 $this->multiBackend = new FileBackendMultiWrite( array(
43 'name' => 'localtesting',
44 'lockManager' => 'fsLockManager',
45 'backends' => array(
46 array(
47 'name' => 'localmutlitesting1',
48 'class' => 'FSFileBackend',
49 'lockManager' => 'nullLockManager',
50 'containerPaths' => array(
51 'unittest-cont1' => "{$tmpPrefix}-localtestingmulti1-cont1",
52 'unittest-cont2' => "{$tmpPrefix}-localtestingmulti1-cont2" ),
53 'isMultiMaster' => false
54 ),
55 array(
56 'name' => 'localmutlitesting2',
57 'class' => 'FSFileBackend',
58 'lockManager' => 'nullLockManager',
59 'containerPaths' => array(
60 'unittest-cont1' => "{$tmpPrefix}-localtestingmulti2-cont1",
61 'unittest-cont2' => "{$tmpPrefix}-localtestingmulti2-cont2" ),
62 'isMultiMaster' => true
63 )
64 )
65 ) );
66 $this->filesToPrune = array();
67 }
68
69 private function baseStorePath() {
70 return 'mwstore://localtesting';
71 }
72
73 private function backendClass() {
74 return get_class( $this->backend );
75 }
76
77 /**
78 * @dataProvider provider_testIsStoragePath
79 */
80 public function testIsStoragePath( $path, $isStorePath ) {
81 $this->assertEquals( $isStorePath, FileBackend::isStoragePath( $path ),
82 "FileBackend::isStoragePath on path '$path'" );
83 }
84
85 function provider_testIsStoragePath() {
86 return array(
87 array( 'mwstore://', true ),
88 array( 'mwstore://backend', true ),
89 array( 'mwstore://backend/container', true ),
90 array( 'mwstore://backend/container/', true ),
91 array( 'mwstore://backend/container/path', true ),
92 array( 'mwstore://backend//container/', true ),
93 array( 'mwstore://backend//container//', true ),
94 array( 'mwstore://backend//container//path', true ),
95 array( 'mwstore:///', true ),
96 array( 'mwstore:/', false ),
97 array( 'mwstore:', false ),
98 );
99 }
100
101 /**
102 * @dataProvider provider_testSplitStoragePath
103 */
104 public function testSplitStoragePath( $path, $res ) {
105 $this->assertEquals( $res, FileBackend::splitStoragePath( $path ),
106 "FileBackend::splitStoragePath on path '$path'" );
107 }
108
109 function provider_testSplitStoragePath() {
110 return array(
111 array( 'mwstore://backend/container', array( 'backend', 'container', '' ) ),
112 array( 'mwstore://backend/container/', array( 'backend', 'container', '' ) ),
113 array( 'mwstore://backend/container/path', array( 'backend', 'container', 'path' ) ),
114 array( 'mwstore://backend/container//path', array( 'backend', 'container', '/path' ) ),
115 array( 'mwstore://backend//container/path', array( null, null, null ) ),
116 array( 'mwstore://backend//container//path', array( null, null, null ) ),
117 array( 'mwstore://', array( null, null, null ) ),
118 array( 'mwstore://backend', array( null, null, null ) ),
119 array( 'mwstore:///', array( null, null, null ) ),
120 array( 'mwstore:/', array( null, null, null ) ),
121 array( 'mwstore:', array( null, null, null ) )
122 );
123 }
124
125 /**
126 * @dataProvider provider_normalizeStoragePath
127 */
128 public function testNormalizeStoragePath( $path, $res ) {
129 $this->assertEquals( $res, FileBackend::normalizeStoragePath( $path ),
130 "FileBackend::normalizeStoragePath on path '$path'" );
131 }
132
133 function provider_normalizeStoragePath() {
134 return array(
135 array( 'mwstore://backend/container', 'mwstore://backend/container' ),
136 array( 'mwstore://backend/container/', 'mwstore://backend/container' ),
137 array( 'mwstore://backend/container/path', 'mwstore://backend/container/path' ),
138 array( 'mwstore://backend/container//path', 'mwstore://backend/container/path' ),
139 array( 'mwstore://backend/container///path', 'mwstore://backend/container/path' ),
140 array( 'mwstore://backend/container///path//to///obj', 'mwstore://backend/container/path/to/obj',
141 array( 'mwstore://', null ),
142 array( 'mwstore://backend', null ),
143 array( 'mwstore://backend//container/path', null ),
144 array( 'mwstore://backend//container//path', null ),
145 array( 'mwstore:///', null ),
146 array( 'mwstore:/', null ),
147 array( 'mwstore:', null ), )
148 );
149 }
150
151 /**
152 * @dataProvider provider_testParentStoragePath
153 */
154 public function testParentStoragePath( $path, $res ) {
155 $this->assertEquals( $res, FileBackend::parentStoragePath( $path ),
156 "FileBackend::parentStoragePath on path '$path'" );
157 }
158
159 function provider_testParentStoragePath() {
160 return array(
161 array( 'mwstore://backend/container/path/to/obj', 'mwstore://backend/container/path/to' ),
162 array( 'mwstore://backend/container/path/to', 'mwstore://backend/container/path' ),
163 array( 'mwstore://backend/container/path', 'mwstore://backend/container' ),
164 array( 'mwstore://backend/container', null ),
165 array( 'mwstore://backend/container/path/to/obj/', 'mwstore://backend/container/path/to' ),
166 array( 'mwstore://backend/container/path/to/', 'mwstore://backend/container/path' ),
167 array( 'mwstore://backend/container/path/', 'mwstore://backend/container' ),
168 array( 'mwstore://backend/container/', null ),
169 );
170 }
171
172 /**
173 * @dataProvider provider_testExtensionFromPath
174 */
175 public function testExtensionFromPath( $path, $res ) {
176 $this->assertEquals( $res, FileBackend::extensionFromPath( $path ),
177 "FileBackend::extensionFromPath on path '$path'" );
178 }
179
180 function provider_testExtensionFromPath() {
181 return array(
182 array( 'mwstore://backend/container/path.txt', 'txt' ),
183 array( 'mwstore://backend/container/path.svg.png', 'png' ),
184 array( 'mwstore://backend/container/path', '' ),
185 array( 'mwstore://backend/container/path.', '' ),
186 );
187 }
188
189 /**
190 * @dataProvider provider_testStore
191 */
192 public function testStore( $op ) {
193 $this->filesToPrune[] = $op['src'];
194
195 $this->backend = $this->singleBackend;
196 $this->tearDownFiles();
197 $this->doTestStore( $op );
198 $this->tearDownFiles();
199
200 $this->backend = $this->multiBackend;
201 $this->tearDownFiles();
202 $this->doTestStore( $op );
203 $this->tearDownFiles();
204 }
205
206 function doTestStore( $op ) {
207 $backendName = $this->backendClass();
208
209 $source = $op['src'];
210 $dest = $op['dst'];
211 $this->prepare( array( 'dir' => dirname( $dest ) ) );
212
213 file_put_contents( $source, "Unit test file" );
214
215 if ( isset( $op['overwrite'] ) || isset( $op['overwriteSame'] ) ) {
216 $this->backend->store( $op );
217 }
218
219 $status = $this->backend->doOperation( $op );
220
221 $this->assertEquals( array(), $status->errors,
222 "Store from $source to $dest succeeded without warnings ($backendName)." );
223 $this->assertEquals( array(), $status->errors,
224 "Store from $source to $dest succeeded ($backendName)." );
225 $this->assertEquals( array( 0 => true ), $status->success,
226 "Store from $source to $dest has proper 'success' field in Status ($backendName)." );
227 $this->assertEquals( true, file_exists( $source ),
228 "Source file $source still exists ($backendName)." );
229 $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $dest ) ),
230 "Destination file $dest exists ($backendName)." );
231
232 $this->assertEquals( filesize( $source ),
233 $this->backend->getFileSize( array( 'src' => $dest ) ),
234 "Destination file $dest has correct size ($backendName)." );
235
236 $props1 = FSFile::getPropsFromPath( $source );
237 $props2 = $this->backend->getFileProps( array( 'src' => $dest ) );
238 $this->assertEquals( $props1, $props2,
239 "Source and destination have the same props ($backendName)." );
240 }
241
242 public function provider_testStore() {
243 $cases = array();
244
245 $tmpName = TempFSFile::factory( "unittests_", 'txt' )->getPath();
246 $toPath = $this->baseStorePath() . '/unittest-cont1/fun/obj1.txt';
247 $op = array( 'op' => 'store', 'src' => $tmpName, 'dst' => $toPath );
248 $cases[] = array(
249 $op, // operation
250 $tmpName, // source
251 $toPath, // dest
252 );
253
254 $op2 = $op;
255 $op2['overwrite'] = true;
256 $cases[] = array(
257 $op2, // operation
258 $tmpName, // source
259 $toPath, // dest
260 );
261
262 $op2 = $op;
263 $op2['overwriteSame'] = true;
264 $cases[] = array(
265 $op2, // operation
266 $tmpName, // source
267 $toPath, // dest
268 );
269
270 return $cases;
271 }
272
273 /**
274 * @dataProvider provider_testCopy
275 */
276 public function testCopy( $op ) {
277 $this->backend = $this->singleBackend;
278 $this->tearDownFiles();
279 $this->doTestCopy( $op );
280 $this->tearDownFiles();
281
282 $this->backend = $this->multiBackend;
283 $this->tearDownFiles();
284 $this->doTestCopy( $op );
285 $this->tearDownFiles();
286 }
287
288 function doTestCopy( $op ) {
289 $backendName = $this->backendClass();
290
291 $source = $op['src'];
292 $dest = $op['dst'];
293 $this->prepare( array( 'dir' => dirname( $source ) ) );
294 $this->prepare( array( 'dir' => dirname( $dest ) ) );
295
296 $status = $this->backend->doOperation(
297 array( 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ) );
298 $this->assertEquals( array(), $status->errors,
299 "Creation of file at $source succeeded ($backendName)." );
300
301 if ( isset( $op['overwrite'] ) || isset( $op['overwriteSame'] ) ) {
302 $this->backend->copy( $op );
303 }
304
305 $status = $this->backend->doOperation( $op );
306
307 $this->assertEquals( array(), $status->errors,
308 "Copy from $source to $dest succeeded without warnings ($backendName)." );
309 $this->assertEquals( true, $status->isOK(),
310 "Copy from $source to $dest succeeded ($backendName)." );
311 $this->assertEquals( array( 0 => true ), $status->success,
312 "Copy from $source to $dest has proper 'success' field in Status ($backendName)." );
313 $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $source ) ),
314 "Source file $source still exists ($backendName)." );
315 $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $dest ) ),
316 "Destination file $dest exists after copy ($backendName)." );
317
318 $this->assertEquals(
319 $this->backend->getFileSize( array( 'src' => $source ) ),
320 $this->backend->getFileSize( array( 'src' => $dest ) ),
321 "Destination file $dest has correct size ($backendName)." );
322
323 $props1 = $this->backend->getFileProps( array( 'src' => $source ) );
324 $props2 = $this->backend->getFileProps( array( 'src' => $dest ) );
325 $this->assertEquals( $props1, $props2,
326 "Source and destination have the same props ($backendName)." );
327 }
328
329 public function provider_testCopy() {
330 $cases = array();
331
332 $source = $this->baseStorePath() . '/unittest-cont1/file.txt';
333 $dest = $this->baseStorePath() . '/unittest-cont2/fileMoved.txt';
334
335 $op = array( 'op' => 'copy', 'src' => $source, 'dst' => $dest );
336 $cases[] = array(
337 $op, // operation
338 $source, // source
339 $dest, // dest
340 );
341
342 $op2 = $op;
343 $op2['overwrite'] = true;
344 $cases[] = array(
345 $op2, // operation
346 $source, // source
347 $dest, // dest
348 );
349
350 $op2 = $op;
351 $op2['overwriteSame'] = true;
352 $cases[] = array(
353 $op2, // operation
354 $source, // source
355 $dest, // dest
356 );
357
358 return $cases;
359 }
360
361 /**
362 * @dataProvider provider_testMove
363 */
364 public function testMove( $op ) {
365 $this->backend = $this->singleBackend;
366 $this->tearDownFiles();
367 $this->doTestMove( $op );
368 $this->tearDownFiles();
369
370 $this->backend = $this->multiBackend;
371 $this->tearDownFiles();
372 $this->doTestMove( $op );
373 $this->tearDownFiles();
374 }
375
376 private function doTestMove( $op ) {
377 $backendName = $this->backendClass();
378
379 $source = $op['src'];
380 $dest = $op['dst'];
381 $this->prepare( array( 'dir' => dirname( $source ) ) );
382 $this->prepare( array( 'dir' => dirname( $dest ) ) );
383
384 $status = $this->backend->doOperation(
385 array( 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ) );
386 $this->assertEquals( array(), $status->errors,
387 "Creation of file at $source succeeded ($backendName)." );
388
389 if ( isset( $op['overwrite'] ) || isset( $op['overwriteSame'] ) ) {
390 $this->backend->copy( $op );
391 }
392
393 $status = $this->backend->doOperation( $op );
394 $this->assertEquals( array(), $status->errors,
395 "Move from $source to $dest succeeded without warnings ($backendName)." );
396 $this->assertEquals( true, $status->isOK(),
397 "Move from $source to $dest succeeded ($backendName)." );
398 $this->assertEquals( array( 0 => true ), $status->success,
399 "Move from $source to $dest has proper 'success' field in Status ($backendName)." );
400 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $source ) ),
401 "Source file $source does not still exists ($backendName)." );
402 $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $dest ) ),
403 "Destination file $dest exists after move ($backendName)." );
404
405 $this->assertNotEquals(
406 $this->backend->getFileSize( array( 'src' => $source ) ),
407 $this->backend->getFileSize( array( 'src' => $dest ) ),
408 "Destination file $dest has correct size ($backendName)." );
409
410 $props1 = $this->backend->getFileProps( array( 'src' => $source ) );
411 $props2 = $this->backend->getFileProps( array( 'src' => $dest ) );
412 $this->assertEquals( false, $props1['fileExists'],
413 "Source file does not exist accourding to props ($backendName)." );
414 $this->assertEquals( true, $props2['fileExists'],
415 "Destination file exists accourding to props ($backendName)." );
416 }
417
418 public function provider_testMove() {
419 $cases = array();
420
421 $source = $this->baseStorePath() . '/unittest-cont1/file.txt';
422 $dest = $this->baseStorePath() . '/unittest-cont2/fileMoved.txt';
423
424 $op = array( 'op' => 'move', 'src' => $source, 'dst' => $dest );
425 $cases[] = array(
426 $op, // operation
427 $source, // source
428 $dest, // dest
429 );
430
431 $op2 = $op;
432 $op2['overwrite'] = true;
433 $cases[] = array(
434 $op2, // operation
435 $source, // source
436 $dest, // dest
437 );
438
439 $op2 = $op;
440 $op2['overwriteSame'] = true;
441 $cases[] = array(
442 $op2, // operation
443 $source, // source
444 $dest, // dest
445 );
446
447 return $cases;
448 }
449
450 /**
451 * @dataProvider provider_testDelete
452 */
453 public function testDelete( $op, $withSource, $okStatus ) {
454 $this->backend = $this->singleBackend;
455 $this->tearDownFiles();
456 $this->doTestDelete( $op, $withSource, $okStatus );
457 $this->tearDownFiles();
458
459 $this->backend = $this->multiBackend;
460 $this->tearDownFiles();
461 $this->doTestDelete( $op, $withSource, $okStatus );
462 $this->tearDownFiles();
463 }
464
465 private function doTestDelete( $op, $withSource, $okStatus ) {
466 $backendName = $this->backendClass();
467
468 $source = $op['src'];
469 $this->prepare( array( 'dir' => dirname( $source ) ) );
470
471 if ( $withSource ) {
472 $status = $this->backend->doOperation(
473 array( 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ) );
474 $this->assertEquals( array(), $status->errors,
475 "Creation of file at $source succeeded ($backendName)." );
476 }
477
478 $status = $this->backend->doOperation( $op );
479 if ( $okStatus ) {
480 $this->assertEquals( array(), $status->errors,
481 "Deletion of file at $source succeeded without warnings ($backendName)." );
482 $this->assertEquals( true, $status->isOK(),
483 "Deletion of file at $source succeeded ($backendName)." );
484 $this->assertEquals( array( 0 => true ), $status->success,
485 "Deletion of file at $source has proper 'success' field in Status ($backendName)." );
486 } else {
487 $this->assertEquals( false, $status->isOK(),
488 "Deletion of file at $source failed ($backendName)." );
489 }
490
491 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $source ) ),
492 "Source file $source does not exist after move ($backendName)." );
493
494 $this->assertFalse(
495 $this->backend->getFileSize( array( 'src' => $source ) ),
496 "Source file $source has correct size (false) ($backendName)." );
497
498 $props1 = $this->backend->getFileProps( array( 'src' => $source ) );
499 $this->assertFalse( $props1['fileExists'],
500 "Source file $source does not exist according to props ($backendName)." );
501 }
502
503 public function provider_testDelete() {
504 $cases = array();
505
506 $source = $this->baseStorePath() . '/unittest-cont1/myfacefile.txt';
507
508 $op = array( 'op' => 'delete', 'src' => $source );
509 $cases[] = array(
510 $op, // operation
511 true, // with source
512 true // succeeds
513 );
514
515 $cases[] = array(
516 $op, // operation
517 false, // without source
518 false // fails
519 );
520
521 $op['ignoreMissingSource'] = true;
522 $cases[] = array(
523 $op, // operation
524 false, // without source
525 true // succeeds
526 );
527
528 return $cases;
529 }
530
531 /**
532 * @dataProvider provider_testCreate
533 */
534 public function testCreate( $op, $alreadyExists, $okStatus, $newSize ) {
535 $this->backend = $this->singleBackend;
536 $this->tearDownFiles();
537 $this->doTestCreate( $op, $alreadyExists, $okStatus, $newSize );
538 $this->tearDownFiles();
539
540 $this->backend = $this->multiBackend;
541 $this->tearDownFiles();
542 $this->doTestCreate( $op, $alreadyExists, $okStatus, $newSize );
543 $this->tearDownFiles();
544 }
545
546 private function doTestCreate( $op, $alreadyExists, $okStatus, $newSize ) {
547 $backendName = $this->backendClass();
548
549 $dest = $op['dst'];
550 $this->prepare( array( 'dir' => dirname( $dest ) ) );
551
552 $oldText = 'blah...blah...waahwaah';
553 if ( $alreadyExists ) {
554 $status = $this->backend->doOperation(
555 array( 'op' => 'create', 'content' => $oldText, 'dst' => $dest ) );
556 $this->assertEquals( array(), $status->errors,
557 "Creation of file at $dest succeeded ($backendName)." );
558 }
559
560 $status = $this->backend->doOperation( $op );
561 if ( $okStatus ) {
562 $this->assertEquals( array(), $status->errors,
563 "Creation of file at $dest succeeded without warnings ($backendName)." );
564 $this->assertEquals( true, $status->isOK(),
565 "Creation of file at $dest succeeded ($backendName)." );
566 $this->assertEquals( array( 0 => true ), $status->success,
567 "Creation of file at $dest has proper 'success' field in Status ($backendName)." );
568 } else {
569 $this->assertEquals( false, $status->isOK(),
570 "Creation of file at $dest failed ($backendName)." );
571 }
572
573 $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $dest ) ),
574 "Destination file $dest exists after creation ($backendName)." );
575
576 $props1 = $this->backend->getFileProps( array( 'src' => $dest ) );
577 $this->assertEquals( true, $props1['fileExists'],
578 "Destination file $dest exists according to props ($backendName)." );
579 if ( $okStatus ) { // file content is what we saved
580 $this->assertEquals( $newSize, $props1['size'],
581 "Destination file $dest has expected size according to props ($backendName)." );
582 $this->assertEquals( $newSize,
583 $this->backend->getFileSize( array( 'src' => $dest ) ),
584 "Destination file $dest has correct size ($backendName)." );
585 } else { // file content is some other previous text
586 $this->assertEquals( strlen( $oldText ), $props1['size'],
587 "Destination file $dest has original size according to props ($backendName)." );
588 $this->assertEquals( strlen( $oldText ),
589 $this->backend->getFileSize( array( 'src' => $dest ) ),
590 "Destination file $dest has original size according to props ($backendName)." );
591 }
592 }
593
594 /**
595 * @dataProvider provider_testCreate
596 */
597 public function provider_testCreate() {
598 $cases = array();
599
600 $dest = $this->baseStorePath() . '/unittest-cont2/myspacefile.txt';
601
602 $op = array( 'op' => 'create', 'content' => 'test test testing', 'dst' => $dest );
603 $cases[] = array(
604 $op, // operation
605 false, // no dest already exists
606 true, // succeeds
607 strlen( $op['content'] )
608 );
609
610 $op2 = $op;
611 $op2['content'] = "\n";
612 $cases[] = array(
613 $op2, // operation
614 false, // no dest already exists
615 true, // succeeds
616 strlen( $op2['content'] )
617 );
618
619 $op2 = $op;
620 $op2['content'] = "fsf\n waf 3kt";
621 $cases[] = array(
622 $op2, // operation
623 true, // dest already exists
624 false, // fails
625 strlen( $op2['content'] )
626 );
627
628 $op2 = $op;
629 $op2['content'] = "egm'g gkpe gpqg eqwgwqg";
630 $op2['overwrite'] = true;
631 $cases[] = array(
632 $op2, // operation
633 true, // dest already exists
634 true, // succeeds
635 strlen( $op2['content'] )
636 );
637
638 $op2 = $op;
639 $op2['content'] = "39qjmg3-qg";
640 $op2['overwriteSame'] = true;
641 $cases[] = array(
642 $op2, // operation
643 true, // dest already exists
644 false, // succeeds
645 strlen( $op2['content'] )
646 );
647
648 return $cases;
649 }
650
651 /**
652 * @dataProvider provider_testConcatenate
653 */
654 public function testConcatenate( $op, $srcs, $srcsContent, $alreadyExists, $okStatus ) {
655 $this->filesToPrune[] = $op['dst'];
656
657 $this->backend = $this->singleBackend;
658 $this->tearDownFiles();
659 $this->doTestConcatenate( $op, $srcs, $srcsContent, $alreadyExists, $okStatus );
660 $this->tearDownFiles();
661
662 $this->backend = $this->multiBackend;
663 $this->tearDownFiles();
664 $this->doTestConcatenate( $op, $srcs, $srcsContent, $alreadyExists, $okStatus );
665 $this->tearDownFiles();
666 }
667
668 public function doTestConcatenate( $params, $srcs, $srcsContent, $alreadyExists, $okStatus ) {
669 $backendName = $this->backendClass();
670
671 $expContent = '';
672 // Create sources
673 $ops = array();
674 foreach ( $srcs as $i => $source ) {
675 $this->prepare( array( 'dir' => dirname( $source ) ) );
676 $ops[] = array(
677 'op' => 'create', // operation
678 'dst' => $source, // source
679 'content' => $srcsContent[$i]
680 );
681 $expContent .= $srcsContent[$i];
682 }
683 $status = $this->backend->doOperations( $ops );
684
685 $this->assertEquals( array(), $status->errors,
686 "Creation of source files succeeded ($backendName)." );
687
688 $dest = $params['dst'];
689 if ( $alreadyExists ) {
690 $ok = file_put_contents( $dest, 'blah...blah...waahwaah' ) !== false;
691 $this->assertEquals( true, $ok,
692 "Creation of file at $dest succeeded ($backendName)." );
693 } else {
694 $ok = file_put_contents( $dest, '' ) !== false;
695 $this->assertEquals( true, $ok,
696 "Creation of 0-byte file at $dest succeeded ($backendName)." );
697 }
698
699 // Combine the files into one
700 $status = $this->backend->concatenate( $params );
701 if ( $okStatus ) {
702 $this->assertEquals( array(), $status->errors,
703 "Creation of concat file at $dest succeeded without warnings ($backendName)." );
704 $this->assertEquals( true, $status->isOK(),
705 "Creation of concat file at $dest succeeded ($backendName)." );
706 } else {
707 $this->assertEquals( false, $status->isOK(),
708 "Creation of concat file at $dest failed ($backendName)." );
709 }
710
711 if ( $okStatus ) {
712 $this->assertEquals( true, is_file( $dest ),
713 "Dest concat file $dest exists after creation ($backendName)." );
714 } else {
715 $this->assertEquals( true, is_file( $dest ),
716 "Dest concat file $dest exists after failed creation ($backendName)." );
717 }
718
719 $contents = file_get_contents( $dest );
720 $this->assertNotEquals( false, $contents, "File at $dest exists ($backendName)." );
721
722 if ( $okStatus ) {
723 $this->assertEquals( $expContent, $contents,
724 "Concat file at $dest has correct contents ($backendName)." );
725 } else {
726 $this->assertNotEquals( $expContent, $contents,
727 "Concat file at $dest has correct contents ($backendName)." );
728 }
729 }
730
731 function provider_testConcatenate() {
732 $cases = array();
733
734 $rand = mt_rand( 0, 2000000000 ) . time();
735 $dest = wfTempDir() . "/randomfile!$rand.txt";
736 $srcs = array(
737 $this->baseStorePath() . '/unittest-cont1/file1.txt',
738 $this->baseStorePath() . '/unittest-cont1/file2.txt',
739 $this->baseStorePath() . '/unittest-cont1/file3.txt',
740 $this->baseStorePath() . '/unittest-cont1/file4.txt',
741 $this->baseStorePath() . '/unittest-cont1/file5.txt',
742 $this->baseStorePath() . '/unittest-cont1/file6.txt',
743 $this->baseStorePath() . '/unittest-cont1/file7.txt',
744 $this->baseStorePath() . '/unittest-cont1/file8.txt',
745 $this->baseStorePath() . '/unittest-cont1/file9.txt',
746 $this->baseStorePath() . '/unittest-cont1/file10.txt'
747 );
748 $content = array(
749 'egfage',
750 'ageageag',
751 'rhokohlr',
752 'shgmslkg',
753 'kenga',
754 'owagmal',
755 'kgmae',
756 'g eak;g',
757 'lkaem;a',
758 'legma'
759 );
760 $params = array( 'srcs' => $srcs, 'dst' => $dest );
761
762 $cases[] = array(
763 $params, // operation
764 $srcs, // sources
765 $content, // content for each source
766 false, // no dest already exists
767 true, // succeeds
768 );
769
770 $cases[] = array(
771 $params, // operation
772 $srcs, // sources
773 $content, // content for each source
774 true, // dest already exists
775 false, // succeeds
776 );
777
778 return $cases;
779 }
780
781 /**
782 * @dataProvider provider_testGetFileStat
783 */
784 public function testGetFileStat( $path, $content, $alreadyExists ) {
785 $this->backend = $this->singleBackend;
786 $this->tearDownFiles();
787 $this->doTestGetFileStat( $path, $content, $alreadyExists );
788 $this->tearDownFiles();
789
790 $this->backend = $this->multiBackend;
791 $this->tearDownFiles();
792 $this->doTestGetFileStat( $path, $content, $alreadyExists );
793 $this->tearDownFiles();
794 }
795
796 private function doTestGetFileStat( $path, $content, $alreadyExists ) {
797 $backendName = $this->backendClass();
798
799 if ( $alreadyExists ) {
800 $this->prepare( array( 'dir' => dirname( $path ) ) );
801 $status = $this->backend->create( array( 'dst' => $path, 'content' => $content ) );
802 $this->assertEquals( array(), $status->errors,
803 "Creation of file at $path succeeded ($backendName)." );
804
805 $size = $this->backend->getFileSize( array( 'src' => $path ) );
806 $time = $this->backend->getFileTimestamp( array( 'src' => $path ) );
807 $stat = $this->backend->getFileStat( array( 'src' => $path ) );
808
809 $this->assertEquals( strlen( $content ), $size,
810 "Correct file size of '$path'" );
811 $this->assertTrue( abs( time() - wfTimestamp( TS_UNIX, $time ) ) < 5,
812 "Correct file timestamp of '$path'" );
813
814 $size = $stat['size'];
815 $time = $stat['mtime'];
816 $this->assertEquals( strlen( $content ), $size,
817 "Correct file size of '$path'" );
818 $this->assertTrue( abs( time() - wfTimestamp( TS_UNIX, $time ) ) < 5,
819 "Correct file timestamp of '$path'" );
820 } else {
821 $size = $this->backend->getFileSize( array( 'src' => $path ) );
822 $time = $this->backend->getFileTimestamp( array( 'src' => $path ) );
823 $stat = $this->backend->getFileStat( array( 'src' => $path ) );
824
825 $this->assertFalse( $size, "Correct file size of '$path'" );
826 $this->assertFalse( $time, "Correct file timestamp of '$path'" );
827 $this->assertFalse( $stat, "Correct file stat of '$path'" );
828 }
829 }
830
831 function provider_testGetFileStat() {
832 $cases = array();
833
834 $base = $this->baseStorePath();
835 $cases[] = array( "$base/unittest-cont1/b/z/some_file.txt", "some file contents", true );
836 $cases[] = array( "$base/unittest-cont1/b/some-other_file.txt", "", true );
837 $cases[] = array( "$base/unittest-cont1/b/some-diff_file.txt", null, false );
838
839 return $cases;
840 }
841
842 /**
843 * @dataProvider provider_testGetFileContents
844 */
845 public function testGetFileContents( $source, $content ) {
846 $this->backend = $this->singleBackend;
847 $this->tearDownFiles();
848 $this->doTestGetFileContents( $source, $content );
849 $this->tearDownFiles();
850
851 $this->backend = $this->multiBackend;
852 $this->tearDownFiles();
853 $this->doTestGetFileContents( $source, $content );
854 $this->tearDownFiles();
855 }
856
857 public function doTestGetFileContents( $source, $content ) {
858 $backendName = $this->backendClass();
859
860 $this->prepare( array( 'dir' => dirname( $source ) ) );
861
862 $status = $this->backend->doOperation(
863 array( 'op' => 'create', 'content' => $content, 'dst' => $source ) );
864 $this->assertEquals( array(), $status->errors,
865 "Creation of file at $source succeeded ($backendName)." );
866 $this->assertEquals( true, $status->isOK(),
867 "Creation of file at $source succeeded with OK status ($backendName)." );
868
869 $newContents = $this->backend->getFileContents( array( 'src' => $source, 'latest' => 1 ) );
870 $this->assertNotEquals( false, $newContents,
871 "Read of file at $source succeeded ($backendName)." );
872
873 $this->assertEquals( $content, $newContents,
874 "Contents read match data at $source ($backendName)." );
875 }
876
877 function provider_testGetFileContents() {
878 $cases = array();
879
880 $base = $this->baseStorePath();
881 $cases[] = array( "$base/unittest-cont1/b/z/some_file.txt", "some file contents" );
882 $cases[] = array( "$base/unittest-cont1/b/some-other_file.txt", "more file contents" );
883
884 return $cases;
885 }
886
887 /**
888 * @dataProvider provider_testGetLocalCopy
889 */
890 public function testGetLocalCopy( $source, $content ) {
891 $this->backend = $this->singleBackend;
892 $this->tearDownFiles();
893 $this->doTestGetLocalCopy( $source, $content );
894 $this->tearDownFiles();
895
896 $this->backend = $this->multiBackend;
897 $this->tearDownFiles();
898 $this->doTestGetLocalCopy( $source, $content );
899 $this->tearDownFiles();
900 }
901
902 public function doTestGetLocalCopy( $source, $content ) {
903 $backendName = $this->backendClass();
904
905 $this->prepare( array( 'dir' => dirname( $source ) ) );
906
907 $status = $this->backend->doOperation(
908 array( 'op' => 'create', 'content' => $content, 'dst' => $source ) );
909 $this->assertEquals( array(), $status->errors,
910 "Creation of file at $source succeeded ($backendName)." );
911
912 $tmpFile = $this->backend->getLocalCopy( array( 'src' => $source ) );
913 $this->assertNotNull( $tmpFile,
914 "Creation of local copy of $source succeeded ($backendName)." );
915
916 $contents = file_get_contents( $tmpFile->getPath() );
917 $this->assertNotEquals( false, $contents, "Local copy of $source exists ($backendName)." );
918 }
919
920 function provider_testGetLocalCopy() {
921 $cases = array();
922
923 $base = $this->baseStorePath();
924 $cases[] = array( "$base/unittest-cont1/a/z/some_file.txt", "some file contents" );
925 $cases[] = array( "$base/unittest-cont1/a/some-other_file.txt", "more file contents" );
926
927 return $cases;
928 }
929
930 /**
931 * @dataProvider provider_testGetLocalReference
932 */
933 public function testGetLocalReference( $source, $content ) {
934 $this->backend = $this->singleBackend;
935 $this->tearDownFiles();
936 $this->doTestGetLocalReference( $source, $content );
937 $this->tearDownFiles();
938
939 $this->backend = $this->multiBackend;
940 $this->tearDownFiles();
941 $this->doTestGetLocalReference( $source, $content );
942 $this->tearDownFiles();
943 }
944
945 private function doTestGetLocalReference( $source, $content ) {
946 $backendName = $this->backendClass();
947
948 $this->prepare( array( 'dir' => dirname( $source ) ) );
949
950 $status = $this->backend->doOperation(
951 array( 'op' => 'create', 'content' => $content, 'dst' => $source ) );
952 $this->assertEquals( array(), $status->errors,
953 "Creation of file at $source succeeded ($backendName)." );
954
955 $tmpFile = $this->backend->getLocalReference( array( 'src' => $source ) );
956 $this->assertNotNull( $tmpFile,
957 "Creation of local copy of $source succeeded ($backendName)." );
958
959 $contents = file_get_contents( $tmpFile->getPath() );
960 $this->assertNotEquals( false, $contents, "Local copy of $source exists ($backendName)." );
961 }
962
963 function provider_testGetLocalReference() {
964 $cases = array();
965
966 $base = $this->baseStorePath();
967 $cases[] = array( "$base/unittest-cont1/a/z/some_file.txt", "some file contents" );
968 $cases[] = array( "$base/unittest-cont1/a/some-other_file.txt", "more file contents" );
969
970 return $cases;
971 }
972
973 /**
974 * @dataProvider provider_testPrepareAndClean
975 */
976 public function testPrepareAndClean( $path, $isOK ) {
977 $this->backend = $this->singleBackend;
978 $this->doTestPrepareAndClean( $path, $isOK );
979 $this->tearDownFiles();
980
981 $this->backend = $this->multiBackend;
982 $this->doTestPrepareAndClean( $path, $isOK );
983 $this->tearDownFiles();
984 }
985
986 function provider_testPrepareAndClean() {
987 $base = $this->baseStorePath();
988 return array(
989 array( "$base/unittest-cont1/a/z/some_file1.txt", true ),
990 array( "$base/unittest-cont2/a/z/some_file2.txt", true ),
991 # Specific to FS backend with no basePath field set
992 #array( "$base/unittest-cont3/a/z/some_file3.txt", false ),
993 );
994 }
995
996 function doTestPrepareAndClean( $path, $isOK ) {
997 $backendName = $this->backendClass();
998
999 $status = $this->prepare( array( 'dir' => dirname( $path ) ) );
1000 if ( $isOK ) {
1001 $this->assertEquals( array(), $status->errors,
1002 "Preparing dir $path succeeded without warnings ($backendName)." );
1003 $this->assertEquals( true, $status->isOK(),
1004 "Preparing dir $path succeeded ($backendName)." );
1005 } else {
1006 $this->assertEquals( false, $status->isOK(),
1007 "Preparing dir $path failed ($backendName)." );
1008 }
1009
1010 $status = $this->backend->clean( array( 'dir' => dirname( $path ) ) );
1011 if ( $isOK ) {
1012 $this->assertEquals( array(), $status->errors,
1013 "Cleaning dir $path succeeded without warnings ($backendName)." );
1014 $this->assertEquals( true, $status->isOK(),
1015 "Cleaning dir $path succeeded ($backendName)." );
1016 } else {
1017 $this->assertEquals( false, $status->isOK(),
1018 "Cleaning dir $path failed ($backendName)." );
1019 }
1020 }
1021
1022 // @TODO: testSecure
1023
1024 public function testDoOperations() {
1025 $this->backend = $this->singleBackend;
1026 $this->tearDownFiles();
1027 $this->doTestDoOperations();
1028 $this->tearDownFiles();
1029
1030 $this->backend = $this->multiBackend;
1031 $this->tearDownFiles();
1032 $this->doTestDoOperations();
1033 $this->tearDownFiles();
1034
1035 // @TODO: test some cases where the ops should fail
1036 }
1037
1038 function doTestDoOperations() {
1039 $base = $this->baseStorePath();
1040
1041 $fileA = "$base/unittest-cont1/a/b/fileA.txt";
1042 $fileAContents = '3tqtmoeatmn4wg4qe-mg3qt3 tq';
1043 $fileB = "$base/unittest-cont1/a/b/fileB.txt";
1044 $fileBContents = 'g-jmq3gpqgt3qtg q3GT ';
1045 $fileC = "$base/unittest-cont1/a/b/fileC.txt";
1046 $fileCContents = 'eigna[ogmewt 3qt g3qg flew[ag';
1047 $fileD = "$base/unittest-cont1/a/b/fileD.txt";
1048
1049 $this->prepare( array( 'dir' => dirname( $fileA ) ) );
1050 $this->backend->create( array( 'dst' => $fileA, 'content' => $fileAContents ) );
1051 $this->prepare( array( 'dir' => dirname( $fileB ) ) );
1052 $this->backend->create( array( 'dst' => $fileB, 'content' => $fileBContents ) );
1053 $this->prepare( array( 'dir' => dirname( $fileC ) ) );
1054 $this->backend->create( array( 'dst' => $fileC, 'content' => $fileCContents ) );
1055
1056 $status = $this->backend->doOperations( array(
1057 array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC, 'overwrite' => 1 ),
1058 // Now: A:<A>, B:<B>, C:<A>, D:<D> (file:<orginal contents>)
1059 array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileA, 'overwriteSame' => 1 ),
1060 // Now: A:<A>, B:<B>, C:<A>, D:<D>
1061 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileD, 'overwrite' => 1 ),
1062 // Now: A:<A>, B:<B>, C:<empty>, D:<A>
1063 array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileC ),
1064 // Now: A:<A>, B:<empty>, C:<B>, D:<A>
1065 array( 'op' => 'move', 'src' => $fileD, 'dst' => $fileA, 'overwriteSame' => 1 ),
1066 // Now: A:<A>, B:<empty>, C:<B>, D:<empty>
1067 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileA, 'overwrite' => 1 ),
1068 // Now: A:<B>, B:<empty>, C:<empty>, D:<empty>
1069 array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC ),
1070 // Now: A:<B>, B:<empty>, C:<B>, D:<empty>
1071 array( 'op' => 'move', 'src' => $fileA, 'dst' => $fileC, 'overwriteSame' => 1 ),
1072 // Now: A:<empty>, B:<empty>, C:<B>, D:<empty>
1073 array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileC, 'overwrite' => 1 ),
1074 // Does nothing
1075 array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileC, 'overwriteSame' => 1 ),
1076 // Does nothing
1077 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileC, 'overwrite' => 1 ),
1078 // Does nothing
1079 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileC, 'overwriteSame' => 1 ),
1080 // Does nothing
1081 array( 'op' => 'null' ),
1082 // Does nothing
1083 ) );
1084
1085 $this->assertEquals( array(), $status->errors, "Operation batch succeeded" );
1086 $this->assertEquals( true, $status->isOK(), "Operation batch succeeded" );
1087 $this->assertEquals( 13, count( $status->success ),
1088 "Operation batch has correct success array" );
1089
1090 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileA ) ),
1091 "File does not exist at $fileA" );
1092 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileB ) ),
1093 "File does not exist at $fileB" );
1094 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileD ) ),
1095 "File does not exist at $fileD" );
1096
1097 $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $fileC ) ),
1098 "File exists at $fileC" );
1099 $this->assertEquals( $fileBContents,
1100 $this->backend->getFileContents( array( 'src' => $fileC ) ),
1101 "Correct file contents of $fileC" );
1102 $this->assertEquals( strlen( $fileBContents ),
1103 $this->backend->getFileSize( array( 'src' => $fileC ) ),
1104 "Correct file size of $fileC" );
1105 $this->assertEquals( wfBaseConvert( sha1( $fileBContents ), 16, 36, 31 ),
1106 $this->backend->getFileSha1Base36( array( 'src' => $fileC ) ),
1107 "Correct file SHA-1 of $fileC" );
1108 }
1109
1110 public function testGetFileList() {
1111 $this->backend = $this->singleBackend;
1112 $this->tearDownFiles();
1113 $this->doTestGetFileList();
1114 $this->tearDownFiles();
1115
1116 $this->backend = $this->multiBackend;
1117 $this->tearDownFiles();
1118 $this->doTestGetFileList();
1119 $this->tearDownFiles();
1120 }
1121
1122 private function doTestGetFileList() {
1123 $backendName = $this->backendClass();
1124
1125 $base = $this->baseStorePath();
1126 $files = array(
1127 "$base/unittest-cont1/test1.txt",
1128 "$base/unittest-cont1/test2.txt",
1129 "$base/unittest-cont1/test3.txt",
1130 "$base/unittest-cont1/subdir1/test1.txt",
1131 "$base/unittest-cont1/subdir1/test2.txt",
1132 "$base/unittest-cont1/subdir2/test3.txt",
1133 "$base/unittest-cont1/subdir2/test4.txt",
1134 "$base/unittest-cont1/subdir2/subdir/test1.txt",
1135 "$base/unittest-cont1/subdir2/subdir/test2.txt",
1136 "$base/unittest-cont1/subdir2/subdir/test3.txt",
1137 "$base/unittest-cont1/subdir2/subdir/test4.txt",
1138 "$base/unittest-cont1/subdir2/subdir/test5.txt",
1139 "$base/unittest-cont1/subdir2/subdir/sub/test0.txt",
1140 "$base/unittest-cont1/subdir2/subdir/sub/120-px-file.txt",
1141 );
1142
1143 // Add the files
1144 $ops = array();
1145 foreach ( $files as $file ) {
1146 $this->prepare( array( 'dir' => dirname( $file ) ) );
1147 $ops[] = array( 'op' => 'create', 'content' => 'xxy', 'dst' => $file );
1148 }
1149 $status = $this->backend->doOperations( $ops );
1150 $this->assertEquals( array(), $status->errors,
1151 "Creation of files succeeded ($backendName)." );
1152 $this->assertEquals( true, $status->isOK(),
1153 "Creation of files succeeded with OK status ($backendName)." );
1154
1155 // Expected listing
1156 $expected = array(
1157 "test1.txt",
1158 "test2.txt",
1159 "test3.txt",
1160 "subdir1/test1.txt",
1161 "subdir1/test2.txt",
1162 "subdir2/test3.txt",
1163 "subdir2/test4.txt",
1164 "subdir2/subdir/test1.txt",
1165 "subdir2/subdir/test2.txt",
1166 "subdir2/subdir/test3.txt",
1167 "subdir2/subdir/test4.txt",
1168 "subdir2/subdir/test5.txt",
1169 "subdir2/subdir/sub/test0.txt",
1170 "subdir2/subdir/sub/120-px-file.txt",
1171 );
1172 sort( $expected );
1173
1174 // Actual listing (no trailing slash)
1175 $list = array();
1176 $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1" ) );
1177 foreach ( $iter as $file ) {
1178 $list[] = $file;
1179 }
1180 sort( $list );
1181
1182 $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
1183
1184 // Actual listing (with trailing slash)
1185 $list = array();
1186 $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/" ) );
1187 foreach ( $iter as $file ) {
1188 $list[] = $file;
1189 }
1190 sort( $list );
1191
1192 $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
1193
1194 // Expected listing
1195 $expected = array(
1196 "test1.txt",
1197 "test2.txt",
1198 "test3.txt",
1199 "test4.txt",
1200 "test5.txt",
1201 "sub/test0.txt",
1202 "sub/120-px-file.txt",
1203 );
1204 sort( $expected );
1205
1206 // Actual listing (no trailing slash)
1207 $list = array();
1208 $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/subdir2/subdir" ) );
1209 foreach ( $iter as $file ) {
1210 $list[] = $file;
1211 }
1212 sort( $list );
1213
1214 $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
1215
1216 // Actual listing (with trailing slash)
1217 $list = array();
1218 $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/subdir2/subdir/" ) );
1219 foreach ( $iter as $file ) {
1220 $list[] = $file;
1221 }
1222 sort( $list );
1223
1224 $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
1225
1226 // Actual listing (using iterator second time)
1227 $list = array();
1228 foreach ( $iter as $file ) {
1229 $list[] = $file;
1230 }
1231 sort( $list );
1232
1233 $this->assertEquals( $expected, $list, "Correct file listing ($backendName), second iteration." );
1234
1235 foreach ( $files as $file ) { // clean up
1236 $this->backend->doOperation( array( 'op' => 'delete', 'src' => $file ) );
1237 }
1238
1239 $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/not/exists" ) );
1240 foreach ( $iter as $iter ) {} // no errors
1241 }
1242
1243 // test helper wrapper for backend prepare() function
1244 private function prepare( array $params ) {
1245 $this->dirsToPrune[] = $params['dir'];
1246 return $this->backend->prepare( $params );
1247 }
1248
1249 function tearDownFiles() {
1250 foreach ( $this->filesToPrune as $file ) {
1251 @unlink( $file );
1252 }
1253 $containers = array( 'unittest-cont1', 'unittest-cont2', 'unittest-cont3' );
1254 foreach ( $containers as $container ) {
1255 $this->deleteFiles( $container );
1256 }
1257 foreach ( $this->dirsToPrune as $dir ) {
1258 $this->recursiveClean( $dir );
1259 }
1260 $this->filesToPrune = $this->dirsToPrune = array();
1261 }
1262
1263 private function deleteFiles( $container ) {
1264 $base = $this->baseStorePath();
1265 $iter = $this->backend->getFileList( array( 'dir' => "$base/$container" ) );
1266 if ( $iter ) {
1267 foreach ( $iter as $file ) {
1268 $this->backend->delete( array( 'src' => "$base/$container/$file" ), array( 'force' => 1 ) );
1269 }
1270 }
1271 }
1272
1273 private function recursiveClean( $dir ) {
1274 do {
1275 if ( !$this->backend->clean( array( 'dir' => $dir ) )->isOK() ) {
1276 break;
1277 }
1278 } while ( $dir = FileBackend::parentStoragePath( $dir ) );
1279 }
1280
1281 function tearDown() {
1282 parent::tearDown();
1283 }
1284 }