Merge "Revert "Adding sanity check to Title::isRedirect().""
[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->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 ) ) < 10,
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 ) ) < 10,
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->create( array( 'content' => $content, 'dst' => $source ) );
1003 $this->assertGoodStatus( $status,
1004 "Creation of file at $source succeeded ($backendName)." );
1005
1006 $tmpFile = $this->backend->getLocalReference( array( 'src' => $source ) );
1007 $this->assertNotNull( $tmpFile,
1008 "Creation of local copy of $source succeeded ($backendName)." );
1009
1010 $contents = file_get_contents( $tmpFile->getPath() );
1011 $this->assertNotEquals( false, $contents, "Local copy of $source exists ($backendName)." );
1012 }
1013
1014 function provider_testGetLocalReference() {
1015 $cases = array();
1016
1017 $base = $this->baseStorePath();
1018 $cases[] = array( "$base/unittest-cont1/a/z/some_file.txt", "some file contents" );
1019 $cases[] = array( "$base/unittest-cont1/a/some-other_file.txt", "more file contents" );
1020
1021 return $cases;
1022 }
1023
1024 /**
1025 * @dataProvider provider_testPrepareAndClean
1026 */
1027 public function testPrepareAndClean( $path, $isOK ) {
1028 $this->backend = $this->singleBackend;
1029 $this->doTestPrepareAndClean( $path, $isOK );
1030 $this->tearDownFiles();
1031
1032 $this->backend = $this->multiBackend;
1033 $this->doTestPrepareAndClean( $path, $isOK );
1034 $this->tearDownFiles();
1035 }
1036
1037 function provider_testPrepareAndClean() {
1038 $base = $this->baseStorePath();
1039 return array(
1040 array( "$base/unittest-cont1/a/z/some_file1.txt", true ),
1041 array( "$base/unittest-cont2/a/z/some_file2.txt", true ),
1042 # Specific to FS backend with no basePath field set
1043 #array( "$base/unittest-cont3/a/z/some_file3.txt", false ),
1044 );
1045 }
1046
1047 private function doTestPrepareAndClean( $path, $isOK ) {
1048 $backendName = $this->backendClass();
1049
1050 $status = $this->prepare( array( 'dir' => dirname( $path ) ) );
1051 if ( $isOK ) {
1052 $this->assertGoodStatus( $status,
1053 "Preparing dir $path succeeded without warnings ($backendName)." );
1054 $this->assertEquals( true, $status->isOK(),
1055 "Preparing dir $path succeeded ($backendName)." );
1056 } else {
1057 $this->assertEquals( false, $status->isOK(),
1058 "Preparing dir $path failed ($backendName)." );
1059 }
1060
1061 $status = $this->backend->clean( array( 'dir' => dirname( $path ) ) );
1062 if ( $isOK ) {
1063 $this->assertGoodStatus( $status,
1064 "Cleaning dir $path succeeded without warnings ($backendName)." );
1065 $this->assertEquals( true, $status->isOK(),
1066 "Cleaning dir $path succeeded ($backendName)." );
1067 } else {
1068 $this->assertEquals( false, $status->isOK(),
1069 "Cleaning dir $path failed ($backendName)." );
1070 }
1071 }
1072
1073 public function testRecursiveClean() {
1074 $this->backend = $this->singleBackend;
1075 $this->doTestRecursiveClean();
1076 $this->tearDownFiles();
1077
1078 $this->backend = $this->multiBackend;
1079 $this->doTestRecursiveClean();
1080 $this->tearDownFiles();
1081 }
1082
1083 private function doTestRecursiveClean() {
1084 $backendName = $this->backendClass();
1085
1086 $base = $this->baseStorePath();
1087 $dirs = array(
1088 "$base/unittest-cont1/a",
1089 "$base/unittest-cont1/a/b",
1090 "$base/unittest-cont1/a/b/c",
1091 "$base/unittest-cont1/a/b/c/d0",
1092 "$base/unittest-cont1/a/b/c/d1",
1093 "$base/unittest-cont1/a/b/c/d2",
1094 "$base/unittest-cont1/a/b/c/d0/1",
1095 "$base/unittest-cont1/a/b/c/d0/2",
1096 "$base/unittest-cont1/a/b/c/d1/3",
1097 "$base/unittest-cont1/a/b/c/d1/4",
1098 "$base/unittest-cont1/a/b/c/d2/5",
1099 "$base/unittest-cont1/a/b/c/d2/6"
1100 );
1101 foreach ( $dirs as $dir ) {
1102 $status = $this->prepare( array( 'dir' => $dir ) );
1103 $this->assertGoodStatus( $status,
1104 "Preparing dir $dir succeeded without warnings ($backendName)." );
1105 }
1106
1107 if ( $this->backend instanceof FSFileBackend ) {
1108 foreach ( $dirs as $dir ) {
1109 $this->assertEquals( true, $this->backend->directoryExists( array( 'dir' => $dir ) ),
1110 "Dir $dir exists ($backendName)." );
1111 }
1112 }
1113
1114 $status = $this->backend->clean(
1115 array( 'dir' => "$base/unittest-cont1", 'recursive' => 1 ) );
1116 $this->assertGoodStatus( $status,
1117 "Recursive cleaning of dir $dir succeeded without warnings ($backendName)." );
1118
1119 foreach ( $dirs as $dir ) {
1120 $this->assertEquals( false, $this->backend->directoryExists( array( 'dir' => $dir ) ),
1121 "Dir $dir no longer exists ($backendName)." );
1122 }
1123 }
1124
1125 // @TODO: testSecure
1126
1127 public function testDoOperations() {
1128 $this->backend = $this->singleBackend;
1129 $this->tearDownFiles();
1130 $this->doTestDoOperations();
1131 $this->tearDownFiles();
1132
1133 $this->backend = $this->multiBackend;
1134 $this->tearDownFiles();
1135 $this->doTestDoOperations();
1136 $this->tearDownFiles();
1137
1138 $this->backend = $this->singleBackend;
1139 $this->tearDownFiles();
1140 $this->doTestDoOperations2();
1141 $this->tearDownFiles();
1142
1143 $this->backend = $this->multiBackend;
1144 $this->tearDownFiles();
1145 $this->doTestDoOperations2();
1146 $this->tearDownFiles();
1147
1148 $this->backend = $this->singleBackend;
1149 $this->tearDownFiles();
1150 $this->doTestDoOperationsFailing();
1151 $this->tearDownFiles();
1152
1153 $this->backend = $this->multiBackend;
1154 $this->tearDownFiles();
1155 $this->doTestDoOperationsFailing();
1156 $this->tearDownFiles();
1157 }
1158
1159 private function doTestDoOperations() {
1160 $base = $this->baseStorePath();
1161
1162 $fileA = "$base/unittest-cont1/a/b/fileA.txt";
1163 $fileAContents = '3tqtmoeatmn4wg4qe-mg3qt3 tq';
1164 $fileB = "$base/unittest-cont1/a/b/fileB.txt";
1165 $fileBContents = 'g-jmq3gpqgt3qtg q3GT ';
1166 $fileC = "$base/unittest-cont1/a/b/fileC.txt";
1167 $fileCContents = 'eigna[ogmewt 3qt g3qg flew[ag';
1168 $fileD = "$base/unittest-cont1/a/b/fileD.txt";
1169
1170 $this->prepare( array( 'dir' => dirname( $fileA ) ) );
1171 $this->create( array( 'dst' => $fileA, 'content' => $fileAContents ) );
1172 $this->prepare( array( 'dir' => dirname( $fileB ) ) );
1173 $this->create( array( 'dst' => $fileB, 'content' => $fileBContents ) );
1174 $this->prepare( array( 'dir' => dirname( $fileC ) ) );
1175 $this->create( array( 'dst' => $fileC, 'content' => $fileCContents ) );
1176 $this->prepare( array( 'dir' => dirname( $fileD ) ) );
1177
1178 $status = $this->backend->doOperations( array(
1179 array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC, 'overwrite' => 1 ),
1180 // Now: A:<A>, B:<B>, C:<A>, D:<empty> (file:<orginal contents>)
1181 array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileA, 'overwriteSame' => 1 ),
1182 // Now: A:<A>, B:<B>, C:<A>, D:<empty>
1183 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileD, 'overwrite' => 1 ),
1184 // Now: A:<A>, B:<B>, C:<empty>, D:<A>
1185 array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileC ),
1186 // Now: A:<A>, B:<empty>, C:<B>, D:<A>
1187 array( 'op' => 'move', 'src' => $fileD, 'dst' => $fileA, 'overwriteSame' => 1 ),
1188 // Now: A:<A>, B:<empty>, C:<B>, D:<empty>
1189 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileA, 'overwrite' => 1 ),
1190 // Now: A:<B>, B:<empty>, C:<empty>, D:<empty>
1191 array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC ),
1192 // Now: A:<B>, B:<empty>, C:<B>, D:<empty>
1193 array( 'op' => 'move', 'src' => $fileA, 'dst' => $fileC, 'overwriteSame' => 1 ),
1194 // Now: A:<empty>, B:<empty>, C:<B>, D:<empty>
1195 array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileC, 'overwrite' => 1 ),
1196 // Does nothing
1197 array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileC, 'overwriteSame' => 1 ),
1198 // Does nothing
1199 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileC, 'overwrite' => 1 ),
1200 // Does nothing
1201 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileC, 'overwriteSame' => 1 ),
1202 // Does nothing
1203 array( 'op' => 'null' ),
1204 // Does nothing
1205 ) );
1206
1207 $this->assertGoodStatus( $status, "Operation batch succeeded" );
1208 $this->assertEquals( true, $status->isOK(), "Operation batch succeeded" );
1209 $this->assertEquals( 13, count( $status->success ),
1210 "Operation batch has correct success array" );
1211
1212 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileA ) ),
1213 "File does not exist at $fileA" );
1214 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileB ) ),
1215 "File does not exist at $fileB" );
1216 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileD ) ),
1217 "File does not exist at $fileD" );
1218
1219 $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $fileC ) ),
1220 "File exists at $fileC" );
1221 $this->assertEquals( $fileBContents,
1222 $this->backend->getFileContents( array( 'src' => $fileC ) ),
1223 "Correct file contents of $fileC" );
1224 $this->assertEquals( strlen( $fileBContents ),
1225 $this->backend->getFileSize( array( 'src' => $fileC ) ),
1226 "Correct file size of $fileC" );
1227 $this->assertEquals( wfBaseConvert( sha1( $fileBContents ), 16, 36, 31 ),
1228 $this->backend->getFileSha1Base36( array( 'src' => $fileC ) ),
1229 "Correct file SHA-1 of $fileC" );
1230 }
1231
1232 // concurrency orientated
1233 private function doTestDoOperations2() {
1234 $base = $this->baseStorePath();
1235
1236 $fileAContents = '3tqtmoeatmn4wg4qe-mg3qt3 tq';
1237 $fileBContents = 'g-jmq3gpqgt3qtg q3GT ';
1238 $fileCContents = 'eigna[ogmewt 3qt g3qg flew[ag';
1239
1240 $tmpNameA = TempFSFile::factory( "unittests_", 'txt' )->getPath();
1241 file_put_contents( $tmpNameA, $fileAContents );
1242 $tmpNameB = TempFSFile::factory( "unittests_", 'txt' )->getPath();
1243 file_put_contents( $tmpNameB, $fileBContents );
1244 $tmpNameC = TempFSFile::factory( "unittests_", 'txt' )->getPath();
1245 file_put_contents( $tmpNameC, $fileCContents );
1246
1247 $this->filesToPrune[] = $tmpNameA; # avoid file leaking
1248 $this->filesToPrune[] = $tmpNameB; # avoid file leaking
1249 $this->filesToPrune[] = $tmpNameC; # avoid file leaking
1250
1251 $fileA = "$base/unittest-cont1/a/b/fileA.txt";
1252 $fileB = "$base/unittest-cont1/a/b/fileB.txt";
1253 $fileC = "$base/unittest-cont1/a/b/fileC.txt";
1254 $fileD = "$base/unittest-cont1/a/b/fileD.txt";
1255
1256 $this->prepare( array( 'dir' => dirname( $fileA ) ) );
1257 $this->create( array( 'dst' => $fileA, 'content' => $fileAContents ) );
1258 $this->prepare( array( 'dir' => dirname( $fileB ) ) );
1259 $this->prepare( array( 'dir' => dirname( $fileC ) ) );
1260 $this->prepare( array( 'dir' => dirname( $fileD ) ) );
1261
1262 $status = $this->backend->doOperations( array(
1263 array( 'op' => 'store', 'src' => $tmpNameA, 'dst' => $fileA, 'overwriteSame' => 1 ),
1264 array( 'op' => 'store', 'src' => $tmpNameB, 'dst' => $fileB, 'overwrite' => 1 ),
1265 array( 'op' => 'store', 'src' => $tmpNameC, 'dst' => $fileC, 'overwrite' => 1 ),
1266 array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC, 'overwrite' => 1 ),
1267 // Now: A:<A>, B:<B>, C:<A>, D:<empty> (file:<orginal contents>)
1268 array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileA, 'overwriteSame' => 1 ),
1269 // Now: A:<A>, B:<B>, C:<A>, D:<empty>
1270 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileD, 'overwrite' => 1 ),
1271 // Now: A:<A>, B:<B>, C:<empty>, D:<A>
1272 array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileC ),
1273 // Now: A:<A>, B:<empty>, C:<B>, D:<A>
1274 array( 'op' => 'move', 'src' => $fileD, 'dst' => $fileA, 'overwriteSame' => 1 ),
1275 // Now: A:<A>, B:<empty>, C:<B>, D:<empty>
1276 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileA, 'overwrite' => 1 ),
1277 // Now: A:<B>, B:<empty>, C:<empty>, D:<empty>
1278 array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC ),
1279 // Now: A:<B>, B:<empty>, C:<B>, D:<empty>
1280 array( 'op' => 'move', 'src' => $fileA, 'dst' => $fileC, 'overwriteSame' => 1 ),
1281 // Now: A:<empty>, B:<empty>, C:<B>, D:<empty>
1282 array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileC, 'overwrite' => 1 ),
1283 // Does nothing
1284 array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileC, 'overwriteSame' => 1 ),
1285 // Does nothing
1286 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileC, 'overwrite' => 1 ),
1287 // Does nothing
1288 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileC, 'overwriteSame' => 1 ),
1289 // Does nothing
1290 array( 'op' => 'null' ),
1291 // Does nothing
1292 ) );
1293
1294 $this->assertGoodStatus( $status, "Operation batch succeeded" );
1295 $this->assertEquals( true, $status->isOK(), "Operation batch succeeded" );
1296 $this->assertEquals( 16, count( $status->success ),
1297 "Operation batch has correct success array" );
1298
1299 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileA ) ),
1300 "File does not exist at $fileA" );
1301 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileB ) ),
1302 "File does not exist at $fileB" );
1303 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileD ) ),
1304 "File does not exist at $fileD" );
1305
1306 $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $fileC ) ),
1307 "File exists at $fileC" );
1308 $this->assertEquals( $fileBContents,
1309 $this->backend->getFileContents( array( 'src' => $fileC ) ),
1310 "Correct file contents of $fileC" );
1311 $this->assertEquals( strlen( $fileBContents ),
1312 $this->backend->getFileSize( array( 'src' => $fileC ) ),
1313 "Correct file size of $fileC" );
1314 $this->assertEquals( wfBaseConvert( sha1( $fileBContents ), 16, 36, 31 ),
1315 $this->backend->getFileSha1Base36( array( 'src' => $fileC ) ),
1316 "Correct file SHA-1 of $fileC" );
1317 }
1318
1319 private function doTestDoOperationsFailing() {
1320 $base = $this->baseStorePath();
1321
1322 $fileA = "$base/unittest-cont2/a/b/fileA.txt";
1323 $fileAContents = '3tqtmoeatmn4wg4qe-mg3qt3 tq';
1324 $fileB = "$base/unittest-cont2/a/b/fileB.txt";
1325 $fileBContents = 'g-jmq3gpqgt3qtg q3GT ';
1326 $fileC = "$base/unittest-cont2/a/b/fileC.txt";
1327 $fileCContents = 'eigna[ogmewt 3qt g3qg flew[ag';
1328 $fileD = "$base/unittest-cont2/a/b/fileD.txt";
1329
1330 $this->prepare( array( 'dir' => dirname( $fileA ) ) );
1331 $this->create( array( 'dst' => $fileA, 'content' => $fileAContents ) );
1332 $this->prepare( array( 'dir' => dirname( $fileB ) ) );
1333 $this->create( array( 'dst' => $fileB, 'content' => $fileBContents ) );
1334 $this->prepare( array( 'dir' => dirname( $fileC ) ) );
1335 $this->create( array( 'dst' => $fileC, 'content' => $fileCContents ) );
1336
1337 $status = $this->backend->doOperations( array(
1338 array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC, 'overwrite' => 1 ),
1339 // Now: A:<A>, B:<B>, C:<A>, D:<empty> (file:<orginal contents>)
1340 array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileA, 'overwriteSame' => 1 ),
1341 // Now: A:<A>, B:<B>, C:<A>, D:<empty>
1342 array( 'op' => 'copy', 'src' => $fileB, 'dst' => $fileD, 'overwrite' => 1 ),
1343 // Now: A:<A>, B:<B>, C:<A>, D:<B>
1344 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileD ),
1345 // Now: A:<A>, B:<B>, C:<A>, D:<empty> (failed)
1346 array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileC, 'overwriteSame' => 1 ),
1347 // Now: A:<A>, B:<B>, C:<A>, D:<empty> (failed)
1348 array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileA, 'overwrite' => 1 ),
1349 // Now: A:<B>, B:<empty>, C:<A>, D:<empty>
1350 array( 'op' => 'delete', 'src' => $fileD ),
1351 // Now: A:<B>, B:<empty>, C:<A>, D:<empty>
1352 array( 'op' => 'null' ),
1353 // Does nothing
1354 ), array( 'force' => 1 ) );
1355
1356 $this->assertNotEquals( array(), $status->errors, "Operation had warnings" );
1357 $this->assertEquals( true, $status->isOK(), "Operation batch succeeded" );
1358 $this->assertEquals( 8, count( $status->success ),
1359 "Operation batch has correct success array" );
1360
1361 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileB ) ),
1362 "File does not exist at $fileB" );
1363 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileD ) ),
1364 "File does not exist at $fileD" );
1365
1366 $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $fileA ) ),
1367 "File does not exist at $fileA" );
1368 $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $fileC ) ),
1369 "File exists at $fileC" );
1370 $this->assertEquals( $fileBContents,
1371 $this->backend->getFileContents( array( 'src' => $fileA ) ),
1372 "Correct file contents of $fileA" );
1373 $this->assertEquals( strlen( $fileBContents ),
1374 $this->backend->getFileSize( array( 'src' => $fileA ) ),
1375 "Correct file size of $fileA" );
1376 $this->assertEquals( wfBaseConvert( sha1( $fileBContents ), 16, 36, 31 ),
1377 $this->backend->getFileSha1Base36( array( 'src' => $fileA ) ),
1378 "Correct file SHA-1 of $fileA" );
1379 }
1380
1381 public function testGetFileList() {
1382 $this->backend = $this->singleBackend;
1383 $this->tearDownFiles();
1384 $this->doTestGetFileList();
1385 $this->tearDownFiles();
1386
1387 $this->backend = $this->multiBackend;
1388 $this->tearDownFiles();
1389 $this->doTestGetFileList();
1390 $this->tearDownFiles();
1391 }
1392
1393 private function doTestGetFileList() {
1394 $backendName = $this->backendClass();
1395
1396 $base = $this->baseStorePath();
1397 $files = array(
1398 "$base/unittest-cont1/test1.txt",
1399 "$base/unittest-cont1/test2.txt",
1400 "$base/unittest-cont1/test3.txt",
1401 "$base/unittest-cont1/subdir1/test1.txt",
1402 "$base/unittest-cont1/subdir1/test2.txt",
1403 "$base/unittest-cont1/subdir2/test3.txt",
1404 "$base/unittest-cont1/subdir2/test4.txt",
1405 "$base/unittest-cont1/subdir2/subdir/test1.txt",
1406 "$base/unittest-cont1/subdir2/subdir/test2.txt",
1407 "$base/unittest-cont1/subdir2/subdir/test3.txt",
1408 "$base/unittest-cont1/subdir2/subdir/test4.txt",
1409 "$base/unittest-cont1/subdir2/subdir/test5.txt",
1410 "$base/unittest-cont1/subdir2/subdir/sub/test0.txt",
1411 "$base/unittest-cont1/subdir2/subdir/sub/120-px-file.txt",
1412 );
1413
1414 // Add the files
1415 $ops = array();
1416 foreach ( $files as $file ) {
1417 $this->prepare( array( 'dir' => dirname( $file ) ) );
1418 $ops[] = array( 'op' => 'create', 'content' => 'xxy', 'dst' => $file );
1419 }
1420 $status = $this->backend->doQuickOperations( $ops );
1421 $this->assertGoodStatus( $status,
1422 "Creation of files succeeded ($backendName)." );
1423 $this->assertEquals( true, $status->isOK(),
1424 "Creation of files succeeded with OK status ($backendName)." );
1425
1426 // Expected listing
1427 $expected = array(
1428 "test1.txt",
1429 "test2.txt",
1430 "test3.txt",
1431 "subdir1/test1.txt",
1432 "subdir1/test2.txt",
1433 "subdir2/test3.txt",
1434 "subdir2/test4.txt",
1435 "subdir2/subdir/test1.txt",
1436 "subdir2/subdir/test2.txt",
1437 "subdir2/subdir/test3.txt",
1438 "subdir2/subdir/test4.txt",
1439 "subdir2/subdir/test5.txt",
1440 "subdir2/subdir/sub/test0.txt",
1441 "subdir2/subdir/sub/120-px-file.txt",
1442 );
1443 sort( $expected );
1444
1445 // Actual listing (no trailing slash)
1446 $list = array();
1447 $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1" ) );
1448 foreach ( $iter as $file ) {
1449 $list[] = $file;
1450 }
1451 sort( $list );
1452
1453 $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
1454
1455 // Actual listing (with trailing slash)
1456 $list = array();
1457 $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/" ) );
1458 foreach ( $iter as $file ) {
1459 $list[] = $file;
1460 }
1461 sort( $list );
1462
1463 $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
1464
1465 // Expected listing
1466 $expected = array(
1467 "test1.txt",
1468 "test2.txt",
1469 "test3.txt",
1470 "test4.txt",
1471 "test5.txt",
1472 "sub/test0.txt",
1473 "sub/120-px-file.txt",
1474 );
1475 sort( $expected );
1476
1477 // Actual listing (no trailing slash)
1478 $list = array();
1479 $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/subdir2/subdir" ) );
1480 foreach ( $iter as $file ) {
1481 $list[] = $file;
1482 }
1483 sort( $list );
1484
1485 $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
1486
1487 // Actual listing (with trailing slash)
1488 $list = array();
1489 $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/subdir2/subdir/" ) );
1490 foreach ( $iter as $file ) {
1491 $list[] = $file;
1492 }
1493 sort( $list );
1494
1495 $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
1496
1497 // Actual listing (using iterator second time)
1498 $list = array();
1499 foreach ( $iter as $file ) {
1500 $list[] = $file;
1501 }
1502 sort( $list );
1503
1504 $this->assertEquals( $expected, $list, "Correct file listing ($backendName), second iteration." );
1505
1506 // Expected listing (top files only)
1507 $expected = array(
1508 "test1.txt",
1509 "test2.txt",
1510 "test3.txt",
1511 "test4.txt",
1512 "test5.txt"
1513 );
1514 sort( $expected );
1515
1516 // Actual listing (top files only)
1517 $list = array();
1518 $iter = $this->backend->getTopFileList( array( 'dir' => "$base/unittest-cont1/subdir2/subdir" ) );
1519 foreach ( $iter as $file ) {
1520 $list[] = $file;
1521 }
1522 sort( $list );
1523
1524 $this->assertEquals( $expected, $list, "Correct top file listing ($backendName)." );
1525
1526 foreach ( $files as $file ) { // clean up
1527 $this->backend->doOperation( array( 'op' => 'delete', 'src' => $file ) );
1528 }
1529
1530 $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/not/exists" ) );
1531 foreach ( $iter as $iter ) {} // no errors
1532 }
1533
1534 public function testGetDirectoryList() {
1535 $this->backend = $this->singleBackend;
1536 $this->tearDownFiles();
1537 $this->doTestGetDirectoryList();
1538 $this->tearDownFiles();
1539
1540 $this->backend = $this->multiBackend;
1541 $this->tearDownFiles();
1542 $this->doTestGetDirectoryList();
1543 $this->tearDownFiles();
1544 }
1545
1546 private function doTestGetDirectoryList() {
1547 $backendName = $this->backendClass();
1548
1549 $base = $this->baseStorePath();
1550 $files = array(
1551 "$base/unittest-cont1/test1.txt",
1552 "$base/unittest-cont1/test2.txt",
1553 "$base/unittest-cont1/test3.txt",
1554 "$base/unittest-cont1/subdir1/test1.txt",
1555 "$base/unittest-cont1/subdir1/test2.txt",
1556 "$base/unittest-cont1/subdir2/test3.txt",
1557 "$base/unittest-cont1/subdir2/test4.txt",
1558 "$base/unittest-cont1/subdir2/subdir/test1.txt",
1559 "$base/unittest-cont1/subdir3/subdir/test2.txt",
1560 "$base/unittest-cont1/subdir4/subdir/test3.txt",
1561 "$base/unittest-cont1/subdir4/subdir/test4.txt",
1562 "$base/unittest-cont1/subdir4/subdir/test5.txt",
1563 "$base/unittest-cont1/subdir4/subdir/sub/test0.txt",
1564 "$base/unittest-cont1/subdir4/subdir/sub/120-px-file.txt",
1565 );
1566
1567 // Add the files
1568 $ops = array();
1569 foreach ( $files as $file ) {
1570 $this->prepare( array( 'dir' => dirname( $file ) ) );
1571 $ops[] = array( 'op' => 'create', 'content' => 'xxy', 'dst' => $file );
1572 }
1573 $status = $this->backend->doQuickOperations( $ops );
1574 $this->assertGoodStatus( $status,
1575 "Creation of files succeeded ($backendName)." );
1576 $this->assertEquals( true, $status->isOK(),
1577 "Creation of files succeeded with OK status ($backendName)." );
1578
1579 // Expected listing
1580 $expected = array(
1581 "subdir1",
1582 "subdir2",
1583 "subdir3",
1584 "subdir4",
1585 );
1586 sort( $expected );
1587
1588 $this->assertEquals( true,
1589 $this->backend->directoryExists( array( 'dir' => "$base/unittest-cont1/subdir1" ) ),
1590 "Directory exists in ($backendName)." );
1591 $this->assertEquals( true,
1592 $this->backend->directoryExists( array( 'dir' => "$base/unittest-cont1/subdir2/subdir" ) ),
1593 "Directory exists in ($backendName)." );
1594 $this->assertEquals( false,
1595 $this->backend->directoryExists( array( 'dir' => "$base/unittest-cont1/subdir2/test1.txt" ) ),
1596 "Directory does not exists in ($backendName)." );
1597
1598 // Actual listing (no trailing slash)
1599 $list = array();
1600 $iter = $this->backend->getTopDirectoryList( array( 'dir' => "$base/unittest-cont1" ) );
1601 foreach ( $iter as $file ) {
1602 $list[] = $file;
1603 }
1604 sort( $list );
1605
1606 $this->assertEquals( $expected, $list, "Correct top dir listing ($backendName)." );
1607
1608 // Actual listing (with trailing slash)
1609 $list = array();
1610 $iter = $this->backend->getTopDirectoryList( array( 'dir' => "$base/unittest-cont1/" ) );
1611 foreach ( $iter as $file ) {
1612 $list[] = $file;
1613 }
1614 sort( $list );
1615
1616 $this->assertEquals( $expected, $list, "Correct top dir listing ($backendName)." );
1617
1618 // Expected listing
1619 $expected = array(
1620 "subdir",
1621 );
1622 sort( $expected );
1623
1624 // Actual listing (no trailing slash)
1625 $list = array();
1626 $iter = $this->backend->getTopDirectoryList( array( 'dir' => "$base/unittest-cont1/subdir2" ) );
1627 foreach ( $iter as $file ) {
1628 $list[] = $file;
1629 }
1630 sort( $list );
1631
1632 $this->assertEquals( $expected, $list, "Correct top dir listing ($backendName)." );
1633
1634 // Actual listing (with trailing slash)
1635 $list = array();
1636 $iter = $this->backend->getTopDirectoryList( array( 'dir' => "$base/unittest-cont1/subdir2/" ) );
1637 foreach ( $iter as $file ) {
1638 $list[] = $file;
1639 }
1640 sort( $list );
1641
1642 $this->assertEquals( $expected, $list, "Correct top dir listing ($backendName)." );
1643
1644 // Actual listing (using iterator second time)
1645 $list = array();
1646 foreach ( $iter as $file ) {
1647 $list[] = $file;
1648 }
1649 sort( $list );
1650
1651 $this->assertEquals( $expected, $list, "Correct top dir listing ($backendName), second iteration." );
1652
1653 // Expected listing (recursive)
1654 $expected = array(
1655 "subdir1",
1656 "subdir2",
1657 "subdir3",
1658 "subdir4",
1659 "subdir2/subdir",
1660 "subdir3/subdir",
1661 "subdir4/subdir",
1662 "subdir4/subdir/sub",
1663 );
1664 sort( $expected );
1665
1666 // Actual listing (recursive)
1667 $list = array();
1668 $iter = $this->backend->getDirectoryList( array( 'dir' => "$base/unittest-cont1/" ) );
1669 foreach ( $iter as $file ) {
1670 $list[] = $file;
1671 }
1672 sort( $list );
1673
1674 $this->assertEquals( $expected, $list, "Correct dir listing ($backendName)." );
1675
1676 // Expected listing (recursive)
1677 $expected = array(
1678 "subdir",
1679 "subdir/sub",
1680 );
1681 sort( $expected );
1682
1683 // Actual listing (recursive)
1684 $list = array();
1685 $iter = $this->backend->getDirectoryList( array( 'dir' => "$base/unittest-cont1/subdir4" ) );
1686 foreach ( $iter as $file ) {
1687 $list[] = $file;
1688 }
1689 sort( $list );
1690
1691 $this->assertEquals( $expected, $list, "Correct dir listing ($backendName)." );
1692
1693 // Actual listing (recursive, second time)
1694 $list = array();
1695 foreach ( $iter as $file ) {
1696 $list[] = $file;
1697 }
1698 sort( $list );
1699
1700 $this->assertEquals( $expected, $list, "Correct dir listing ($backendName)." );
1701
1702 foreach ( $files as $file ) { // clean up
1703 $this->backend->doOperation( array( 'op' => 'delete', 'src' => $file ) );
1704 }
1705
1706 $iter = $this->backend->getDirectoryList( array( 'dir' => "$base/unittest-cont1/not/exists" ) );
1707 foreach ( $iter as $iter ) {} // no errors
1708 }
1709
1710 public function testLockCalls() {
1711 $this->backend = $this->singleBackend;
1712 $this->doTestLockCalls();
1713 }
1714
1715 private function doTestLockCalls() {
1716 $backendName = $this->backendClass();
1717
1718 for ( $i=0; $i<50; $i++ ) {
1719 $paths = array(
1720 "test1.txt",
1721 "test2.txt",
1722 "test3.txt",
1723 "subdir1",
1724 "subdir1", // duplicate
1725 "subdir1/test1.txt",
1726 "subdir1/test2.txt",
1727 "subdir2",
1728 "subdir2", // duplicate
1729 "subdir2/test3.txt",
1730 "subdir2/test4.txt",
1731 "subdir2/subdir",
1732 "subdir2/subdir/test1.txt",
1733 "subdir2/subdir/test2.txt",
1734 "subdir2/subdir/test3.txt",
1735 "subdir2/subdir/test4.txt",
1736 "subdir2/subdir/test5.txt",
1737 "subdir2/subdir/sub",
1738 "subdir2/subdir/sub/test0.txt",
1739 "subdir2/subdir/sub/120-px-file.txt",
1740 );
1741
1742 $status = $this->backend->lockFiles( $paths, LockManager::LOCK_EX );
1743 $this->assertEquals( array(), $status->errors,
1744 "Locking of files succeeded ($backendName)." );
1745 $this->assertEquals( true, $status->isOK(),
1746 "Locking of files succeeded with OK status ($backendName)." );
1747
1748 $status = $this->backend->lockFiles( $paths, LockManager::LOCK_SH );
1749 $this->assertEquals( array(), $status->errors,
1750 "Locking of files succeeded ($backendName)." );
1751 $this->assertEquals( true, $status->isOK(),
1752 "Locking of files succeeded with OK status ($backendName)." );
1753
1754 $status = $this->backend->unlockFiles( $paths, LockManager::LOCK_SH );
1755 $this->assertEquals( array(), $status->errors,
1756 "Locking of files succeeded ($backendName)." );
1757 $this->assertEquals( true, $status->isOK(),
1758 "Locking of files succeeded with OK status ($backendName)." );
1759
1760 $status = $this->backend->unlockFiles( $paths, LockManager::LOCK_EX );
1761 $this->assertEquals( array(), $status->errors,
1762 "Locking of files succeeded ($backendName)." );
1763 $this->assertEquals( true, $status->isOK(),
1764 "Locking of files succeeded with OK status ($backendName)." );
1765 }
1766 }
1767
1768 // test helper wrapper for backend prepare() function
1769 private function prepare( array $params ) {
1770 return $this->backend->prepare( $params );
1771 }
1772
1773 // test helper wrapper for backend prepare() function
1774 private function create( array $params ) {
1775 $params['op'] = 'create';
1776 return $this->backend->doQuickOperations( array( $params ) );
1777 }
1778
1779 function tearDownFiles() {
1780 foreach ( $this->filesToPrune as $file ) {
1781 @unlink( $file );
1782 }
1783 $containers = array( 'unittest-cont1', 'unittest-cont2', 'unittest-cont3' );
1784 foreach ( $containers as $container ) {
1785 $this->deleteFiles( $container );
1786 }
1787 $this->filesToPrune = array();
1788 }
1789
1790 private function deleteFiles( $container ) {
1791 $base = $this->baseStorePath();
1792 $iter = $this->backend->getFileList( array( 'dir' => "$base/$container" ) );
1793 if ( $iter ) {
1794 foreach ( $iter as $file ) {
1795 $this->backend->delete( array( 'src' => "$base/$container/$file" ),
1796 array( 'force' => 1, 'nonLocking' => 1 ) );
1797 }
1798 }
1799 $this->backend->clean( array( 'dir' => "$base/$container", 'recursive' => 1 ) );
1800 }
1801
1802 function assertGoodStatus( $status, $msg ) {
1803 $this->assertEquals( print_r( array(), 1 ), print_r( $status->errors, 1 ), $msg );
1804 }
1805
1806 function tearDown() {
1807 parent::tearDown();
1808 }
1809 }