[FileBackend] Purge Swift process cache before container delete for sanity.
[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 $base = $this->baseStorePath();
1396
1397 // Should have no errors
1398 $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont-notexists" ) );
1399
1400 $files = array(
1401 "$base/unittest-cont1/test1.txt",
1402 "$base/unittest-cont1/test2.txt",
1403 "$base/unittest-cont1/test3.txt",
1404 "$base/unittest-cont1/subdir1/test1.txt",
1405 "$base/unittest-cont1/subdir1/test2.txt",
1406 "$base/unittest-cont1/subdir2/test3.txt",
1407 "$base/unittest-cont1/subdir2/test4.txt",
1408 "$base/unittest-cont1/subdir2/subdir/test1.txt",
1409 "$base/unittest-cont1/subdir2/subdir/test2.txt",
1410 "$base/unittest-cont1/subdir2/subdir/test3.txt",
1411 "$base/unittest-cont1/subdir2/subdir/test4.txt",
1412 "$base/unittest-cont1/subdir2/subdir/test5.txt",
1413 "$base/unittest-cont1/subdir2/subdir/sub/test0.txt",
1414 "$base/unittest-cont1/subdir2/subdir/sub/120-px-file.txt",
1415 );
1416
1417 // Add the files
1418 $ops = array();
1419 foreach ( $files as $file ) {
1420 $this->prepare( array( 'dir' => dirname( $file ) ) );
1421 $ops[] = array( 'op' => 'create', 'content' => 'xxy', 'dst' => $file );
1422 }
1423 $status = $this->backend->doQuickOperations( $ops );
1424 $this->assertGoodStatus( $status,
1425 "Creation of files succeeded ($backendName)." );
1426 $this->assertEquals( true, $status->isOK(),
1427 "Creation of files succeeded with OK status ($backendName)." );
1428
1429 // Expected listing
1430 $expected = array(
1431 "test1.txt",
1432 "test2.txt",
1433 "test3.txt",
1434 "subdir1/test1.txt",
1435 "subdir1/test2.txt",
1436 "subdir2/test3.txt",
1437 "subdir2/test4.txt",
1438 "subdir2/subdir/test1.txt",
1439 "subdir2/subdir/test2.txt",
1440 "subdir2/subdir/test3.txt",
1441 "subdir2/subdir/test4.txt",
1442 "subdir2/subdir/test5.txt",
1443 "subdir2/subdir/sub/test0.txt",
1444 "subdir2/subdir/sub/120-px-file.txt",
1445 );
1446 sort( $expected );
1447
1448 // Actual listing (no trailing slash)
1449 $list = array();
1450 $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1" ) );
1451 foreach ( $iter as $file ) {
1452 $list[] = $file;
1453 }
1454 sort( $list );
1455
1456 $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
1457
1458 // Actual listing (with trailing slash)
1459 $list = array();
1460 $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/" ) );
1461 foreach ( $iter as $file ) {
1462 $list[] = $file;
1463 }
1464 sort( $list );
1465
1466 $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
1467
1468 // Expected listing
1469 $expected = array(
1470 "test1.txt",
1471 "test2.txt",
1472 "test3.txt",
1473 "test4.txt",
1474 "test5.txt",
1475 "sub/test0.txt",
1476 "sub/120-px-file.txt",
1477 );
1478 sort( $expected );
1479
1480 // Actual listing (no trailing slash)
1481 $list = array();
1482 $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/subdir2/subdir" ) );
1483 foreach ( $iter as $file ) {
1484 $list[] = $file;
1485 }
1486 sort( $list );
1487
1488 $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
1489
1490 // Actual listing (with trailing slash)
1491 $list = array();
1492 $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/subdir2/subdir/" ) );
1493 foreach ( $iter as $file ) {
1494 $list[] = $file;
1495 }
1496 sort( $list );
1497
1498 $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
1499
1500 // Actual listing (using iterator second time)
1501 $list = array();
1502 foreach ( $iter as $file ) {
1503 $list[] = $file;
1504 }
1505 sort( $list );
1506
1507 $this->assertEquals( $expected, $list, "Correct file listing ($backendName), second iteration." );
1508
1509 // Expected listing (top files only)
1510 $expected = array(
1511 "test1.txt",
1512 "test2.txt",
1513 "test3.txt",
1514 "test4.txt",
1515 "test5.txt"
1516 );
1517 sort( $expected );
1518
1519 // Actual listing (top files only)
1520 $list = array();
1521 $iter = $this->backend->getTopFileList( array( 'dir' => "$base/unittest-cont1/subdir2/subdir" ) );
1522 foreach ( $iter as $file ) {
1523 $list[] = $file;
1524 }
1525 sort( $list );
1526
1527 $this->assertEquals( $expected, $list, "Correct top file listing ($backendName)." );
1528
1529 foreach ( $files as $file ) { // clean up
1530 $this->backend->doOperation( array( 'op' => 'delete', 'src' => $file ) );
1531 }
1532
1533 $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/not/exists" ) );
1534 foreach ( $iter as $iter ) {} // no errors
1535 }
1536
1537 public function testGetDirectoryList() {
1538 $this->backend = $this->singleBackend;
1539 $this->tearDownFiles();
1540 $this->doTestGetDirectoryList();
1541 $this->tearDownFiles();
1542
1543 $this->backend = $this->multiBackend;
1544 $this->tearDownFiles();
1545 $this->doTestGetDirectoryList();
1546 $this->tearDownFiles();
1547 }
1548
1549 private function doTestGetDirectoryList() {
1550 $backendName = $this->backendClass();
1551
1552 $base = $this->baseStorePath();
1553 $files = array(
1554 "$base/unittest-cont1/test1.txt",
1555 "$base/unittest-cont1/test2.txt",
1556 "$base/unittest-cont1/test3.txt",
1557 "$base/unittest-cont1/subdir1/test1.txt",
1558 "$base/unittest-cont1/subdir1/test2.txt",
1559 "$base/unittest-cont1/subdir2/test3.txt",
1560 "$base/unittest-cont1/subdir2/test4.txt",
1561 "$base/unittest-cont1/subdir2/subdir/test1.txt",
1562 "$base/unittest-cont1/subdir3/subdir/test2.txt",
1563 "$base/unittest-cont1/subdir4/subdir/test3.txt",
1564 "$base/unittest-cont1/subdir4/subdir/test4.txt",
1565 "$base/unittest-cont1/subdir4/subdir/test5.txt",
1566 "$base/unittest-cont1/subdir4/subdir/sub/test0.txt",
1567 "$base/unittest-cont1/subdir4/subdir/sub/120-px-file.txt",
1568 );
1569
1570 // Add the files
1571 $ops = array();
1572 foreach ( $files as $file ) {
1573 $this->prepare( array( 'dir' => dirname( $file ) ) );
1574 $ops[] = array( 'op' => 'create', 'content' => 'xxy', 'dst' => $file );
1575 }
1576 $status = $this->backend->doQuickOperations( $ops );
1577 $this->assertGoodStatus( $status,
1578 "Creation of files succeeded ($backendName)." );
1579 $this->assertEquals( true, $status->isOK(),
1580 "Creation of files succeeded with OK status ($backendName)." );
1581
1582 // Expected listing
1583 $expected = array(
1584 "subdir1",
1585 "subdir2",
1586 "subdir3",
1587 "subdir4",
1588 );
1589 sort( $expected );
1590
1591 $this->assertEquals( true,
1592 $this->backend->directoryExists( array( 'dir' => "$base/unittest-cont1/subdir1" ) ),
1593 "Directory exists in ($backendName)." );
1594 $this->assertEquals( true,
1595 $this->backend->directoryExists( array( 'dir' => "$base/unittest-cont1/subdir2/subdir" ) ),
1596 "Directory exists in ($backendName)." );
1597 $this->assertEquals( false,
1598 $this->backend->directoryExists( array( 'dir' => "$base/unittest-cont1/subdir2/test1.txt" ) ),
1599 "Directory does not exists in ($backendName)." );
1600
1601 // Actual listing (no trailing slash)
1602 $list = array();
1603 $iter = $this->backend->getTopDirectoryList( array( 'dir' => "$base/unittest-cont1" ) );
1604 foreach ( $iter as $file ) {
1605 $list[] = $file;
1606 }
1607 sort( $list );
1608
1609 $this->assertEquals( $expected, $list, "Correct top dir listing ($backendName)." );
1610
1611 // Actual listing (with trailing slash)
1612 $list = array();
1613 $iter = $this->backend->getTopDirectoryList( array( 'dir' => "$base/unittest-cont1/" ) );
1614 foreach ( $iter as $file ) {
1615 $list[] = $file;
1616 }
1617 sort( $list );
1618
1619 $this->assertEquals( $expected, $list, "Correct top dir listing ($backendName)." );
1620
1621 // Expected listing
1622 $expected = array(
1623 "subdir",
1624 );
1625 sort( $expected );
1626
1627 // Actual listing (no trailing slash)
1628 $list = array();
1629 $iter = $this->backend->getTopDirectoryList( array( 'dir' => "$base/unittest-cont1/subdir2" ) );
1630 foreach ( $iter as $file ) {
1631 $list[] = $file;
1632 }
1633 sort( $list );
1634
1635 $this->assertEquals( $expected, $list, "Correct top dir listing ($backendName)." );
1636
1637 // Actual listing (with trailing slash)
1638 $list = array();
1639 $iter = $this->backend->getTopDirectoryList( array( 'dir' => "$base/unittest-cont1/subdir2/" ) );
1640 foreach ( $iter as $file ) {
1641 $list[] = $file;
1642 }
1643 sort( $list );
1644
1645 $this->assertEquals( $expected, $list, "Correct top dir listing ($backendName)." );
1646
1647 // Actual listing (using iterator second time)
1648 $list = array();
1649 foreach ( $iter as $file ) {
1650 $list[] = $file;
1651 }
1652 sort( $list );
1653
1654 $this->assertEquals( $expected, $list, "Correct top dir listing ($backendName), second iteration." );
1655
1656 // Expected listing (recursive)
1657 $expected = array(
1658 "subdir1",
1659 "subdir2",
1660 "subdir3",
1661 "subdir4",
1662 "subdir2/subdir",
1663 "subdir3/subdir",
1664 "subdir4/subdir",
1665 "subdir4/subdir/sub",
1666 );
1667 sort( $expected );
1668
1669 // Actual listing (recursive)
1670 $list = array();
1671 $iter = $this->backend->getDirectoryList( array( 'dir' => "$base/unittest-cont1/" ) );
1672 foreach ( $iter as $file ) {
1673 $list[] = $file;
1674 }
1675 sort( $list );
1676
1677 $this->assertEquals( $expected, $list, "Correct dir listing ($backendName)." );
1678
1679 // Expected listing (recursive)
1680 $expected = array(
1681 "subdir",
1682 "subdir/sub",
1683 );
1684 sort( $expected );
1685
1686 // Actual listing (recursive)
1687 $list = array();
1688 $iter = $this->backend->getDirectoryList( array( 'dir' => "$base/unittest-cont1/subdir4" ) );
1689 foreach ( $iter as $file ) {
1690 $list[] = $file;
1691 }
1692 sort( $list );
1693
1694 $this->assertEquals( $expected, $list, "Correct dir listing ($backendName)." );
1695
1696 // Actual listing (recursive, second time)
1697 $list = array();
1698 foreach ( $iter as $file ) {
1699 $list[] = $file;
1700 }
1701 sort( $list );
1702
1703 $this->assertEquals( $expected, $list, "Correct dir listing ($backendName)." );
1704
1705 foreach ( $files as $file ) { // clean up
1706 $this->backend->doOperation( array( 'op' => 'delete', 'src' => $file ) );
1707 }
1708
1709 $iter = $this->backend->getDirectoryList( array( 'dir' => "$base/unittest-cont1/not/exists" ) );
1710 foreach ( $iter as $iter ) {} // no errors
1711 }
1712
1713 public function testLockCalls() {
1714 $this->backend = $this->singleBackend;
1715 $this->doTestLockCalls();
1716 }
1717
1718 private function doTestLockCalls() {
1719 $backendName = $this->backendClass();
1720
1721 for ( $i=0; $i<50; $i++ ) {
1722 $paths = array(
1723 "test1.txt",
1724 "test2.txt",
1725 "test3.txt",
1726 "subdir1",
1727 "subdir1", // duplicate
1728 "subdir1/test1.txt",
1729 "subdir1/test2.txt",
1730 "subdir2",
1731 "subdir2", // duplicate
1732 "subdir2/test3.txt",
1733 "subdir2/test4.txt",
1734 "subdir2/subdir",
1735 "subdir2/subdir/test1.txt",
1736 "subdir2/subdir/test2.txt",
1737 "subdir2/subdir/test3.txt",
1738 "subdir2/subdir/test4.txt",
1739 "subdir2/subdir/test5.txt",
1740 "subdir2/subdir/sub",
1741 "subdir2/subdir/sub/test0.txt",
1742 "subdir2/subdir/sub/120-px-file.txt",
1743 );
1744
1745 $status = $this->backend->lockFiles( $paths, LockManager::LOCK_EX );
1746 $this->assertEquals( array(), $status->errors,
1747 "Locking of files succeeded ($backendName)." );
1748 $this->assertEquals( true, $status->isOK(),
1749 "Locking of files succeeded with OK status ($backendName)." );
1750
1751 $status = $this->backend->lockFiles( $paths, LockManager::LOCK_SH );
1752 $this->assertEquals( array(), $status->errors,
1753 "Locking of files succeeded ($backendName)." );
1754 $this->assertEquals( true, $status->isOK(),
1755 "Locking of files succeeded with OK status ($backendName)." );
1756
1757 $status = $this->backend->unlockFiles( $paths, LockManager::LOCK_SH );
1758 $this->assertEquals( array(), $status->errors,
1759 "Locking of files succeeded ($backendName)." );
1760 $this->assertEquals( true, $status->isOK(),
1761 "Locking of files succeeded with OK status ($backendName)." );
1762
1763 $status = $this->backend->unlockFiles( $paths, LockManager::LOCK_EX );
1764 $this->assertEquals( array(), $status->errors,
1765 "Locking of files succeeded ($backendName)." );
1766 $this->assertEquals( true, $status->isOK(),
1767 "Locking of files succeeded with OK status ($backendName)." );
1768 }
1769 }
1770
1771 // test helper wrapper for backend prepare() function
1772 private function prepare( array $params ) {
1773 return $this->backend->prepare( $params );
1774 }
1775
1776 // test helper wrapper for backend prepare() function
1777 private function create( array $params ) {
1778 $params['op'] = 'create';
1779 return $this->backend->doQuickOperations( array( $params ) );
1780 }
1781
1782 function tearDownFiles() {
1783 foreach ( $this->filesToPrune as $file ) {
1784 @unlink( $file );
1785 }
1786 $containers = array( 'unittest-cont1', 'unittest-cont2', 'unittest-cont3' );
1787 foreach ( $containers as $container ) {
1788 $this->deleteFiles( $container );
1789 }
1790 $this->filesToPrune = array();
1791 }
1792
1793 private function deleteFiles( $container ) {
1794 $base = $this->baseStorePath();
1795 $iter = $this->backend->getFileList( array( 'dir' => "$base/$container" ) );
1796 if ( $iter ) {
1797 foreach ( $iter as $file ) {
1798 $this->backend->delete( array( 'src' => "$base/$container/$file" ),
1799 array( 'force' => 1, 'nonLocking' => 1 ) );
1800 }
1801 }
1802 $this->backend->clean( array( 'dir' => "$base/$container", 'recursive' => 1 ) );
1803 }
1804
1805 function assertGoodStatus( $status, $msg ) {
1806 $this->assertEquals( print_r( array(), 1 ), print_r( $status->errors, 1 ), $msg );
1807 }
1808
1809 function tearDown() {
1810 parent::tearDown();
1811 }
1812 }