Merge "Remove extra unneeded whitespace"
[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 static $backendToUse;
11
12 function setUp() {
13 global $wgFileBackends;
14 parent::setUp();
15 $tmpPrefix = wfTempDir() . '/filebackend-unittest-' . time() . '-' . mt_rand();
16 if ( $this->getCliArg( 'use-filebackend=' ) ) {
17 if ( self::$backendToUse ) {
18 $this->singleBackend = self::$backendToUse;
19 } else {
20 $name = $this->getCliArg( 'use-filebackend=' );
21 $useConfig = array();
22 foreach ( $wgFileBackends as $conf ) {
23 if ( $conf['name'] == $name ) {
24 $useConfig = $conf;
25 break;
26 }
27 }
28 $useConfig['name'] = 'localtesting'; // swap name
29 $class = $useConfig['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 #'parallelize' => 'implicit',
38 'containerPaths' => array(
39 'unittest-cont1' => "{$tmpPrefix}-localtesting-cont1",
40 'unittest-cont2' => "{$tmpPrefix}-localtesting-cont2" )
41 ) );
42 }
43 $this->multiBackend = new FileBackendMultiWrite( array(
44 'name' => 'localtesting',
45 'lockManager' => 'fsLockManager',
46 'parallelize' => 'implicit',
47 'backends' => array(
48 array(
49 'name' => 'localmutlitesting1',
50 'class' => 'FSFileBackend',
51 'lockManager' => 'nullLockManager',
52 'containerPaths' => array(
53 'unittest-cont1' => "{$tmpPrefix}-localtestingmulti1-cont1",
54 'unittest-cont2' => "{$tmpPrefix}-localtestingmulti1-cont2" ),
55 'isMultiMaster' => false
56 ),
57 array(
58 'name' => 'localmutlitesting2',
59 'class' => 'FSFileBackend',
60 'lockManager' => 'nullLockManager',
61 'containerPaths' => array(
62 'unittest-cont1' => "{$tmpPrefix}-localtestingmulti2-cont1",
63 'unittest-cont2' => "{$tmpPrefix}-localtestingmulti2-cont2" ),
64 'isMultiMaster' => true
65 )
66 )
67 ) );
68 $this->filesToPrune = array();
69 }
70
71 private function baseStorePath() {
72 return 'mwstore://localtesting';
73 }
74
75 private function backendClass() {
76 return get_class( $this->backend );
77 }
78
79 /**
80 * @dataProvider provider_testIsStoragePath
81 */
82 public function testIsStoragePath( $path, $isStorePath ) {
83 $this->assertEquals( $isStorePath, FileBackend::isStoragePath( $path ),
84 "FileBackend::isStoragePath on path '$path'" );
85 }
86
87 function provider_testIsStoragePath() {
88 return array(
89 array( 'mwstore://', true ),
90 array( 'mwstore://backend', true ),
91 array( 'mwstore://backend/container', true ),
92 array( 'mwstore://backend/container/', true ),
93 array( 'mwstore://backend/container/path', true ),
94 array( 'mwstore://backend//container/', true ),
95 array( 'mwstore://backend//container//', true ),
96 array( 'mwstore://backend//container//path', true ),
97 array( 'mwstore:///', true ),
98 array( 'mwstore:/', false ),
99 array( 'mwstore:', false ),
100 );
101 }
102
103 /**
104 * @dataProvider provider_testSplitStoragePath
105 */
106 public function testSplitStoragePath( $path, $res ) {
107 $this->assertEquals( $res, FileBackend::splitStoragePath( $path ),
108 "FileBackend::splitStoragePath on path '$path'" );
109 }
110
111 function provider_testSplitStoragePath() {
112 return array(
113 array( 'mwstore://backend/container', array( 'backend', 'container', '' ) ),
114 array( 'mwstore://backend/container/', array( 'backend', 'container', '' ) ),
115 array( 'mwstore://backend/container/path', array( 'backend', 'container', 'path' ) ),
116 array( 'mwstore://backend/container//path', array( 'backend', 'container', '/path' ) ),
117 array( 'mwstore://backend//container/path', array( null, null, null ) ),
118 array( 'mwstore://backend//container//path', array( null, null, null ) ),
119 array( 'mwstore://', array( null, null, null ) ),
120 array( 'mwstore://backend', array( null, null, null ) ),
121 array( 'mwstore:///', array( null, null, null ) ),
122 array( 'mwstore:/', array( null, null, null ) ),
123 array( 'mwstore:', array( null, null, null ) )
124 );
125 }
126
127 /**
128 * @dataProvider provider_normalizeStoragePath
129 */
130 public function testNormalizeStoragePath( $path, $res ) {
131 $this->assertEquals( $res, FileBackend::normalizeStoragePath( $path ),
132 "FileBackend::normalizeStoragePath on path '$path'" );
133 }
134
135 function provider_normalizeStoragePath() {
136 return array(
137 array( 'mwstore://backend/container', 'mwstore://backend/container' ),
138 array( 'mwstore://backend/container/', 'mwstore://backend/container' ),
139 array( 'mwstore://backend/container/path', 'mwstore://backend/container/path' ),
140 array( 'mwstore://backend/container//path', 'mwstore://backend/container/path' ),
141 array( 'mwstore://backend/container///path', 'mwstore://backend/container/path' ),
142 array( 'mwstore://backend/container///path//to///obj', 'mwstore://backend/container/path/to/obj',
143 array( 'mwstore://', null ),
144 array( 'mwstore://backend', null ),
145 array( 'mwstore://backend//container/path', null ),
146 array( 'mwstore://backend//container//path', null ),
147 array( 'mwstore:///', null ),
148 array( 'mwstore:/', null ),
149 array( 'mwstore:', null ), )
150 );
151 }
152
153 /**
154 * @dataProvider provider_testParentStoragePath
155 */
156 public function testParentStoragePath( $path, $res ) {
157 $this->assertEquals( $res, FileBackend::parentStoragePath( $path ),
158 "FileBackend::parentStoragePath on path '$path'" );
159 }
160
161 function provider_testParentStoragePath() {
162 return array(
163 array( 'mwstore://backend/container/path/to/obj', 'mwstore://backend/container/path/to' ),
164 array( 'mwstore://backend/container/path/to', 'mwstore://backend/container/path' ),
165 array( 'mwstore://backend/container/path', 'mwstore://backend/container' ),
166 array( 'mwstore://backend/container', null ),
167 array( 'mwstore://backend/container/path/to/obj/', 'mwstore://backend/container/path/to' ),
168 array( 'mwstore://backend/container/path/to/', 'mwstore://backend/container/path' ),
169 array( 'mwstore://backend/container/path/', 'mwstore://backend/container' ),
170 array( 'mwstore://backend/container/', null ),
171 );
172 }
173
174 /**
175 * @dataProvider provider_testExtensionFromPath
176 */
177 public function testExtensionFromPath( $path, $res ) {
178 $this->assertEquals( $res, FileBackend::extensionFromPath( $path ),
179 "FileBackend::extensionFromPath on path '$path'" );
180 }
181
182 function provider_testExtensionFromPath() {
183 return array(
184 array( 'mwstore://backend/container/path.txt', 'txt' ),
185 array( 'mwstore://backend/container/path.svg.png', 'png' ),
186 array( 'mwstore://backend/container/path', '' ),
187 array( 'mwstore://backend/container/path.', '' ),
188 );
189 }
190
191 /**
192 * @dataProvider provider_testStore
193 */
194 public function testStore( $op ) {
195 $this->filesToPrune[] = $op['src'];
196
197 $this->backend = $this->singleBackend;
198 $this->tearDownFiles();
199 $this->doTestStore( $op );
200 $this->tearDownFiles();
201
202 $this->backend = $this->multiBackend;
203 $this->tearDownFiles();
204 $this->doTestStore( $op );
205 $this->filesToPrune[] = $op['src']; # avoid file leaking
206 $this->tearDownFiles();
207 }
208
209 private function doTestStore( $op ) {
210 $backendName = $this->backendClass();
211
212 $source = $op['src'];
213 $dest = $op['dst'];
214 $this->prepare( array( 'dir' => dirname( $dest ) ) );
215
216 file_put_contents( $source, "Unit test file" );
217
218 if ( isset( $op['overwrite'] ) || isset( $op['overwriteSame'] ) ) {
219 $this->backend->store( $op );
220 }
221
222 $status = $this->backend->doOperation( $op );
223
224 $this->assertGoodStatus( $status,
225 "Store from $source to $dest succeeded without warnings ($backendName)." );
226 $this->assertEquals( true, $status->isOK(),
227 "Store from $source to $dest succeeded ($backendName)." );
228 $this->assertEquals( array( 0 => true ), $status->success,
229 "Store from $source to $dest has proper 'success' field in Status ($backendName)." );
230 $this->assertEquals( true, file_exists( $source ),
231 "Source file $source still exists ($backendName)." );
232 $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $dest ) ),
233 "Destination file $dest exists ($backendName)." );
234
235 $this->assertEquals( filesize( $source ),
236 $this->backend->getFileSize( array( 'src' => $dest ) ),
237 "Destination file $dest has correct size ($backendName)." );
238
239 $props1 = FSFile::getPropsFromPath( $source );
240 $props2 = $this->backend->getFileProps( array( 'src' => $dest ) );
241 $this->assertEquals( $props1, $props2,
242 "Source and destination have the same props ($backendName)." );
243 }
244
245 public function provider_testStore() {
246 $cases = array();
247
248 $tmpName = TempFSFile::factory( "unittests_", 'txt' )->getPath();
249 $toPath = $this->baseStorePath() . '/unittest-cont1/fun/obj1.txt';
250 $op = array( 'op' => 'store', 'src' => $tmpName, 'dst' => $toPath );
251 $cases[] = array(
252 $op, // operation
253 $tmpName, // source
254 $toPath, // dest
255 );
256
257 $op2 = $op;
258 $op2['overwrite'] = true;
259 $cases[] = array(
260 $op2, // operation
261 $tmpName, // source
262 $toPath, // dest
263 );
264
265 $op2 = $op;
266 $op2['overwriteSame'] = true;
267 $cases[] = array(
268 $op2, // operation
269 $tmpName, // source
270 $toPath, // dest
271 );
272
273 return $cases;
274 }
275
276 /**
277 * @dataProvider provider_testCopy
278 */
279 public function testCopy( $op ) {
280 $this->backend = $this->singleBackend;
281 $this->tearDownFiles();
282 $this->doTestCopy( $op );
283 $this->tearDownFiles();
284
285 $this->backend = $this->multiBackend;
286 $this->tearDownFiles();
287 $this->doTestCopy( $op );
288 $this->tearDownFiles();
289 }
290
291 private function doTestCopy( $op ) {
292 $backendName = $this->backendClass();
293
294 $source = $op['src'];
295 $dest = $op['dst'];
296 $this->prepare( array( 'dir' => dirname( $source ) ) );
297 $this->prepare( array( 'dir' => dirname( $dest ) ) );
298
299 $status = $this->backend->doOperation(
300 array( 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ) );
301 $this->assertGoodStatus( $status,
302 "Creation of file at $source succeeded ($backendName)." );
303
304 if ( isset( $op['overwrite'] ) || isset( $op['overwriteSame'] ) ) {
305 $this->backend->copy( $op );
306 }
307
308 $status = $this->backend->doOperation( $op );
309
310 $this->assertGoodStatus( $status,
311 "Copy from $source to $dest succeeded without warnings ($backendName)." );
312 $this->assertEquals( true, $status->isOK(),
313 "Copy from $source to $dest succeeded ($backendName)." );
314 $this->assertEquals( array( 0 => true ), $status->success,
315 "Copy from $source to $dest has proper 'success' field in Status ($backendName)." );
316 $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $source ) ),
317 "Source file $source still exists ($backendName)." );
318 $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $dest ) ),
319 "Destination file $dest exists after copy ($backendName)." );
320
321 $this->assertEquals(
322 $this->backend->getFileSize( array( 'src' => $source ) ),
323 $this->backend->getFileSize( array( 'src' => $dest ) ),
324 "Destination file $dest has correct size ($backendName)." );
325
326 $props1 = $this->backend->getFileProps( array( 'src' => $source ) );
327 $props2 = $this->backend->getFileProps( array( 'src' => $dest ) );
328 $this->assertEquals( $props1, $props2,
329 "Source and destination have the same props ($backendName)." );
330 }
331
332 public function provider_testCopy() {
333 $cases = array();
334
335 $source = $this->baseStorePath() . '/unittest-cont1/file.txt';
336 $dest = $this->baseStorePath() . '/unittest-cont2/fileMoved.txt';
337
338 $op = array( 'op' => 'copy', 'src' => $source, 'dst' => $dest );
339 $cases[] = array(
340 $op, // operation
341 $source, // source
342 $dest, // dest
343 );
344
345 $op2 = $op;
346 $op2['overwrite'] = true;
347 $cases[] = array(
348 $op2, // operation
349 $source, // source
350 $dest, // dest
351 );
352
353 $op2 = $op;
354 $op2['overwriteSame'] = true;
355 $cases[] = array(
356 $op2, // operation
357 $source, // source
358 $dest, // dest
359 );
360
361 return $cases;
362 }
363
364 /**
365 * @dataProvider provider_testMove
366 */
367 public function testMove( $op ) {
368 $this->backend = $this->singleBackend;
369 $this->tearDownFiles();
370 $this->doTestMove( $op );
371 $this->tearDownFiles();
372
373 $this->backend = $this->multiBackend;
374 $this->tearDownFiles();
375 $this->doTestMove( $op );
376 $this->tearDownFiles();
377 }
378
379 private function doTestMove( $op ) {
380 $backendName = $this->backendClass();
381
382 $source = $op['src'];
383 $dest = $op['dst'];
384 $this->prepare( array( 'dir' => dirname( $source ) ) );
385 $this->prepare( array( 'dir' => dirname( $dest ) ) );
386
387 $status = $this->backend->doOperation(
388 array( 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ) );
389 $this->assertGoodStatus( $status,
390 "Creation of file at $source succeeded ($backendName)." );
391
392 if ( isset( $op['overwrite'] ) || isset( $op['overwriteSame'] ) ) {
393 $this->backend->copy( $op );
394 }
395
396 $status = $this->backend->doOperation( $op );
397 $this->assertGoodStatus( $status,
398 "Move from $source to $dest succeeded without warnings ($backendName)." );
399 $this->assertEquals( true, $status->isOK(),
400 "Move from $source to $dest succeeded ($backendName)." );
401 $this->assertEquals( array( 0 => true ), $status->success,
402 "Move from $source to $dest has proper 'success' field in Status ($backendName)." );
403 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $source ) ),
404 "Source file $source does not still exists ($backendName)." );
405 $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $dest ) ),
406 "Destination file $dest exists after move ($backendName)." );
407
408 $this->assertNotEquals(
409 $this->backend->getFileSize( array( 'src' => $source ) ),
410 $this->backend->getFileSize( array( 'src' => $dest ) ),
411 "Destination file $dest has correct size ($backendName)." );
412
413 $props1 = $this->backend->getFileProps( array( 'src' => $source ) );
414 $props2 = $this->backend->getFileProps( array( 'src' => $dest ) );
415 $this->assertEquals( false, $props1['fileExists'],
416 "Source file does not exist accourding to props ($backendName)." );
417 $this->assertEquals( true, $props2['fileExists'],
418 "Destination file exists accourding to props ($backendName)." );
419 }
420
421 public function provider_testMove() {
422 $cases = array();
423
424 $source = $this->baseStorePath() . '/unittest-cont1/file.txt';
425 $dest = $this->baseStorePath() . '/unittest-cont2/fileMoved.txt';
426
427 $op = array( 'op' => 'move', 'src' => $source, 'dst' => $dest );
428 $cases[] = array(
429 $op, // operation
430 $source, // source
431 $dest, // dest
432 );
433
434 $op2 = $op;
435 $op2['overwrite'] = true;
436 $cases[] = array(
437 $op2, // operation
438 $source, // source
439 $dest, // dest
440 );
441
442 $op2 = $op;
443 $op2['overwriteSame'] = true;
444 $cases[] = array(
445 $op2, // operation
446 $source, // source
447 $dest, // dest
448 );
449
450 return $cases;
451 }
452
453 /**
454 * @dataProvider provider_testDelete
455 */
456 public function testDelete( $op, $withSource, $okStatus ) {
457 $this->backend = $this->singleBackend;
458 $this->tearDownFiles();
459 $this->doTestDelete( $op, $withSource, $okStatus );
460 $this->tearDownFiles();
461
462 $this->backend = $this->multiBackend;
463 $this->tearDownFiles();
464 $this->doTestDelete( $op, $withSource, $okStatus );
465 $this->tearDownFiles();
466 }
467
468 private function doTestDelete( $op, $withSource, $okStatus ) {
469 $backendName = $this->backendClass();
470
471 $source = $op['src'];
472 $this->prepare( array( 'dir' => dirname( $source ) ) );
473
474 if ( $withSource ) {
475 $status = $this->backend->doOperation(
476 array( 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ) );
477 $this->assertGoodStatus( $status,
478 "Creation of file at $source succeeded ($backendName)." );
479 }
480
481 $status = $this->backend->doOperation( $op );
482 if ( $okStatus ) {
483 $this->assertGoodStatus( $status,
484 "Deletion of file at $source succeeded without warnings ($backendName)." );
485 $this->assertEquals( true, $status->isOK(),
486 "Deletion of file at $source succeeded ($backendName)." );
487 $this->assertEquals( array( 0 => true ), $status->success,
488 "Deletion of file at $source has proper 'success' field in Status ($backendName)." );
489 } else {
490 $this->assertEquals( false, $status->isOK(),
491 "Deletion of file at $source failed ($backendName)." );
492 }
493
494 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $source ) ),
495 "Source file $source does not exist after move ($backendName)." );
496
497 $this->assertFalse(
498 $this->backend->getFileSize( array( 'src' => $source ) ),
499 "Source file $source has correct size (false) ($backendName)." );
500
501 $props1 = $this->backend->getFileProps( array( 'src' => $source ) );
502 $this->assertFalse( $props1['fileExists'],
503 "Source file $source does not exist according to props ($backendName)." );
504 }
505
506 public function provider_testDelete() {
507 $cases = array();
508
509 $source = $this->baseStorePath() . '/unittest-cont1/myfacefile.txt';
510
511 $op = array( 'op' => 'delete', 'src' => $source );
512 $cases[] = array(
513 $op, // operation
514 true, // with source
515 true // succeeds
516 );
517
518 $cases[] = array(
519 $op, // operation
520 false, // without source
521 false // fails
522 );
523
524 $op['ignoreMissingSource'] = true;
525 $cases[] = array(
526 $op, // operation
527 false, // without source
528 true // succeeds
529 );
530
531 return $cases;
532 }
533
534 /**
535 * @dataProvider provider_testCreate
536 */
537 public function testCreate( $op, $alreadyExists, $okStatus, $newSize ) {
538 $this->backend = $this->singleBackend;
539 $this->tearDownFiles();
540 $this->doTestCreate( $op, $alreadyExists, $okStatus, $newSize );
541 $this->tearDownFiles();
542
543 $this->backend = $this->multiBackend;
544 $this->tearDownFiles();
545 $this->doTestCreate( $op, $alreadyExists, $okStatus, $newSize );
546 $this->tearDownFiles();
547 }
548
549 private function doTestCreate( $op, $alreadyExists, $okStatus, $newSize ) {
550 $backendName = $this->backendClass();
551
552 $dest = $op['dst'];
553 $this->prepare( array( 'dir' => dirname( $dest ) ) );
554
555 $oldText = 'blah...blah...waahwaah';
556 if ( $alreadyExists ) {
557 $status = $this->backend->doOperation(
558 array( 'op' => 'create', 'content' => $oldText, 'dst' => $dest ) );
559 $this->assertGoodStatus( $status,
560 "Creation of file at $dest succeeded ($backendName)." );
561 }
562
563 $status = $this->backend->doOperation( $op );
564 if ( $okStatus ) {
565 $this->assertGoodStatus( $status,
566 "Creation of file at $dest succeeded without warnings ($backendName)." );
567 $this->assertEquals( true, $status->isOK(),
568 "Creation of file at $dest succeeded ($backendName)." );
569 $this->assertEquals( array( 0 => true ), $status->success,
570 "Creation of file at $dest has proper 'success' field in Status ($backendName)." );
571 } else {
572 $this->assertEquals( false, $status->isOK(),
573 "Creation of file at $dest failed ($backendName)." );
574 }
575
576 $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $dest ) ),
577 "Destination file $dest exists after creation ($backendName)." );
578
579 $props1 = $this->backend->getFileProps( array( 'src' => $dest ) );
580 $this->assertEquals( true, $props1['fileExists'],
581 "Destination file $dest exists according to props ($backendName)." );
582 if ( $okStatus ) { // file content is what we saved
583 $this->assertEquals( $newSize, $props1['size'],
584 "Destination file $dest has expected size according to props ($backendName)." );
585 $this->assertEquals( $newSize,
586 $this->backend->getFileSize( array( 'src' => $dest ) ),
587 "Destination file $dest has correct size ($backendName)." );
588 } else { // file content is some other previous text
589 $this->assertEquals( strlen( $oldText ), $props1['size'],
590 "Destination file $dest has original size according to props ($backendName)." );
591 $this->assertEquals( strlen( $oldText ),
592 $this->backend->getFileSize( array( 'src' => $dest ) ),
593 "Destination file $dest has original size according to props ($backendName)." );
594 }
595 }
596
597 /**
598 * @dataProvider provider_testCreate
599 */
600 public function provider_testCreate() {
601 $cases = array();
602
603 $dest = $this->baseStorePath() . '/unittest-cont2/myspacefile.txt';
604
605 $op = array( 'op' => 'create', 'content' => 'test test testing', 'dst' => $dest );
606 $cases[] = array(
607 $op, // operation
608 false, // no dest already exists
609 true, // succeeds
610 strlen( $op['content'] )
611 );
612
613 $op2 = $op;
614 $op2['content'] = "\n";
615 $cases[] = array(
616 $op2, // operation
617 false, // no dest already exists
618 true, // succeeds
619 strlen( $op2['content'] )
620 );
621
622 $op2 = $op;
623 $op2['content'] = "fsf\n waf 3kt";
624 $cases[] = array(
625 $op2, // operation
626 true, // dest already exists
627 false, // fails
628 strlen( $op2['content'] )
629 );
630
631 $op2 = $op;
632 $op2['content'] = "egm'g gkpe gpqg eqwgwqg";
633 $op2['overwrite'] = true;
634 $cases[] = array(
635 $op2, // operation
636 true, // dest already exists
637 true, // succeeds
638 strlen( $op2['content'] )
639 );
640
641 $op2 = $op;
642 $op2['content'] = "39qjmg3-qg";
643 $op2['overwriteSame'] = true;
644 $cases[] = array(
645 $op2, // operation
646 true, // dest already exists
647 false, // succeeds
648 strlen( $op2['content'] )
649 );
650
651 return $cases;
652 }
653
654 public function testDoQuickOperations() {
655 $this->backend = $this->singleBackend;
656 $this->doTestDoQuickOperations();
657 $this->tearDownFiles();
658
659 $this->backend = $this->multiBackend;
660 $this->doTestDoQuickOperations();
661 $this->tearDownFiles();
662 }
663
664 private function doTestDoQuickOperations() {
665 $backendName = $this->backendClass();
666
667 $base = $this->baseStorePath();
668 $files = array(
669 "$base/unittest-cont1/fileA.a",
670 "$base/unittest-cont1/fileB.a",
671 "$base/unittest-cont1/fileC.a"
672 );
673 $ops = array();
674 $purgeOps = array();
675 foreach ( $files as $path ) {
676 $status = $this->prepare( array( 'dir' => dirname( $path ) ) );
677 $this->assertGoodStatus( $status,
678 "Preparing $path succeeded without warnings ($backendName)." );
679 $ops[] = array( 'op' => 'create', 'dst' => $path, 'content' => mt_rand(0,50000) );
680 $purgeOps[] = array( 'op' => 'delete', 'src' => $path );
681 }
682 $purgeOps[] = array( 'op' => 'null' );
683 $status = $this->backend->doQuickOperations( $ops );
684 $this->assertGoodStatus( $status,
685 "Creation of source files succeeded ($backendName)." );
686
687 foreach ( $files as $file ) {
688 $this->assertTrue( $this->backend->fileExists( array( 'src' => $file ) ),
689 "File $file exists." );
690 }
691
692 $status = $this->backend->doQuickOperations( $purgeOps );
693 $this->assertGoodStatus( $status,
694 "Quick deletion of source files succeeded ($backendName)." );
695
696 foreach ( $files as $file ) {
697 $this->assertFalse( $this->backend->fileExists( array( 'src' => $file ) ),
698 "File $file purged." );
699 }
700 }
701
702 /**
703 * @dataProvider provider_testConcatenate
704 */
705 public function testConcatenate( $op, $srcs, $srcsContent, $alreadyExists, $okStatus ) {
706 $this->filesToPrune[] = $op['dst'];
707
708 $this->backend = $this->singleBackend;
709 $this->tearDownFiles();
710 $this->doTestConcatenate( $op, $srcs, $srcsContent, $alreadyExists, $okStatus );
711 $this->tearDownFiles();
712
713 $this->backend = $this->multiBackend;
714 $this->tearDownFiles();
715 $this->doTestConcatenate( $op, $srcs, $srcsContent, $alreadyExists, $okStatus );
716 $this->filesToPrune[] = $op['dst']; # avoid file leaking
717 $this->tearDownFiles();
718 }
719
720 private function doTestConcatenate( $params, $srcs, $srcsContent, $alreadyExists, $okStatus ) {
721 $backendName = $this->backendClass();
722
723 $expContent = '';
724 // Create sources
725 $ops = array();
726 foreach ( $srcs as $i => $source ) {
727 $this->prepare( array( 'dir' => dirname( $source ) ) );
728 $ops[] = array(
729 'op' => 'create', // operation
730 'dst' => $source, // source
731 'content' => $srcsContent[$i]
732 );
733 $expContent .= $srcsContent[$i];
734 }
735 $status = $this->backend->doOperations( $ops );
736
737 $this->assertGoodStatus( $status,
738 "Creation of source files succeeded ($backendName)." );
739
740 $dest = $params['dst'];
741 if ( $alreadyExists ) {
742 $ok = file_put_contents( $dest, 'blah...blah...waahwaah' ) !== false;
743 $this->assertEquals( true, $ok,
744 "Creation of file at $dest succeeded ($backendName)." );
745 } else {
746 $ok = file_put_contents( $dest, '' ) !== false;
747 $this->assertEquals( true, $ok,
748 "Creation of 0-byte file at $dest succeeded ($backendName)." );
749 }
750
751 // Combine the files into one
752 $status = $this->backend->concatenate( $params );
753 if ( $okStatus ) {
754 $this->assertGoodStatus( $status,
755 "Creation of concat file at $dest succeeded without warnings ($backendName)." );
756 $this->assertEquals( true, $status->isOK(),
757 "Creation of concat file at $dest succeeded ($backendName)." );
758 } else {
759 $this->assertEquals( false, $status->isOK(),
760 "Creation of concat file at $dest failed ($backendName)." );
761 }
762
763 if ( $okStatus ) {
764 $this->assertEquals( true, is_file( $dest ),
765 "Dest concat file $dest exists after creation ($backendName)." );
766 } else {
767 $this->assertEquals( true, is_file( $dest ),
768 "Dest concat file $dest exists after failed creation ($backendName)." );
769 }
770
771 $contents = file_get_contents( $dest );
772 $this->assertNotEquals( false, $contents, "File at $dest exists ($backendName)." );
773
774 if ( $okStatus ) {
775 $this->assertEquals( $expContent, $contents,
776 "Concat file at $dest has correct contents ($backendName)." );
777 } else {
778 $this->assertNotEquals( $expContent, $contents,
779 "Concat file at $dest has correct contents ($backendName)." );
780 }
781 }
782
783 function provider_testConcatenate() {
784 $cases = array();
785
786 $rand = mt_rand( 0, 2000000000 ) . time();
787 $dest = wfTempDir() . "/randomfile!$rand.txt";
788 $srcs = array(
789 $this->baseStorePath() . '/unittest-cont1/file1.txt',
790 $this->baseStorePath() . '/unittest-cont1/file2.txt',
791 $this->baseStorePath() . '/unittest-cont1/file3.txt',
792 $this->baseStorePath() . '/unittest-cont1/file4.txt',
793 $this->baseStorePath() . '/unittest-cont1/file5.txt',
794 $this->baseStorePath() . '/unittest-cont1/file6.txt',
795 $this->baseStorePath() . '/unittest-cont1/file7.txt',
796 $this->baseStorePath() . '/unittest-cont1/file8.txt',
797 $this->baseStorePath() . '/unittest-cont1/file9.txt',
798 $this->baseStorePath() . '/unittest-cont1/file10.txt'
799 );
800 $content = array(
801 'egfage',
802 'ageageag',
803 'rhokohlr',
804 'shgmslkg',
805 'kenga',
806 'owagmal',
807 'kgmae',
808 'g eak;g',
809 'lkaem;a',
810 'legma'
811 );
812 $params = array( 'srcs' => $srcs, 'dst' => $dest );
813
814 $cases[] = array(
815 $params, // operation
816 $srcs, // sources
817 $content, // content for each source
818 false, // no dest already exists
819 true, // succeeds
820 );
821
822 $cases[] = array(
823 $params, // operation
824 $srcs, // sources
825 $content, // content for each source
826 true, // dest already exists
827 false, // succeeds
828 );
829
830 return $cases;
831 }
832
833 /**
834 * @dataProvider provider_testGetFileStat
835 */
836 public function testGetFileStat( $path, $content, $alreadyExists ) {
837 $this->backend = $this->singleBackend;
838 $this->tearDownFiles();
839 $this->doTestGetFileStat( $path, $content, $alreadyExists );
840 $this->tearDownFiles();
841
842 $this->backend = $this->multiBackend;
843 $this->tearDownFiles();
844 $this->doTestGetFileStat( $path, $content, $alreadyExists );
845 $this->tearDownFiles();
846 }
847
848 private function doTestGetFileStat( $path, $content, $alreadyExists ) {
849 $backendName = $this->backendClass();
850
851 if ( $alreadyExists ) {
852 $this->prepare( array( 'dir' => dirname( $path ) ) );
853 $status = $this->backend->create( array( 'dst' => $path, 'content' => $content ) );
854 $this->assertGoodStatus( $status,
855 "Creation of file at $path succeeded ($backendName)." );
856
857 $size = $this->backend->getFileSize( array( 'src' => $path ) );
858 $time = $this->backend->getFileTimestamp( array( 'src' => $path ) );
859 $stat = $this->backend->getFileStat( array( 'src' => $path ) );
860
861 $this->assertEquals( strlen( $content ), $size,
862 "Correct file size of '$path'" );
863 $this->assertTrue( abs( time() - wfTimestamp( TS_UNIX, $time ) ) < 5,
864 "Correct file timestamp of '$path'" );
865
866 $size = $stat['size'];
867 $time = $stat['mtime'];
868 $this->assertEquals( strlen( $content ), $size,
869 "Correct file size of '$path'" );
870 $this->assertTrue( abs( time() - wfTimestamp( TS_UNIX, $time ) ) < 5,
871 "Correct file timestamp of '$path'" );
872 } else {
873 $size = $this->backend->getFileSize( array( 'src' => $path ) );
874 $time = $this->backend->getFileTimestamp( array( 'src' => $path ) );
875 $stat = $this->backend->getFileStat( array( 'src' => $path ) );
876
877 $this->assertFalse( $size, "Correct file size of '$path'" );
878 $this->assertFalse( $time, "Correct file timestamp of '$path'" );
879 $this->assertFalse( $stat, "Correct file stat of '$path'" );
880 }
881 }
882
883 function provider_testGetFileStat() {
884 $cases = array();
885
886 $base = $this->baseStorePath();
887 $cases[] = array( "$base/unittest-cont1/b/z/some_file.txt", "some file contents", true );
888 $cases[] = array( "$base/unittest-cont1/b/some-other_file.txt", "", true );
889 $cases[] = array( "$base/unittest-cont1/b/some-diff_file.txt", null, false );
890
891 return $cases;
892 }
893
894 /**
895 * @dataProvider provider_testGetFileContents
896 */
897 public function testGetFileContents( $source, $content ) {
898 $this->backend = $this->singleBackend;
899 $this->tearDownFiles();
900 $this->doTestGetFileContents( $source, $content );
901 $this->tearDownFiles();
902
903 $this->backend = $this->multiBackend;
904 $this->tearDownFiles();
905 $this->doTestGetFileContents( $source, $content );
906 $this->tearDownFiles();
907 }
908
909 private function doTestGetFileContents( $source, $content ) {
910 $backendName = $this->backendClass();
911
912 $this->prepare( array( 'dir' => dirname( $source ) ) );
913
914 $status = $this->backend->doOperation(
915 array( 'op' => 'create', 'content' => $content, 'dst' => $source ) );
916 $this->assertGoodStatus( $status,
917 "Creation of file at $source succeeded ($backendName)." );
918 $this->assertEquals( true, $status->isOK(),
919 "Creation of file at $source succeeded with OK status ($backendName)." );
920
921 $newContents = $this->backend->getFileContents( array( 'src' => $source, 'latest' => 1 ) );
922 $this->assertNotEquals( false, $newContents,
923 "Read of file at $source succeeded ($backendName)." );
924
925 $this->assertEquals( $content, $newContents,
926 "Contents read match data at $source ($backendName)." );
927 }
928
929 function provider_testGetFileContents() {
930 $cases = array();
931
932 $base = $this->baseStorePath();
933 $cases[] = array( "$base/unittest-cont1/b/z/some_file.txt", "some file contents" );
934 $cases[] = array( "$base/unittest-cont1/b/some-other_file.txt", "more file contents" );
935
936 return $cases;
937 }
938
939 /**
940 * @dataProvider provider_testGetLocalCopy
941 */
942 public function testGetLocalCopy( $source, $content ) {
943 $this->backend = $this->singleBackend;
944 $this->tearDownFiles();
945 $this->doTestGetLocalCopy( $source, $content );
946 $this->tearDownFiles();
947
948 $this->backend = $this->multiBackend;
949 $this->tearDownFiles();
950 $this->doTestGetLocalCopy( $source, $content );
951 $this->tearDownFiles();
952 }
953
954 private function doTestGetLocalCopy( $source, $content ) {
955 $backendName = $this->backendClass();
956
957 $this->prepare( array( 'dir' => dirname( $source ) ) );
958
959 $status = $this->backend->doOperation(
960 array( 'op' => 'create', 'content' => $content, 'dst' => $source ) );
961 $this->assertGoodStatus( $status,
962 "Creation of file at $source succeeded ($backendName)." );
963
964 $tmpFile = $this->backend->getLocalCopy( array( 'src' => $source ) );
965 $this->assertNotNull( $tmpFile,
966 "Creation of local copy of $source succeeded ($backendName)." );
967
968 $contents = file_get_contents( $tmpFile->getPath() );
969 $this->assertNotEquals( false, $contents, "Local copy of $source exists ($backendName)." );
970 }
971
972 function provider_testGetLocalCopy() {
973 $cases = array();
974
975 $base = $this->baseStorePath();
976 $cases[] = array( "$base/unittest-cont1/a/z/some_file.txt", "some file contents" );
977 $cases[] = array( "$base/unittest-cont1/a/some-other_file.txt", "more file contents" );
978
979 return $cases;
980 }
981
982 /**
983 * @dataProvider provider_testGetLocalReference
984 */
985 public function testGetLocalReference( $source, $content ) {
986 $this->backend = $this->singleBackend;
987 $this->tearDownFiles();
988 $this->doTestGetLocalReference( $source, $content );
989 $this->tearDownFiles();
990
991 $this->backend = $this->multiBackend;
992 $this->tearDownFiles();
993 $this->doTestGetLocalReference( $source, $content );
994 $this->tearDownFiles();
995 }
996
997 private function doTestGetLocalReference( $source, $content ) {
998 $backendName = $this->backendClass();
999
1000 $this->prepare( array( 'dir' => dirname( $source ) ) );
1001
1002 $status = $this->backend->doOperation(
1003 array( 'op' => 'create', 'content' => $content, 'dst' => $source ) );
1004 $this->assertGoodStatus( $status,
1005 "Creation of file at $source succeeded ($backendName)." );
1006
1007 $tmpFile = $this->backend->getLocalReference( array( 'src' => $source ) );
1008 $this->assertNotNull( $tmpFile,
1009 "Creation of local copy of $source succeeded ($backendName)." );
1010
1011 $contents = file_get_contents( $tmpFile->getPath() );
1012 $this->assertNotEquals( false, $contents, "Local copy of $source exists ($backendName)." );
1013 }
1014
1015 function provider_testGetLocalReference() {
1016 $cases = array();
1017
1018 $base = $this->baseStorePath();
1019 $cases[] = array( "$base/unittest-cont1/a/z/some_file.txt", "some file contents" );
1020 $cases[] = array( "$base/unittest-cont1/a/some-other_file.txt", "more file contents" );
1021
1022 return $cases;
1023 }
1024
1025 /**
1026 * @dataProvider provider_testPrepareAndClean
1027 */
1028 public function testPrepareAndClean( $path, $isOK ) {
1029 $this->backend = $this->singleBackend;
1030 $this->doTestPrepareAndClean( $path, $isOK );
1031 $this->tearDownFiles();
1032
1033 $this->backend = $this->multiBackend;
1034 $this->doTestPrepareAndClean( $path, $isOK );
1035 $this->tearDownFiles();
1036 }
1037
1038 function provider_testPrepareAndClean() {
1039 $base = $this->baseStorePath();
1040 return array(
1041 array( "$base/unittest-cont1/a/z/some_file1.txt", true ),
1042 array( "$base/unittest-cont2/a/z/some_file2.txt", true ),
1043 # Specific to FS backend with no basePath field set
1044 #array( "$base/unittest-cont3/a/z/some_file3.txt", false ),
1045 );
1046 }
1047
1048 private function doTestPrepareAndClean( $path, $isOK ) {
1049 $backendName = $this->backendClass();
1050
1051 $status = $this->prepare( array( 'dir' => dirname( $path ) ) );
1052 if ( $isOK ) {
1053 $this->assertGoodStatus( $status,
1054 "Preparing dir $path succeeded without warnings ($backendName)." );
1055 $this->assertEquals( true, $status->isOK(),
1056 "Preparing dir $path succeeded ($backendName)." );
1057 } else {
1058 $this->assertEquals( false, $status->isOK(),
1059 "Preparing dir $path failed ($backendName)." );
1060 }
1061
1062 $status = $this->backend->clean( array( 'dir' => dirname( $path ) ) );
1063 if ( $isOK ) {
1064 $this->assertGoodStatus( $status,
1065 "Cleaning dir $path succeeded without warnings ($backendName)." );
1066 $this->assertEquals( true, $status->isOK(),
1067 "Cleaning dir $path succeeded ($backendName)." );
1068 } else {
1069 $this->assertEquals( false, $status->isOK(),
1070 "Cleaning dir $path failed ($backendName)." );
1071 }
1072 }
1073
1074 public function testRecursiveClean() {
1075 $this->backend = $this->singleBackend;
1076 $this->doTestRecursiveClean();
1077 $this->tearDownFiles();
1078
1079 $this->backend = $this->multiBackend;
1080 $this->doTestRecursiveClean();
1081 $this->tearDownFiles();
1082 }
1083
1084 private function doTestRecursiveClean() {
1085 $backendName = $this->backendClass();
1086
1087 $base = $this->baseStorePath();
1088 $dirs = array(
1089 "$base/unittest-cont1/a",
1090 "$base/unittest-cont1/a/b",
1091 "$base/unittest-cont1/a/b/c",
1092 "$base/unittest-cont1/a/b/c/d0",
1093 "$base/unittest-cont1/a/b/c/d1",
1094 "$base/unittest-cont1/a/b/c/d2",
1095 "$base/unittest-cont1/a/b/c/d0/1",
1096 "$base/unittest-cont1/a/b/c/d0/2",
1097 "$base/unittest-cont1/a/b/c/d1/3",
1098 "$base/unittest-cont1/a/b/c/d1/4",
1099 "$base/unittest-cont1/a/b/c/d2/5",
1100 "$base/unittest-cont1/a/b/c/d2/6"
1101 );
1102 foreach ( $dirs as $dir ) {
1103 $status = $this->prepare( array( 'dir' => $dir ) );
1104 $this->assertGoodStatus( $status,
1105 "Preparing dir $dir succeeded without warnings ($backendName)." );
1106 }
1107
1108 if ( $this->backend instanceof FSFileBackend ) {
1109 foreach ( $dirs as $dir ) {
1110 $this->assertEquals( true, $this->backend->directoryExists( array( 'dir' => $dir ) ),
1111 "Dir $dir exists ($backendName)." );
1112 }
1113 }
1114
1115 $status = $this->backend->clean(
1116 array( 'dir' => "$base/unittest-cont1", 'recursive' => 1 ) );
1117 $this->assertGoodStatus( $status,
1118 "Recursive cleaning of dir $dir succeeded without warnings ($backendName)." );
1119
1120 foreach ( $dirs as $dir ) {
1121 $this->assertEquals( false, $this->backend->directoryExists( array( 'dir' => $dir ) ),
1122 "Dir $dir no longer exists ($backendName)." );
1123 }
1124 }
1125
1126 // @TODO: testSecure
1127
1128 public function testDoOperations() {
1129 $this->backend = $this->singleBackend;
1130 $this->tearDownFiles();
1131 $this->doTestDoOperations();
1132 $this->tearDownFiles();
1133
1134 $this->backend = $this->multiBackend;
1135 $this->tearDownFiles();
1136 $this->doTestDoOperations();
1137 $this->tearDownFiles();
1138
1139 $this->backend = $this->singleBackend;
1140 $this->tearDownFiles();
1141 $this->doTestDoOperations2();
1142 $this->tearDownFiles();
1143
1144 $this->backend = $this->multiBackend;
1145 $this->tearDownFiles();
1146 $this->doTestDoOperations2();
1147 $this->tearDownFiles();
1148
1149 $this->backend = $this->singleBackend;
1150 $this->tearDownFiles();
1151 $this->doTestDoOperationsFailing();
1152 $this->tearDownFiles();
1153
1154 $this->backend = $this->multiBackend;
1155 $this->tearDownFiles();
1156 $this->doTestDoOperationsFailing();
1157 $this->tearDownFiles();
1158 }
1159
1160 private function doTestDoOperations() {
1161 $base = $this->baseStorePath();
1162
1163 $fileA = "$base/unittest-cont1/a/b/fileA.txt";
1164 $fileAContents = '3tqtmoeatmn4wg4qe-mg3qt3 tq';
1165 $fileB = "$base/unittest-cont1/a/b/fileB.txt";
1166 $fileBContents = 'g-jmq3gpqgt3qtg q3GT ';
1167 $fileC = "$base/unittest-cont1/a/b/fileC.txt";
1168 $fileCContents = 'eigna[ogmewt 3qt g3qg flew[ag';
1169 $fileD = "$base/unittest-cont1/a/b/fileD.txt";
1170
1171 $this->prepare( array( 'dir' => dirname( $fileA ) ) );
1172 $this->backend->create( array( 'dst' => $fileA, 'content' => $fileAContents ) );
1173 $this->prepare( array( 'dir' => dirname( $fileB ) ) );
1174 $this->backend->create( array( 'dst' => $fileB, 'content' => $fileBContents ) );
1175 $this->prepare( array( 'dir' => dirname( $fileC ) ) );
1176 $this->backend->create( array( 'dst' => $fileC, 'content' => $fileCContents ) );
1177 $this->prepare( array( 'dir' => dirname( $fileD ) ) );
1178
1179 $status = $this->backend->doOperations( array(
1180 array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC, 'overwrite' => 1 ),
1181 // Now: A:<A>, B:<B>, C:<A>, D:<empty> (file:<orginal contents>)
1182 array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileA, 'overwriteSame' => 1 ),
1183 // Now: A:<A>, B:<B>, C:<A>, D:<empty>
1184 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileD, 'overwrite' => 1 ),
1185 // Now: A:<A>, B:<B>, C:<empty>, D:<A>
1186 array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileC ),
1187 // Now: A:<A>, B:<empty>, C:<B>, D:<A>
1188 array( 'op' => 'move', 'src' => $fileD, 'dst' => $fileA, 'overwriteSame' => 1 ),
1189 // Now: A:<A>, B:<empty>, C:<B>, D:<empty>
1190 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileA, 'overwrite' => 1 ),
1191 // Now: A:<B>, B:<empty>, C:<empty>, D:<empty>
1192 array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC ),
1193 // Now: A:<B>, B:<empty>, C:<B>, D:<empty>
1194 array( 'op' => 'move', 'src' => $fileA, 'dst' => $fileC, 'overwriteSame' => 1 ),
1195 // Now: A:<empty>, B:<empty>, C:<B>, D:<empty>
1196 array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileC, 'overwrite' => 1 ),
1197 // Does nothing
1198 array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileC, 'overwriteSame' => 1 ),
1199 // Does nothing
1200 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileC, 'overwrite' => 1 ),
1201 // Does nothing
1202 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileC, 'overwriteSame' => 1 ),
1203 // Does nothing
1204 array( 'op' => 'null' ),
1205 // Does nothing
1206 ) );
1207
1208 $this->assertGoodStatus( $status, "Operation batch succeeded" );
1209 $this->assertEquals( true, $status->isOK(), "Operation batch succeeded" );
1210 $this->assertEquals( 13, count( $status->success ),
1211 "Operation batch has correct success array" );
1212
1213 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileA ) ),
1214 "File does not exist at $fileA" );
1215 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileB ) ),
1216 "File does not exist at $fileB" );
1217 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileD ) ),
1218 "File does not exist at $fileD" );
1219
1220 $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $fileC ) ),
1221 "File exists at $fileC" );
1222 $this->assertEquals( $fileBContents,
1223 $this->backend->getFileContents( array( 'src' => $fileC ) ),
1224 "Correct file contents of $fileC" );
1225 $this->assertEquals( strlen( $fileBContents ),
1226 $this->backend->getFileSize( array( 'src' => $fileC ) ),
1227 "Correct file size of $fileC" );
1228 $this->assertEquals( wfBaseConvert( sha1( $fileBContents ), 16, 36, 31 ),
1229 $this->backend->getFileSha1Base36( array( 'src' => $fileC ) ),
1230 "Correct file SHA-1 of $fileC" );
1231 }
1232
1233 // concurrency orientated
1234 private function doTestDoOperations2() {
1235 $base = $this->baseStorePath();
1236
1237 $fileAContents = '3tqtmoeatmn4wg4qe-mg3qt3 tq';
1238 $fileBContents = 'g-jmq3gpqgt3qtg q3GT ';
1239 $fileCContents = 'eigna[ogmewt 3qt g3qg flew[ag';
1240
1241 $tmpNameA = TempFSFile::factory( "unittests_", 'txt' )->getPath();
1242 file_put_contents( $tmpNameA, $fileAContents );
1243 $tmpNameB = TempFSFile::factory( "unittests_", 'txt' )->getPath();
1244 file_put_contents( $tmpNameB, $fileBContents );
1245 $tmpNameC = TempFSFile::factory( "unittests_", 'txt' )->getPath();
1246 file_put_contents( $tmpNameC, $fileCContents );
1247
1248 $this->filesToPrune[] = $tmpNameA; # avoid file leaking
1249 $this->filesToPrune[] = $tmpNameB; # avoid file leaking
1250 $this->filesToPrune[] = $tmpNameC; # avoid file leaking
1251
1252 $fileA = "$base/unittest-cont1/a/b/fileA.txt";
1253 $fileB = "$base/unittest-cont1/a/b/fileB.txt";
1254 $fileC = "$base/unittest-cont1/a/b/fileC.txt";
1255 $fileD = "$base/unittest-cont1/a/b/fileD.txt";
1256
1257 $this->prepare( array( 'dir' => dirname( $fileA ) ) );
1258 $this->backend->create( array( 'dst' => $fileA, 'content' => $fileAContents ) );
1259 $this->prepare( array( 'dir' => dirname( $fileB ) ) );
1260 $this->prepare( array( 'dir' => dirname( $fileC ) ) );
1261 $this->prepare( array( 'dir' => dirname( $fileD ) ) );
1262
1263 $status = $this->backend->doOperations( array(
1264 array( 'op' => 'store', 'src' => $tmpNameA, 'dst' => $fileA, 'overwriteSame' => 1 ),
1265 array( 'op' => 'store', 'src' => $tmpNameB, 'dst' => $fileB, 'overwrite' => 1 ),
1266 array( 'op' => 'store', 'src' => $tmpNameC, 'dst' => $fileC, 'overwrite' => 1 ),
1267 array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC, 'overwrite' => 1 ),
1268 // Now: A:<A>, B:<B>, C:<A>, D:<empty> (file:<orginal contents>)
1269 array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileA, 'overwriteSame' => 1 ),
1270 // Now: A:<A>, B:<B>, C:<A>, D:<empty>
1271 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileD, 'overwrite' => 1 ),
1272 // Now: A:<A>, B:<B>, C:<empty>, D:<A>
1273 array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileC ),
1274 // Now: A:<A>, B:<empty>, C:<B>, D:<A>
1275 array( 'op' => 'move', 'src' => $fileD, 'dst' => $fileA, 'overwriteSame' => 1 ),
1276 // Now: A:<A>, B:<empty>, C:<B>, D:<empty>
1277 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileA, 'overwrite' => 1 ),
1278 // Now: A:<B>, B:<empty>, C:<empty>, D:<empty>
1279 array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC ),
1280 // Now: A:<B>, B:<empty>, C:<B>, D:<empty>
1281 array( 'op' => 'move', 'src' => $fileA, 'dst' => $fileC, 'overwriteSame' => 1 ),
1282 // Now: A:<empty>, B:<empty>, C:<B>, D:<empty>
1283 array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileC, 'overwrite' => 1 ),
1284 // Does nothing
1285 array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileC, 'overwriteSame' => 1 ),
1286 // Does nothing
1287 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileC, 'overwrite' => 1 ),
1288 // Does nothing
1289 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileC, 'overwriteSame' => 1 ),
1290 // Does nothing
1291 array( 'op' => 'null' ),
1292 // Does nothing
1293 ) );
1294
1295 $this->assertGoodStatus( $status, "Operation batch succeeded" );
1296 $this->assertEquals( true, $status->isOK(), "Operation batch succeeded" );
1297 $this->assertEquals( 16, count( $status->success ),
1298 "Operation batch has correct success array" );
1299
1300 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileA ) ),
1301 "File does not exist at $fileA" );
1302 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileB ) ),
1303 "File does not exist at $fileB" );
1304 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileD ) ),
1305 "File does not exist at $fileD" );
1306
1307 $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $fileC ) ),
1308 "File exists at $fileC" );
1309 $this->assertEquals( $fileBContents,
1310 $this->backend->getFileContents( array( 'src' => $fileC ) ),
1311 "Correct file contents of $fileC" );
1312 $this->assertEquals( strlen( $fileBContents ),
1313 $this->backend->getFileSize( array( 'src' => $fileC ) ),
1314 "Correct file size of $fileC" );
1315 $this->assertEquals( wfBaseConvert( sha1( $fileBContents ), 16, 36, 31 ),
1316 $this->backend->getFileSha1Base36( array( 'src' => $fileC ) ),
1317 "Correct file SHA-1 of $fileC" );
1318 }
1319
1320 private function doTestDoOperationsFailing() {
1321 $base = $this->baseStorePath();
1322
1323 $fileA = "$base/unittest-cont2/a/b/fileA.txt";
1324 $fileAContents = '3tqtmoeatmn4wg4qe-mg3qt3 tq';
1325 $fileB = "$base/unittest-cont2/a/b/fileB.txt";
1326 $fileBContents = 'g-jmq3gpqgt3qtg q3GT ';
1327 $fileC = "$base/unittest-cont2/a/b/fileC.txt";
1328 $fileCContents = 'eigna[ogmewt 3qt g3qg flew[ag';
1329 $fileD = "$base/unittest-cont2/a/b/fileD.txt";
1330
1331 $this->prepare( array( 'dir' => dirname( $fileA ) ) );
1332 $this->backend->create( array( 'dst' => $fileA, 'content' => $fileAContents ) );
1333 $this->prepare( array( 'dir' => dirname( $fileB ) ) );
1334 $this->backend->create( array( 'dst' => $fileB, 'content' => $fileBContents ) );
1335 $this->prepare( array( 'dir' => dirname( $fileC ) ) );
1336 $this->backend->create( array( 'dst' => $fileC, 'content' => $fileCContents ) );
1337
1338 $status = $this->backend->doOperations( array(
1339 array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC, 'overwrite' => 1 ),
1340 // Now: A:<A>, B:<B>, C:<A>, D:<empty> (file:<orginal contents>)
1341 array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileA, 'overwriteSame' => 1 ),
1342 // Now: A:<A>, B:<B>, C:<A>, D:<empty>
1343 array( 'op' => 'copy', 'src' => $fileB, 'dst' => $fileD, 'overwrite' => 1 ),
1344 // Now: A:<A>, B:<B>, C:<A>, D:<B>
1345 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileD ),
1346 // Now: A:<A>, B:<B>, C:<A>, D:<empty> (failed)
1347 array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileC, 'overwriteSame' => 1 ),
1348 // Now: A:<A>, B:<B>, C:<A>, D:<empty> (failed)
1349 array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileA, 'overwrite' => 1 ),
1350 // Now: A:<B>, B:<empty>, C:<A>, D:<empty>
1351 array( 'op' => 'delete', 'src' => $fileD ),
1352 // Now: A:<B>, B:<empty>, C:<A>, D:<empty>
1353 array( 'op' => 'null' ),
1354 // Does nothing
1355 ), array( 'force' => 1 ) );
1356
1357 $this->assertNotEquals( array(), $status->errors, "Operation had warnings" );
1358 $this->assertEquals( true, $status->isOK(), "Operation batch succeeded" );
1359 $this->assertEquals( 8, count( $status->success ),
1360 "Operation batch has correct success array" );
1361
1362 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileB ) ),
1363 "File does not exist at $fileB" );
1364 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileD ) ),
1365 "File does not exist at $fileD" );
1366
1367 $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $fileA ) ),
1368 "File does not exist at $fileA" );
1369 $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $fileC ) ),
1370 "File exists at $fileC" );
1371 $this->assertEquals( $fileBContents,
1372 $this->backend->getFileContents( array( 'src' => $fileA ) ),
1373 "Correct file contents of $fileA" );
1374 $this->assertEquals( strlen( $fileBContents ),
1375 $this->backend->getFileSize( array( 'src' => $fileA ) ),
1376 "Correct file size of $fileA" );
1377 $this->assertEquals( wfBaseConvert( sha1( $fileBContents ), 16, 36, 31 ),
1378 $this->backend->getFileSha1Base36( array( 'src' => $fileA ) ),
1379 "Correct file SHA-1 of $fileA" );
1380 }
1381
1382 public function testGetFileList() {
1383 $this->backend = $this->singleBackend;
1384 $this->tearDownFiles();
1385 $this->doTestGetFileList();
1386 $this->tearDownFiles();
1387
1388 $this->backend = $this->multiBackend;
1389 $this->tearDownFiles();
1390 $this->doTestGetFileList();
1391 $this->tearDownFiles();
1392 }
1393
1394 private function doTestGetFileList() {
1395 $backendName = $this->backendClass();
1396
1397 $base = $this->baseStorePath();
1398 $files = array(
1399 "$base/unittest-cont1/test1.txt",
1400 "$base/unittest-cont1/test2.txt",
1401 "$base/unittest-cont1/test3.txt",
1402 "$base/unittest-cont1/subdir1/test1.txt",
1403 "$base/unittest-cont1/subdir1/test2.txt",
1404 "$base/unittest-cont1/subdir2/test3.txt",
1405 "$base/unittest-cont1/subdir2/test4.txt",
1406 "$base/unittest-cont1/subdir2/subdir/test1.txt",
1407 "$base/unittest-cont1/subdir2/subdir/test2.txt",
1408 "$base/unittest-cont1/subdir2/subdir/test3.txt",
1409 "$base/unittest-cont1/subdir2/subdir/test4.txt",
1410 "$base/unittest-cont1/subdir2/subdir/test5.txt",
1411 "$base/unittest-cont1/subdir2/subdir/sub/test0.txt",
1412 "$base/unittest-cont1/subdir2/subdir/sub/120-px-file.txt",
1413 );
1414
1415 // Add the files
1416 $ops = array();
1417 foreach ( $files as $file ) {
1418 $this->prepare( array( 'dir' => dirname( $file ) ) );
1419 $ops[] = array( 'op' => 'create', 'content' => 'xxy', 'dst' => $file );
1420 }
1421 $status = $this->backend->doOperations( $ops );
1422 $this->assertGoodStatus( $status,
1423 "Creation of files succeeded ($backendName)." );
1424 $this->assertEquals( true, $status->isOK(),
1425 "Creation of files succeeded with OK status ($backendName)." );
1426
1427 // Expected listing
1428 $expected = array(
1429 "test1.txt",
1430 "test2.txt",
1431 "test3.txt",
1432 "subdir1/test1.txt",
1433 "subdir1/test2.txt",
1434 "subdir2/test3.txt",
1435 "subdir2/test4.txt",
1436 "subdir2/subdir/test1.txt",
1437 "subdir2/subdir/test2.txt",
1438 "subdir2/subdir/test3.txt",
1439 "subdir2/subdir/test4.txt",
1440 "subdir2/subdir/test5.txt",
1441 "subdir2/subdir/sub/test0.txt",
1442 "subdir2/subdir/sub/120-px-file.txt",
1443 );
1444 sort( $expected );
1445
1446 // Actual listing (no trailing slash)
1447 $list = array();
1448 $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1" ) );
1449 foreach ( $iter as $file ) {
1450 $list[] = $file;
1451 }
1452 sort( $list );
1453
1454 $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
1455
1456 // Actual listing (with trailing slash)
1457 $list = array();
1458 $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/" ) );
1459 foreach ( $iter as $file ) {
1460 $list[] = $file;
1461 }
1462 sort( $list );
1463
1464 $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
1465
1466 // Expected listing
1467 $expected = array(
1468 "test1.txt",
1469 "test2.txt",
1470 "test3.txt",
1471 "test4.txt",
1472 "test5.txt",
1473 "sub/test0.txt",
1474 "sub/120-px-file.txt",
1475 );
1476 sort( $expected );
1477
1478 // Actual listing (no trailing slash)
1479 $list = array();
1480 $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/subdir2/subdir" ) );
1481 foreach ( $iter as $file ) {
1482 $list[] = $file;
1483 }
1484 sort( $list );
1485
1486 $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
1487
1488 // Actual listing (with trailing slash)
1489 $list = array();
1490 $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/subdir2/subdir/" ) );
1491 foreach ( $iter as $file ) {
1492 $list[] = $file;
1493 }
1494 sort( $list );
1495
1496 $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
1497
1498 // Actual listing (using iterator second time)
1499 $list = array();
1500 foreach ( $iter as $file ) {
1501 $list[] = $file;
1502 }
1503 sort( $list );
1504
1505 $this->assertEquals( $expected, $list, "Correct file listing ($backendName), second iteration." );
1506
1507 // Expected listing (top files only)
1508 $expected = array(
1509 "test1.txt",
1510 "test2.txt",
1511 "test3.txt",
1512 "test4.txt",
1513 "test5.txt"
1514 );
1515 sort( $expected );
1516
1517 // Actual listing (top files only)
1518 $list = array();
1519 $iter = $this->backend->getTopFileList( array( 'dir' => "$base/unittest-cont1/subdir2/subdir" ) );
1520 foreach ( $iter as $file ) {
1521 $list[] = $file;
1522 }
1523 sort( $list );
1524
1525 $this->assertEquals( $expected, $list, "Correct top file listing ($backendName)." );
1526
1527 foreach ( $files as $file ) { // clean up
1528 $this->backend->doOperation( array( 'op' => 'delete', 'src' => $file ) );
1529 }
1530
1531 $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/not/exists" ) );
1532 foreach ( $iter as $iter ) {} // no errors
1533 }
1534
1535 public function testGetDirectoryList() {
1536 $this->backend = $this->singleBackend;
1537 $this->tearDownFiles();
1538 $this->doTestGetDirectoryList();
1539 $this->tearDownFiles();
1540
1541 $this->backend = $this->multiBackend;
1542 $this->tearDownFiles();
1543 $this->doTestGetDirectoryList();
1544 $this->tearDownFiles();
1545 }
1546
1547 private function doTestGetDirectoryList() {
1548 $backendName = $this->backendClass();
1549
1550 $base = $this->baseStorePath();
1551 $files = array(
1552 "$base/unittest-cont1/test1.txt",
1553 "$base/unittest-cont1/test2.txt",
1554 "$base/unittest-cont1/test3.txt",
1555 "$base/unittest-cont1/subdir1/test1.txt",
1556 "$base/unittest-cont1/subdir1/test2.txt",
1557 "$base/unittest-cont1/subdir2/test3.txt",
1558 "$base/unittest-cont1/subdir2/test4.txt",
1559 "$base/unittest-cont1/subdir2/subdir/test1.txt",
1560 "$base/unittest-cont1/subdir3/subdir/test2.txt",
1561 "$base/unittest-cont1/subdir4/subdir/test3.txt",
1562 "$base/unittest-cont1/subdir4/subdir/test4.txt",
1563 "$base/unittest-cont1/subdir4/subdir/test5.txt",
1564 "$base/unittest-cont1/subdir4/subdir/sub/test0.txt",
1565 "$base/unittest-cont1/subdir4/subdir/sub/120-px-file.txt",
1566 );
1567
1568 // Add the files
1569 $ops = array();
1570 foreach ( $files as $file ) {
1571 $this->prepare( array( 'dir' => dirname( $file ) ) );
1572 $ops[] = array( 'op' => 'create', 'content' => 'xxy', 'dst' => $file );
1573 }
1574 $status = $this->backend->doOperations( $ops );
1575 $this->assertGoodStatus( $status,
1576 "Creation of files succeeded ($backendName)." );
1577 $this->assertEquals( true, $status->isOK(),
1578 "Creation of files succeeded with OK status ($backendName)." );
1579
1580 // Expected listing
1581 $expected = array(
1582 "subdir1",
1583 "subdir2",
1584 "subdir3",
1585 "subdir4",
1586 );
1587 sort( $expected );
1588
1589 $this->assertEquals( true,
1590 $this->backend->directoryExists( array( 'dir' => "$base/unittest-cont1/subdir1" ) ),
1591 "Directory exists in ($backendName)." );
1592 $this->assertEquals( true,
1593 $this->backend->directoryExists( array( 'dir' => "$base/unittest-cont1/subdir2/subdir" ) ),
1594 "Directory exists in ($backendName)." );
1595 $this->assertEquals( false,
1596 $this->backend->directoryExists( array( 'dir' => "$base/unittest-cont1/subdir2/test1.txt" ) ),
1597 "Directory does not exists in ($backendName)." );
1598
1599 // Actual listing (no trailing slash)
1600 $list = array();
1601 $iter = $this->backend->getTopDirectoryList( array( 'dir' => "$base/unittest-cont1" ) );
1602 foreach ( $iter as $file ) {
1603 $list[] = $file;
1604 }
1605 sort( $list );
1606
1607 $this->assertEquals( $expected, $list, "Correct top dir listing ($backendName)." );
1608
1609 // Actual listing (with trailing slash)
1610 $list = array();
1611 $iter = $this->backend->getTopDirectoryList( array( 'dir' => "$base/unittest-cont1/" ) );
1612 foreach ( $iter as $file ) {
1613 $list[] = $file;
1614 }
1615 sort( $list );
1616
1617 $this->assertEquals( $expected, $list, "Correct top dir listing ($backendName)." );
1618
1619 // Expected listing
1620 $expected = array(
1621 "subdir",
1622 );
1623 sort( $expected );
1624
1625 // Actual listing (no trailing slash)
1626 $list = array();
1627 $iter = $this->backend->getTopDirectoryList( array( 'dir' => "$base/unittest-cont1/subdir2" ) );
1628 foreach ( $iter as $file ) {
1629 $list[] = $file;
1630 }
1631 sort( $list );
1632
1633 $this->assertEquals( $expected, $list, "Correct top dir listing ($backendName)." );
1634
1635 // Actual listing (with trailing slash)
1636 $list = array();
1637 $iter = $this->backend->getTopDirectoryList( array( 'dir' => "$base/unittest-cont1/subdir2/" ) );
1638 foreach ( $iter as $file ) {
1639 $list[] = $file;
1640 }
1641 sort( $list );
1642
1643 $this->assertEquals( $expected, $list, "Correct top dir listing ($backendName)." );
1644
1645 // Actual listing (using iterator second time)
1646 $list = array();
1647 foreach ( $iter as $file ) {
1648 $list[] = $file;
1649 }
1650 sort( $list );
1651
1652 $this->assertEquals( $expected, $list, "Correct top dir listing ($backendName), second iteration." );
1653
1654 // Expected listing (recursive)
1655 $expected = array(
1656 "subdir1",
1657 "subdir2",
1658 "subdir3",
1659 "subdir4",
1660 "subdir2/subdir",
1661 "subdir3/subdir",
1662 "subdir4/subdir",
1663 "subdir4/subdir/sub",
1664 );
1665 sort( $expected );
1666
1667 // Actual listing (recursive)
1668 $list = array();
1669 $iter = $this->backend->getDirectoryList( array( 'dir' => "$base/unittest-cont1/" ) );
1670 foreach ( $iter as $file ) {
1671 $list[] = $file;
1672 }
1673 sort( $list );
1674
1675 $this->assertEquals( $expected, $list, "Correct dir listing ($backendName)." );
1676
1677 // Expected listing (recursive)
1678 $expected = array(
1679 "subdir",
1680 "subdir/sub",
1681 );
1682 sort( $expected );
1683
1684 // Actual listing (recursive)
1685 $list = array();
1686 $iter = $this->backend->getDirectoryList( array( 'dir' => "$base/unittest-cont1/subdir4" ) );
1687 foreach ( $iter as $file ) {
1688 $list[] = $file;
1689 }
1690 sort( $list );
1691
1692 $this->assertEquals( $expected, $list, "Correct dir listing ($backendName)." );
1693
1694 // Actual listing (recursive, second time)
1695 $list = array();
1696 foreach ( $iter as $file ) {
1697 $list[] = $file;
1698 }
1699 sort( $list );
1700
1701 $this->assertEquals( $expected, $list, "Correct dir listing ($backendName)." );
1702
1703 foreach ( $files as $file ) { // clean up
1704 $this->backend->doOperation( array( 'op' => 'delete', 'src' => $file ) );
1705 }
1706
1707 $iter = $this->backend->getDirectoryList( array( 'dir' => "$base/unittest-cont1/not/exists" ) );
1708 foreach ( $iter as $iter ) {} // no errors
1709 }
1710
1711 public function testLockCalls() {
1712 $this->backend = $this->singleBackend;
1713 $this->doTestLockCalls();
1714 }
1715
1716 private function doTestLockCalls() {
1717 $backendName = $this->backendClass();
1718
1719 for ( $i=0; $i<50; $i++ ) {
1720 $paths = array(
1721 "test1.txt",
1722 "test2.txt",
1723 "test3.txt",
1724 "subdir1",
1725 "subdir1", // duplicate
1726 "subdir1/test1.txt",
1727 "subdir1/test2.txt",
1728 "subdir2",
1729 "subdir2", // duplicate
1730 "subdir2/test3.txt",
1731 "subdir2/test4.txt",
1732 "subdir2/subdir",
1733 "subdir2/subdir/test1.txt",
1734 "subdir2/subdir/test2.txt",
1735 "subdir2/subdir/test3.txt",
1736 "subdir2/subdir/test4.txt",
1737 "subdir2/subdir/test5.txt",
1738 "subdir2/subdir/sub",
1739 "subdir2/subdir/sub/test0.txt",
1740 "subdir2/subdir/sub/120-px-file.txt",
1741 );
1742
1743 $status = $this->backend->lockFiles( $paths, LockManager::LOCK_EX );
1744 $this->assertEquals( array(), $status->errors,
1745 "Locking of files succeeded ($backendName)." );
1746 $this->assertEquals( true, $status->isOK(),
1747 "Locking of files succeeded with OK status ($backendName)." );
1748
1749 $status = $this->backend->lockFiles( $paths, LockManager::LOCK_SH );
1750 $this->assertEquals( array(), $status->errors,
1751 "Locking of files succeeded ($backendName)." );
1752 $this->assertEquals( true, $status->isOK(),
1753 "Locking of files succeeded with OK status ($backendName)." );
1754
1755 $status = $this->backend->unlockFiles( $paths, LockManager::LOCK_SH );
1756 $this->assertEquals( array(), $status->errors,
1757 "Locking of files succeeded ($backendName)." );
1758 $this->assertEquals( true, $status->isOK(),
1759 "Locking of files succeeded with OK status ($backendName)." );
1760
1761 $status = $this->backend->unlockFiles( $paths, LockManager::LOCK_EX );
1762 $this->assertEquals( array(), $status->errors,
1763 "Locking of files succeeded ($backendName)." );
1764 $this->assertEquals( true, $status->isOK(),
1765 "Locking of files succeeded with OK status ($backendName)." );
1766 }
1767 }
1768
1769 // test helper wrapper for backend prepare() function
1770 private function prepare( array $params ) {
1771 return $this->backend->prepare( $params );
1772 }
1773
1774 function tearDownFiles() {
1775 foreach ( $this->filesToPrune as $file ) {
1776 @unlink( $file );
1777 }
1778 $containers = array( 'unittest-cont1', 'unittest-cont2', 'unittest-cont3' );
1779 foreach ( $containers as $container ) {
1780 $this->deleteFiles( $container );
1781 }
1782 $this->filesToPrune = array();
1783 }
1784
1785 private function deleteFiles( $container ) {
1786 $base = $this->baseStorePath();
1787 $iter = $this->backend->getFileList( array( 'dir' => "$base/$container" ) );
1788 if ( $iter ) {
1789 foreach ( $iter as $file ) {
1790 $this->backend->delete( array( 'src' => "$base/$container/$file" ),
1791 array( 'force' => 1, 'nonLocking' => 1 ) );
1792 }
1793 }
1794 $this->backend->clean( array( 'dir' => "$base/$container", 'recursive' => 1 ) );
1795 }
1796
1797 function assertGoodStatus( $status, $msg ) {
1798 $this->assertEquals( print_r( array(), 1 ), print_r( $status->errors, 1 ), $msg );
1799 }
1800
1801 function tearDown() {
1802 parent::tearDown();
1803 }
1804 }