8 class FileBackendTest
extends MediaWikiTestCase
{
9 private $backend, $multiBackend;
10 private $filesToPrune = array();
11 private static $backendToUse;
13 protected function setUp() {
14 global $wgFileBackends;
16 $tmpPrefix = wfTempDir() . '/filebackend-unittest-' . time() . '-' . mt_rand();
17 if ( $this->getCliArg( 'use-filebackend=' ) ) {
18 if ( self
::$backendToUse ) {
19 $this->singleBackend
= self
::$backendToUse;
21 $name = $this->getCliArg( 'use-filebackend=' );
23 foreach ( $wgFileBackends as $conf ) {
24 if ( $conf['name'] == $name ) {
29 $useConfig['name'] = 'localtesting'; // swap name
30 $useConfig['shardViaHashLevels'] = array( // test sharding
31 'unittest-cont1' => array( 'levels' => 1, 'base' => 16, 'repeat' => 1 )
33 $class = $useConfig['class'];
34 self
::$backendToUse = new $class( $useConfig );
35 $this->singleBackend
= self
::$backendToUse;
38 $this->singleBackend
= new FSFileBackend( array(
39 'name' => 'localtesting',
40 'lockManager' => 'fsLockManager',
41 #'parallelize' => 'implicit',
42 'containerPaths' => array(
43 'unittest-cont1' => "{$tmpPrefix}-localtesting-cont1",
44 'unittest-cont2' => "{$tmpPrefix}-localtesting-cont2" )
47 $this->multiBackend
= new FileBackendMultiWrite( array(
48 'name' => 'localtesting',
49 'lockManager' => 'fsLockManager',
50 'parallelize' => 'implicit',
53 'name' => 'localmultitesting1',
54 'class' => 'FSFileBackend',
55 'lockManager' => 'nullLockManager',
56 'containerPaths' => array(
57 'unittest-cont1' => "{$tmpPrefix}-localtestingmulti1-cont1",
58 'unittest-cont2' => "{$tmpPrefix}-localtestingmulti1-cont2" ),
59 'isMultiMaster' => false
62 'name' => 'localmultitesting2',
63 'class' => 'FSFileBackend',
64 'lockManager' => 'nullLockManager',
65 'containerPaths' => array(
66 'unittest-cont1' => "{$tmpPrefix}-localtestingmulti2-cont1",
67 'unittest-cont2' => "{$tmpPrefix}-localtestingmulti2-cont2" ),
68 'isMultiMaster' => true
72 $this->filesToPrune
= array();
75 private static function baseStorePath() {
76 return 'mwstore://localtesting';
79 private function backendClass() {
80 return get_class( $this->backend
);
84 * @dataProvider provider_testIsStoragePath
86 public function testIsStoragePath( $path, $isStorePath ) {
87 $this->assertEquals( $isStorePath, FileBackend
::isStoragePath( $path ),
88 "FileBackend::isStoragePath on path '$path'" );
91 function provider_testIsStoragePath() {
93 array( 'mwstore://', true ),
94 array( 'mwstore://backend', true ),
95 array( 'mwstore://backend/container', true ),
96 array( 'mwstore://backend/container/', true ),
97 array( 'mwstore://backend/container/path', true ),
98 array( 'mwstore://backend//container/', true ),
99 array( 'mwstore://backend//container//', true ),
100 array( 'mwstore://backend//container//path', true ),
101 array( 'mwstore:///', true ),
102 array( 'mwstore:/', false ),
103 array( 'mwstore:', false ),
108 * @dataProvider provider_testSplitStoragePath
110 public function testSplitStoragePath( $path, $res ) {
111 $this->assertEquals( $res, FileBackend
::splitStoragePath( $path ),
112 "FileBackend::splitStoragePath on path '$path'" );
115 function provider_testSplitStoragePath() {
117 array( 'mwstore://backend/container', array( 'backend', 'container', '' ) ),
118 array( 'mwstore://backend/container/', array( 'backend', 'container', '' ) ),
119 array( 'mwstore://backend/container/path', array( 'backend', 'container', 'path' ) ),
120 array( 'mwstore://backend/container//path', array( 'backend', 'container', '/path' ) ),
121 array( 'mwstore://backend//container/path', array( null, null, null ) ),
122 array( 'mwstore://backend//container//path', array( null, null, null ) ),
123 array( 'mwstore://', array( null, null, null ) ),
124 array( 'mwstore://backend', array( null, null, null ) ),
125 array( 'mwstore:///', array( null, null, null ) ),
126 array( 'mwstore:/', array( null, null, null ) ),
127 array( 'mwstore:', array( null, null, null ) )
132 * @dataProvider provider_normalizeStoragePath
134 public function testNormalizeStoragePath( $path, $res ) {
135 $this->assertEquals( $res, FileBackend
::normalizeStoragePath( $path ),
136 "FileBackend::normalizeStoragePath on path '$path'" );
139 function provider_normalizeStoragePath() {
141 array( 'mwstore://backend/container', 'mwstore://backend/container' ),
142 array( 'mwstore://backend/container/', 'mwstore://backend/container' ),
143 array( 'mwstore://backend/container/path', 'mwstore://backend/container/path' ),
144 array( 'mwstore://backend/container//path', 'mwstore://backend/container/path' ),
145 array( 'mwstore://backend/container///path', 'mwstore://backend/container/path' ),
146 array( 'mwstore://backend/container///path//to///obj', 'mwstore://backend/container/path/to/obj',
147 array( 'mwstore://', null ),
148 array( 'mwstore://backend', null ),
149 array( 'mwstore://backend//container/path', null ),
150 array( 'mwstore://backend//container//path', null ),
151 array( 'mwstore:///', null ),
152 array( 'mwstore:/', null ),
153 array( 'mwstore:', null ), )
158 * @dataProvider provider_testParentStoragePath
160 public function testParentStoragePath( $path, $res ) {
161 $this->assertEquals( $res, FileBackend
::parentStoragePath( $path ),
162 "FileBackend::parentStoragePath on path '$path'" );
165 function provider_testParentStoragePath() {
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 array( 'mwstore://backend/container/path/to/obj/', 'mwstore://backend/container/path/to' ),
172 array( 'mwstore://backend/container/path/to/', 'mwstore://backend/container/path' ),
173 array( 'mwstore://backend/container/path/', 'mwstore://backend/container' ),
174 array( 'mwstore://backend/container/', null ),
179 * @dataProvider provider_testExtensionFromPath
181 public function testExtensionFromPath( $path, $res ) {
182 $this->assertEquals( $res, FileBackend
::extensionFromPath( $path ),
183 "FileBackend::extensionFromPath on path '$path'" );
186 public static function provider_testExtensionFromPath() {
188 array( 'mwstore://backend/container/path.txt', 'txt' ),
189 array( 'mwstore://backend/container/path.svg.png', 'png' ),
190 array( 'mwstore://backend/container/path', '' ),
191 array( 'mwstore://backend/container/path.', '' ),
196 * @dataProvider provider_testStore
198 public function testStore( $op ) {
199 $this->filesToPrune
[] = $op['src'];
201 $this->backend
= $this->singleBackend
;
202 $this->tearDownFiles();
203 $this->doTestStore( $op );
204 $this->tearDownFiles();
206 $this->backend
= $this->multiBackend
;
207 $this->tearDownFiles();
208 $this->doTestStore( $op );
209 $this->filesToPrune
[] = $op['src']; # avoid file leaking
210 $this->tearDownFiles();
213 private function doTestStore( $op ) {
214 $backendName = $this->backendClass();
216 $source = $op['src'];
218 $this->prepare( array( 'dir' => dirname( $dest ) ) );
220 file_put_contents( $source, "Unit test file" );
222 if ( isset( $op['overwrite'] ) ||
isset( $op['overwriteSame'] ) ) {
223 $this->backend
->store( $op );
226 $status = $this->backend
->doOperation( $op );
228 $this->assertGoodStatus( $status,
229 "Store from $source to $dest succeeded without warnings ($backendName)." );
230 $this->assertEquals( true, $status->isOK(),
231 "Store from $source to $dest succeeded ($backendName)." );
232 $this->assertEquals( array( 0 => true ), $status->success
,
233 "Store from $source to $dest has proper 'success' field in Status ($backendName)." );
234 $this->assertEquals( true, file_exists( $source ),
235 "Source file $source still exists ($backendName)." );
236 $this->assertEquals( true, $this->backend
->fileExists( array( 'src' => $dest ) ),
237 "Destination file $dest exists ($backendName)." );
239 $this->assertEquals( filesize( $source ),
240 $this->backend
->getFileSize( array( 'src' => $dest ) ),
241 "Destination file $dest has correct size ($backendName)." );
243 $props1 = FSFile
::getPropsFromPath( $source );
244 $props2 = $this->backend
->getFileProps( array( 'src' => $dest ) );
245 $this->assertEquals( $props1, $props2,
246 "Source and destination have the same props ($backendName)." );
248 $this->assertBackendPathsConsistent( array( $dest ) );
251 public static function provider_testStore() {
254 $tmpName = TempFSFile
::factory( "unittests_", 'txt' )->getPath();
255 $toPath = self
::baseStorePath() . '/unittest-cont1/e/fun/obj1.txt';
256 $op = array( 'op' => 'store', 'src' => $tmpName, 'dst' => $toPath );
264 $op2['overwrite'] = true;
272 $op2['overwriteSame'] = true;
283 * @dataProvider provider_testCopy
285 public function testCopy( $op ) {
286 $this->backend
= $this->singleBackend
;
287 $this->tearDownFiles();
288 $this->doTestCopy( $op );
289 $this->tearDownFiles();
291 $this->backend
= $this->multiBackend
;
292 $this->tearDownFiles();
293 $this->doTestCopy( $op );
294 $this->tearDownFiles();
297 private function doTestCopy( $op ) {
298 $backendName = $this->backendClass();
300 $source = $op['src'];
302 $this->prepare( array( 'dir' => dirname( $source ) ) );
303 $this->prepare( array( 'dir' => dirname( $dest ) ) );
305 if ( isset( $op['ignoreMissingSource'] ) ) {
306 $status = $this->backend
->doOperation( $op );
307 $this->assertGoodStatus( $status,
308 "Move from $source to $dest succeeded without warnings ($backendName)." );
309 $this->assertEquals( array( 0 => true ), $status->success
,
310 "Move from $source to $dest has proper 'success' field in Status ($backendName)." );
311 $this->assertEquals( false, $this->backend
->fileExists( array( 'src' => $source ) ),
312 "Source file $source does not exist ($backendName)." );
313 $this->assertEquals( false, $this->backend
->fileExists( array( 'src' => $dest ) ),
314 "Destination file $dest does not exist ($backendName)." );
318 $status = $this->backend
->doOperation(
319 array( 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ) );
320 $this->assertGoodStatus( $status,
321 "Creation of file at $source succeeded ($backendName)." );
323 if ( isset( $op['overwrite'] ) ||
isset( $op['overwriteSame'] ) ) {
324 $this->backend
->copy( $op );
327 $status = $this->backend
->doOperation( $op );
329 $this->assertGoodStatus( $status,
330 "Copy from $source to $dest succeeded without warnings ($backendName)." );
331 $this->assertEquals( true, $status->isOK(),
332 "Copy from $source to $dest succeeded ($backendName)." );
333 $this->assertEquals( array( 0 => true ), $status->success
,
334 "Copy from $source to $dest has proper 'success' field in Status ($backendName)." );
335 $this->assertEquals( true, $this->backend
->fileExists( array( 'src' => $source ) ),
336 "Source file $source still exists ($backendName)." );
337 $this->assertEquals( true, $this->backend
->fileExists( array( 'src' => $dest ) ),
338 "Destination file $dest exists after copy ($backendName)." );
341 $this->backend
->getFileSize( array( 'src' => $source ) ),
342 $this->backend
->getFileSize( array( 'src' => $dest ) ),
343 "Destination file $dest has correct size ($backendName)." );
345 $props1 = $this->backend
->getFileProps( array( 'src' => $source ) );
346 $props2 = $this->backend
->getFileProps( array( 'src' => $dest ) );
347 $this->assertEquals( $props1, $props2,
348 "Source and destination have the same props ($backendName)." );
350 $this->assertBackendPathsConsistent( array( $source, $dest ) );
353 public static function provider_testCopy() {
356 $source = self
::baseStorePath() . '/unittest-cont1/e/file.txt';
357 $dest = self
::baseStorePath() . '/unittest-cont2/a/fileMoved.txt';
359 $op = array( 'op' => 'copy', 'src' => $source, 'dst' => $dest );
367 $op2['overwrite'] = true;
375 $op2['overwriteSame'] = true;
383 $op2['ignoreMissingSource'] = true;
394 * @dataProvider provider_testMove
396 public function testMove( $op ) {
397 $this->backend
= $this->singleBackend
;
398 $this->tearDownFiles();
399 $this->doTestMove( $op );
400 $this->tearDownFiles();
402 $this->backend
= $this->multiBackend
;
403 $this->tearDownFiles();
404 $this->doTestMove( $op );
405 $this->tearDownFiles();
408 private function doTestMove( $op ) {
409 $backendName = $this->backendClass();
411 $source = $op['src'];
413 $this->prepare( array( 'dir' => dirname( $source ) ) );
414 $this->prepare( array( 'dir' => dirname( $dest ) ) );
416 if ( isset( $op['ignoreMissingSource'] ) ) {
417 $status = $this->backend
->doOperation( $op );
418 $this->assertGoodStatus( $status,
419 "Move from $source to $dest succeeded without warnings ($backendName)." );
420 $this->assertEquals( array( 0 => true ), $status->success
,
421 "Move from $source to $dest has proper 'success' field in Status ($backendName)." );
422 $this->assertEquals( false, $this->backend
->fileExists( array( 'src' => $source ) ),
423 "Source file $source does not exist ($backendName)." );
424 $this->assertEquals( false, $this->backend
->fileExists( array( 'src' => $dest ) ),
425 "Destination file $dest does not exist ($backendName)." );
429 $status = $this->backend
->doOperation(
430 array( 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ) );
431 $this->assertGoodStatus( $status,
432 "Creation of file at $source succeeded ($backendName)." );
434 if ( isset( $op['overwrite'] ) ||
isset( $op['overwriteSame'] ) ) {
435 $this->backend
->copy( $op );
438 $status = $this->backend
->doOperation( $op );
439 $this->assertGoodStatus( $status,
440 "Move from $source to $dest succeeded without warnings ($backendName)." );
441 $this->assertEquals( true, $status->isOK(),
442 "Move from $source to $dest succeeded ($backendName)." );
443 $this->assertEquals( array( 0 => true ), $status->success
,
444 "Move from $source to $dest has proper 'success' field in Status ($backendName)." );
445 $this->assertEquals( false, $this->backend
->fileExists( array( 'src' => $source ) ),
446 "Source file $source does not still exists ($backendName)." );
447 $this->assertEquals( true, $this->backend
->fileExists( array( 'src' => $dest ) ),
448 "Destination file $dest exists after move ($backendName)." );
450 $this->assertNotEquals(
451 $this->backend
->getFileSize( array( 'src' => $source ) ),
452 $this->backend
->getFileSize( array( 'src' => $dest ) ),
453 "Destination file $dest has correct size ($backendName)." );
455 $props1 = $this->backend
->getFileProps( array( 'src' => $source ) );
456 $props2 = $this->backend
->getFileProps( array( 'src' => $dest ) );
457 $this->assertEquals( false, $props1['fileExists'],
458 "Source file does not exist accourding to props ($backendName)." );
459 $this->assertEquals( true, $props2['fileExists'],
460 "Destination file exists accourding to props ($backendName)." );
462 $this->assertBackendPathsConsistent( array( $source, $dest ) );
465 public static function provider_testMove() {
468 $source = self
::baseStorePath() . '/unittest-cont1/e/file.txt';
469 $dest = self
::baseStorePath() . '/unittest-cont2/a/fileMoved.txt';
471 $op = array( 'op' => 'move', 'src' => $source, 'dst' => $dest );
479 $op2['overwrite'] = true;
487 $op2['overwriteSame'] = true;
495 $op2['ignoreMissingSource'] = true;
506 * @dataProvider provider_testDelete
508 public function testDelete( $op, $withSource, $okStatus ) {
509 $this->backend
= $this->singleBackend
;
510 $this->tearDownFiles();
511 $this->doTestDelete( $op, $withSource, $okStatus );
512 $this->tearDownFiles();
514 $this->backend
= $this->multiBackend
;
515 $this->tearDownFiles();
516 $this->doTestDelete( $op, $withSource, $okStatus );
517 $this->tearDownFiles();
520 private function doTestDelete( $op, $withSource, $okStatus ) {
521 $backendName = $this->backendClass();
523 $source = $op['src'];
524 $this->prepare( array( 'dir' => dirname( $source ) ) );
527 $status = $this->backend
->doOperation(
528 array( 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ) );
529 $this->assertGoodStatus( $status,
530 "Creation of file at $source succeeded ($backendName)." );
533 $status = $this->backend
->doOperation( $op );
535 $this->assertGoodStatus( $status,
536 "Deletion of file at $source succeeded without warnings ($backendName)." );
537 $this->assertEquals( true, $status->isOK(),
538 "Deletion of file at $source succeeded ($backendName)." );
539 $this->assertEquals( array( 0 => true ), $status->success
,
540 "Deletion of file at $source has proper 'success' field in Status ($backendName)." );
542 $this->assertEquals( false, $status->isOK(),
543 "Deletion of file at $source failed ($backendName)." );
546 $this->assertEquals( false, $this->backend
->fileExists( array( 'src' => $source ) ),
547 "Source file $source does not exist after move ($backendName)." );
550 $this->backend
->getFileSize( array( 'src' => $source ) ),
551 "Source file $source has correct size (false) ($backendName)." );
553 $props1 = $this->backend
->getFileProps( array( 'src' => $source ) );
554 $this->assertFalse( $props1['fileExists'],
555 "Source file $source does not exist according to props ($backendName)." );
557 $this->assertBackendPathsConsistent( array( $source ) );
560 public static function provider_testDelete() {
563 $source = self
::baseStorePath() . '/unittest-cont1/e/myfacefile.txt';
565 $op = array( 'op' => 'delete', 'src' => $source );
574 false, // without source
578 $op['ignoreMissingSource'] = true;
581 false, // without source
589 * @dataProvider provider_testCreate
591 public function testCreate( $op, $alreadyExists, $okStatus, $newSize ) {
592 $this->backend
= $this->singleBackend
;
593 $this->tearDownFiles();
594 $this->doTestCreate( $op, $alreadyExists, $okStatus, $newSize );
595 $this->tearDownFiles();
597 $this->backend
= $this->multiBackend
;
598 $this->tearDownFiles();
599 $this->doTestCreate( $op, $alreadyExists, $okStatus, $newSize );
600 $this->tearDownFiles();
603 private function doTestCreate( $op, $alreadyExists, $okStatus, $newSize ) {
604 $backendName = $this->backendClass();
607 $this->prepare( array( 'dir' => dirname( $dest ) ) );
609 $oldText = 'blah...blah...waahwaah';
610 if ( $alreadyExists ) {
611 $status = $this->backend
->doOperation(
612 array( 'op' => 'create', 'content' => $oldText, 'dst' => $dest ) );
613 $this->assertGoodStatus( $status,
614 "Creation of file at $dest succeeded ($backendName)." );
617 $status = $this->backend
->doOperation( $op );
619 $this->assertGoodStatus( $status,
620 "Creation of file at $dest succeeded without warnings ($backendName)." );
621 $this->assertEquals( true, $status->isOK(),
622 "Creation of file at $dest succeeded ($backendName)." );
623 $this->assertEquals( array( 0 => true ), $status->success
,
624 "Creation of file at $dest has proper 'success' field in Status ($backendName)." );
626 $this->assertEquals( false, $status->isOK(),
627 "Creation of file at $dest failed ($backendName)." );
630 $this->assertEquals( true, $this->backend
->fileExists( array( 'src' => $dest ) ),
631 "Destination file $dest exists after creation ($backendName)." );
633 $props1 = $this->backend
->getFileProps( array( 'src' => $dest ) );
634 $this->assertEquals( true, $props1['fileExists'],
635 "Destination file $dest exists according to props ($backendName)." );
636 if ( $okStatus ) { // file content is what we saved
637 $this->assertEquals( $newSize, $props1['size'],
638 "Destination file $dest has expected size according to props ($backendName)." );
639 $this->assertEquals( $newSize,
640 $this->backend
->getFileSize( array( 'src' => $dest ) ),
641 "Destination file $dest has correct size ($backendName)." );
642 } else { // file content is some other previous text
643 $this->assertEquals( strlen( $oldText ), $props1['size'],
644 "Destination file $dest has original size according to props ($backendName)." );
645 $this->assertEquals( strlen( $oldText ),
646 $this->backend
->getFileSize( array( 'src' => $dest ) ),
647 "Destination file $dest has original size according to props ($backendName)." );
650 $this->assertBackendPathsConsistent( array( $dest ) );
654 * @dataProvider provider_testCreate
656 public static function provider_testCreate() {
659 $dest = self
::baseStorePath() . '/unittest-cont2/a/myspacefile.txt';
661 $op = array( 'op' => 'create', 'content' => 'test test testing', 'dst' => $dest );
664 false, // no dest already exists
666 strlen( $op['content'] )
670 $op2['content'] = "\n";
673 false, // no dest already exists
675 strlen( $op2['content'] )
679 $op2['content'] = "fsf\n waf 3kt";
682 true, // dest already exists
684 strlen( $op2['content'] )
688 $op2['content'] = "egm'g gkpe gpqg eqwgwqg";
689 $op2['overwrite'] = true;
692 true, // dest already exists
694 strlen( $op2['content'] )
698 $op2['content'] = "39qjmg3-qg";
699 $op2['overwriteSame'] = true;
702 true, // dest already exists
704 strlen( $op2['content'] )
710 public function testDoQuickOperations() {
711 $this->backend
= $this->singleBackend
;
712 $this->doTestDoQuickOperations();
713 $this->tearDownFiles();
715 $this->backend
= $this->multiBackend
;
716 $this->doTestDoQuickOperations();
717 $this->tearDownFiles();
720 private function doTestDoQuickOperations() {
721 $backendName = $this->backendClass();
723 $base = self
::baseStorePath();
725 "$base/unittest-cont1/e/fileA.a",
726 "$base/unittest-cont1/e/fileB.a",
727 "$base/unittest-cont1/e/fileC.a"
731 foreach ( $files as $path ) {
732 $status = $this->prepare( array( 'dir' => dirname( $path ) ) );
733 $this->assertGoodStatus( $status,
734 "Preparing $path succeeded without warnings ($backendName)." );
735 $ops[] = array( 'op' => 'create', 'dst' => $path, 'content' => mt_rand(0,50000) );
736 $purgeOps[] = array( 'op' => 'delete', 'src' => $path );
738 $purgeOps[] = array( 'op' => 'null' );
739 $status = $this->backend
->doQuickOperations( $ops );
740 $this->assertGoodStatus( $status,
741 "Creation of source files succeeded ($backendName)." );
743 foreach ( $files as $file ) {
744 $this->assertTrue( $this->backend
->fileExists( array( 'src' => $file ) ),
745 "File $file exists." );
748 $status = $this->backend
->doQuickOperations( $purgeOps );
749 $this->assertGoodStatus( $status,
750 "Quick deletion of source files succeeded ($backendName)." );
752 foreach ( $files as $file ) {
753 $this->assertFalse( $this->backend
->fileExists( array( 'src' => $file ) ),
754 "File $file purged." );
759 * @dataProvider provider_testConcatenate
761 public function testConcatenate( $op, $srcs, $srcsContent, $alreadyExists, $okStatus ) {
762 $this->filesToPrune
[] = $op['dst'];
764 $this->backend
= $this->singleBackend
;
765 $this->tearDownFiles();
766 $this->doTestConcatenate( $op, $srcs, $srcsContent, $alreadyExists, $okStatus );
767 $this->tearDownFiles();
769 $this->backend
= $this->multiBackend
;
770 $this->tearDownFiles();
771 $this->doTestConcatenate( $op, $srcs, $srcsContent, $alreadyExists, $okStatus );
772 $this->filesToPrune
[] = $op['dst']; # avoid file leaking
773 $this->tearDownFiles();
776 private function doTestConcatenate( $params, $srcs, $srcsContent, $alreadyExists, $okStatus ) {
777 $backendName = $this->backendClass();
782 foreach ( $srcs as $i => $source ) {
783 $this->prepare( array( 'dir' => dirname( $source ) ) );
785 'op' => 'create', // operation
786 'dst' => $source, // source
787 'content' => $srcsContent[$i]
789 $expContent .= $srcsContent[$i];
791 $status = $this->backend
->doOperations( $ops );
793 $this->assertGoodStatus( $status,
794 "Creation of source files succeeded ($backendName)." );
796 $dest = $params['dst'];
797 if ( $alreadyExists ) {
798 $ok = file_put_contents( $dest, 'blah...blah...waahwaah' ) !== false;
799 $this->assertEquals( true, $ok,
800 "Creation of file at $dest succeeded ($backendName)." );
802 $ok = file_put_contents( $dest, '' ) !== false;
803 $this->assertEquals( true, $ok,
804 "Creation of 0-byte file at $dest succeeded ($backendName)." );
807 // Combine the files into one
808 $status = $this->backend
->concatenate( $params );
810 $this->assertGoodStatus( $status,
811 "Creation of concat file at $dest succeeded without warnings ($backendName)." );
812 $this->assertEquals( true, $status->isOK(),
813 "Creation of concat file at $dest succeeded ($backendName)." );
815 $this->assertEquals( false, $status->isOK(),
816 "Creation of concat file at $dest failed ($backendName)." );
820 $this->assertEquals( true, is_file( $dest ),
821 "Dest concat file $dest exists after creation ($backendName)." );
823 $this->assertEquals( true, is_file( $dest ),
824 "Dest concat file $dest exists after failed creation ($backendName)." );
827 $contents = file_get_contents( $dest );
828 $this->assertNotEquals( false, $contents, "File at $dest exists ($backendName)." );
831 $this->assertEquals( $expContent, $contents,
832 "Concat file at $dest has correct contents ($backendName)." );
834 $this->assertNotEquals( $expContent, $contents,
835 "Concat file at $dest has correct contents ($backendName)." );
839 function provider_testConcatenate() {
842 $rand = mt_rand( 0, 2000000000 ) . time();
843 $dest = wfTempDir() . "/randomfile!$rand.txt";
845 self
::baseStorePath() . '/unittest-cont1/e/file1.txt',
846 self
::baseStorePath() . '/unittest-cont1/e/file2.txt',
847 self
::baseStorePath() . '/unittest-cont1/e/file3.txt',
848 self
::baseStorePath() . '/unittest-cont1/e/file4.txt',
849 self
::baseStorePath() . '/unittest-cont1/e/file5.txt',
850 self
::baseStorePath() . '/unittest-cont1/e/file6.txt',
851 self
::baseStorePath() . '/unittest-cont1/e/file7.txt',
852 self
::baseStorePath() . '/unittest-cont1/e/file8.txt',
853 self
::baseStorePath() . '/unittest-cont1/e/file9.txt',
854 self
::baseStorePath() . '/unittest-cont1/e/file10.txt'
868 $params = array( 'srcs' => $srcs, 'dst' => $dest );
871 $params, // operation
873 $content, // content for each source
874 false, // no dest already exists
879 $params, // operation
881 $content, // content for each source
882 true, // dest already exists
890 * @dataProvider provider_testGetFileStat
892 public function testGetFileStat( $path, $content, $alreadyExists ) {
893 $this->backend
= $this->singleBackend
;
894 $this->tearDownFiles();
895 $this->doTestGetFileStat( $path, $content, $alreadyExists );
896 $this->tearDownFiles();
898 $this->backend
= $this->multiBackend
;
899 $this->tearDownFiles();
900 $this->doTestGetFileStat( $path, $content, $alreadyExists );
901 $this->tearDownFiles();
904 private function doTestGetFileStat( $path, $content, $alreadyExists ) {
905 $backendName = $this->backendClass();
907 if ( $alreadyExists ) {
908 $this->prepare( array( 'dir' => dirname( $path ) ) );
909 $status = $this->create( array( 'dst' => $path, 'content' => $content ) );
910 $this->assertGoodStatus( $status,
911 "Creation of file at $path succeeded ($backendName)." );
913 $size = $this->backend
->getFileSize( array( 'src' => $path ) );
914 $time = $this->backend
->getFileTimestamp( array( 'src' => $path ) );
915 $stat = $this->backend
->getFileStat( array( 'src' => $path ) );
917 $this->assertEquals( strlen( $content ), $size,
918 "Correct file size of '$path'" );
919 $this->assertTrue( abs( time() - wfTimestamp( TS_UNIX
, $time ) ) < 10,
920 "Correct file timestamp of '$path'" );
922 $size = $stat['size'];
923 $time = $stat['mtime'];
924 $this->assertEquals( strlen( $content ), $size,
925 "Correct file size of '$path'" );
926 $this->assertTrue( abs( time() - wfTimestamp( TS_UNIX
, $time ) ) < 10,
927 "Correct file timestamp of '$path'" );
929 $this->backend
->clearCache( array( $path ) );
931 $size = $this->backend
->getFileSize( array( 'src' => $path ) );
933 $this->assertEquals( strlen( $content ), $size,
934 "Correct file size of '$path'" );
936 $this->backend
->preloadCache( array( $path ) );
938 $size = $this->backend
->getFileSize( array( 'src' => $path ) );
940 $this->assertEquals( strlen( $content ), $size,
941 "Correct file size of '$path'" );
943 $size = $this->backend
->getFileSize( array( 'src' => $path ) );
944 $time = $this->backend
->getFileTimestamp( array( 'src' => $path ) );
945 $stat = $this->backend
->getFileStat( array( 'src' => $path ) );
947 $this->assertFalse( $size, "Correct file size of '$path'" );
948 $this->assertFalse( $time, "Correct file timestamp of '$path'" );
949 $this->assertFalse( $stat, "Correct file stat of '$path'" );
953 function provider_testGetFileStat() {
956 $base = self
::baseStorePath();
957 $cases[] = array( "$base/unittest-cont1/e/b/z/some_file.txt", "some file contents", true );
958 $cases[] = array( "$base/unittest-cont1/e/b/some-other_file.txt", "", true );
959 $cases[] = array( "$base/unittest-cont1/e/b/some-diff_file.txt", null, false );
965 * @dataProvider provider_testGetFileContents
967 public function testGetFileContents( $source, $content ) {
968 $this->backend
= $this->singleBackend
;
969 $this->tearDownFiles();
970 $this->doTestGetFileContents( $source, $content );
971 $this->tearDownFiles();
973 $this->backend
= $this->multiBackend
;
974 $this->tearDownFiles();
975 $this->doTestGetFileContents( $source, $content );
976 $this->tearDownFiles();
979 private function doTestGetFileContents( $source, $content ) {
980 $backendName = $this->backendClass();
982 $srcs = (array)$source;
983 $content = (array)$content;
984 foreach ( $srcs as $i => $src ) {
985 $this->prepare( array( 'dir' => dirname( $src ) ) );
986 $status = $this->backend
->doOperation(
987 array( 'op' => 'create', 'content' => $content[$i], 'dst' => $src ) );
988 $this->assertGoodStatus( $status,
989 "Creation of file at $src succeeded ($backendName)." );
992 if ( is_array( $source ) ) {
993 $contents = $this->backend
->getFileContentsMulti( array( 'srcs' => $source ) );
994 foreach ( $contents as $path => $data ) {
995 $this->assertNotEquals( false, $data, "Contents of $path exists ($backendName)." );
996 $this->assertEquals( current( $content ), $data, "Contents of $path is correct ($backendName)." );
999 $this->assertEquals( $source, array_keys( $contents ), "Contents in right order ($backendName)." );
1000 $this->assertEquals( count( $source ), count( $contents ), "Contents array size correct ($backendName)." );
1002 $data = $this->backend
->getFileContents( array( 'src' => $source ) );
1003 $this->assertNotEquals( false, $data, "Contents of $source exists ($backendName)." );
1004 $this->assertEquals( $content[0], $data, "Contents of $source is correct ($backendName)." );
1008 function provider_testGetFileContents() {
1011 $base = self
::baseStorePath();
1012 $cases[] = array( "$base/unittest-cont1/e/b/z/some_file.txt", "some file contents" );
1013 $cases[] = array( "$base/unittest-cont1/e/b/some-other_file.txt", "more file contents" );
1015 array( "$base/unittest-cont1/e/a/x.txt", "$base/unittest-cont1/e/a/y.txt",
1016 "$base/unittest-cont1/e/a/z.txt" ),
1017 array( "contents xx", "contents xy", "contents xz" )
1024 * @dataProvider provider_testGetLocalCopy
1026 public function testGetLocalCopy( $source, $content ) {
1027 $this->backend
= $this->singleBackend
;
1028 $this->tearDownFiles();
1029 $this->doTestGetLocalCopy( $source, $content );
1030 $this->tearDownFiles();
1032 $this->backend
= $this->multiBackend
;
1033 $this->tearDownFiles();
1034 $this->doTestGetLocalCopy( $source, $content );
1035 $this->tearDownFiles();
1038 private function doTestGetLocalCopy( $source, $content ) {
1039 $backendName = $this->backendClass();
1041 $srcs = (array)$source;
1042 $content = (array)$content;
1043 foreach ( $srcs as $i => $src ) {
1044 $this->prepare( array( 'dir' => dirname( $src ) ) );
1045 $status = $this->backend
->doOperation(
1046 array( 'op' => 'create', 'content' => $content[$i], 'dst' => $src ) );
1047 $this->assertGoodStatus( $status,
1048 "Creation of file at $src succeeded ($backendName)." );
1051 if ( is_array( $source ) ) {
1052 $tmpFiles = $this->backend
->getLocalCopyMulti( array( 'srcs' => $source ) );
1053 foreach ( $tmpFiles as $path => $tmpFile ) {
1054 $this->assertNotNull( $tmpFile,
1055 "Creation of local copy of $path succeeded ($backendName)." );
1056 $contents = file_get_contents( $tmpFile->getPath() );
1057 $this->assertNotEquals( false, $contents, "Local copy of $path exists ($backendName)." );
1058 $this->assertEquals( current( $content ), $contents, "Local copy of $path is correct ($backendName)." );
1061 $this->assertEquals( $source, array_keys( $tmpFiles ), "Local copies in right order ($backendName)." );
1062 $this->assertEquals( count( $source ), count( $tmpFiles ), "Local copies array size correct ($backendName)." );
1064 $tmpFile = $this->backend
->getLocalCopy( array( 'src' => $source ) );
1065 $this->assertNotNull( $tmpFile,
1066 "Creation of local copy of $source succeeded ($backendName)." );
1067 $contents = file_get_contents( $tmpFile->getPath() );
1068 $this->assertNotEquals( false, $contents, "Local copy of $source exists ($backendName)." );
1069 $this->assertEquals( $content[0], $contents, "Local copy of $source is correct ($backendName)." );
1072 $obj = new stdClass();
1073 $tmpFile->bind( $obj );
1076 function provider_testGetLocalCopy() {
1079 $base = self
::baseStorePath();
1080 $cases[] = array( "$base/unittest-cont1/e/a/z/some_file.txt", "some file contents" );
1081 $cases[] = array( "$base/unittest-cont1/e/a/some-other_file.txt", "more file contents" );
1082 $cases[] = array( "$base/unittest-cont1/e/a/\$odd&.txt", "test file contents" );
1084 array( "$base/unittest-cont1/e/a/x.txt", "$base/unittest-cont1/e/a/y.txt",
1085 "$base/unittest-cont1/e/a/z.txt" ),
1086 array( "contents xx", "contents xy", "contents xz" )
1093 * @dataProvider provider_testGetLocalReference
1095 public function testGetLocalReference( $source, $content ) {
1096 $this->backend
= $this->singleBackend
;
1097 $this->tearDownFiles();
1098 $this->doTestGetLocalReference( $source, $content );
1099 $this->tearDownFiles();
1101 $this->backend
= $this->multiBackend
;
1102 $this->tearDownFiles();
1103 $this->doTestGetLocalReference( $source, $content );
1104 $this->tearDownFiles();
1107 private function doTestGetLocalReference( $source, $content ) {
1108 $backendName = $this->backendClass();
1110 $srcs = (array)$source;
1111 $content = (array)$content;
1112 foreach ( $srcs as $i => $src ) {
1113 $this->prepare( array( 'dir' => dirname( $src ) ) );
1114 $status = $this->backend
->doOperation(
1115 array( 'op' => 'create', 'content' => $content[$i], 'dst' => $src ) );
1116 $this->assertGoodStatus( $status,
1117 "Creation of file at $src succeeded ($backendName)." );
1120 if ( is_array( $source ) ) {
1121 $tmpFiles = $this->backend
->getLocalReferenceMulti( array( 'srcs' => $source ) );
1122 foreach ( $tmpFiles as $path => $tmpFile ) {
1123 $this->assertNotNull( $tmpFile,
1124 "Creation of local copy of $path succeeded ($backendName)." );
1125 $contents = file_get_contents( $tmpFile->getPath() );
1126 $this->assertNotEquals( false, $contents, "Local ref of $path exists ($backendName)." );
1127 $this->assertEquals( current( $content ), $contents, "Local ref of $path is correct ($backendName)." );
1130 $this->assertEquals( $source, array_keys( $tmpFiles ), "Local refs in right order ($backendName)." );
1131 $this->assertEquals( count( $source ), count( $tmpFiles ), "Local refs array size correct ($backendName)." );
1133 $tmpFile = $this->backend
->getLocalReference( array( 'src' => $source ) );
1134 $this->assertNotNull( $tmpFile,
1135 "Creation of local copy of $source succeeded ($backendName)." );
1136 $contents = file_get_contents( $tmpFile->getPath() );
1137 $this->assertNotEquals( false, $contents, "Local ref of $source exists ($backendName)." );
1138 $this->assertEquals( $content[0], $contents, "Local ref of $source is correct ($backendName)." );
1142 function provider_testGetLocalReference() {
1145 $base = self
::baseStorePath();
1146 $cases[] = array( "$base/unittest-cont1/e/a/z/some_file.txt", "some file contents" );
1147 $cases[] = array( "$base/unittest-cont1/e/a/some-other_file.txt", "more file contents" );
1148 $cases[] = array( "$base/unittest-cont1/e/a/\$odd&.txt", "test file contents" );
1150 array( "$base/unittest-cont1/e/a/x.txt", "$base/unittest-cont1/e/a/y.txt",
1151 "$base/unittest-cont1/e/a/z.txt" ),
1152 array( "contents xx", "contents xy", "contents xz" )
1158 public function testGetLocalCopyAndReference404() {
1159 $this->backend
= $this->singleBackend
;
1160 $this->tearDownFiles();
1161 $this->doTestGetLocalCopyAndReference404();
1162 $this->tearDownFiles();
1164 $this->backend
= $this->multiBackend
;
1165 $this->tearDownFiles();
1166 $this->doTestGetLocalCopyAndReference404();
1167 $this->tearDownFiles();
1170 public function doTestGetLocalCopyAndReference404() {
1171 $backendName = $this->backendClass();
1173 $base = self
::baseStorePath();
1175 $tmpFile = $this->backend
->getLocalCopy( array(
1176 'src' => "$base/unittest-cont1/not-there" ) );
1177 $this->assertEquals( null, $tmpFile, "Local copy of not existing file is null ($backendName)." );
1179 $tmpFile = $this->backend
->getLocalReference( array(
1180 'src' => "$base/unittest-cont1/not-there" ) );
1181 $this->assertEquals( null, $tmpFile, "Local ref of not existing file is null ($backendName)." );
1185 * @dataProvider provider_testGetFileHttpUrl
1187 public function testGetFileHttpUrl( $source, $content ) {
1188 $this->backend
= $this->singleBackend
;
1189 $this->tearDownFiles();
1190 $this->doTestGetFileHttpUrl( $source, $content );
1191 $this->tearDownFiles();
1193 $this->backend
= $this->multiBackend
;
1194 $this->tearDownFiles();
1195 $this->doTestGetFileHttpUrl( $source, $content );
1196 $this->tearDownFiles();
1199 private function doTestGetFileHttpUrl( $source, $content ) {
1200 $backendName = $this->backendClass();
1202 $this->prepare( array( 'dir' => dirname( $source ) ) );
1203 $status = $this->backend
->doOperation(
1204 array( 'op' => 'create', 'content' => $content, 'dst' => $source ) );
1205 $this->assertGoodStatus( $status,
1206 "Creation of file at $source succeeded ($backendName)." );
1208 $url = $this->backend
->getFileHttpUrl( array( 'src' => $source ) );
1210 if ( $url !== null ) { // supported
1211 $data = Http
::request( "GET", $url );
1212 $this->assertEquals( $content, $data,
1213 "HTTP GET of URL has right contents ($backendName)." );
1217 function provider_testGetFileHttpUrl() {
1220 $base = self
::baseStorePath();
1221 $cases[] = array( "$base/unittest-cont1/e/a/z/some_file.txt", "some file contents" );
1222 $cases[] = array( "$base/unittest-cont1/e/a/some-other_file.txt", "more file contents" );
1223 $cases[] = array( "$base/unittest-cont1/e/a/\$odd&.txt", "test file contents" );
1229 * @dataProvider provider_testPrepareAndClean
1231 public function testPrepareAndClean( $path, $isOK ) {
1232 $this->backend
= $this->singleBackend
;
1233 $this->doTestPrepareAndClean( $path, $isOK );
1234 $this->tearDownFiles();
1236 $this->backend
= $this->multiBackend
;
1237 $this->doTestPrepareAndClean( $path, $isOK );
1238 $this->tearDownFiles();
1241 function provider_testPrepareAndClean() {
1242 $base = self
::baseStorePath();
1244 array( "$base/unittest-cont1/e/a/z/some_file1.txt", true ),
1245 array( "$base/unittest-cont2/a/z/some_file2.txt", true ),
1246 # Specific to FS backend with no basePath field set
1247 #array( "$base/unittest-cont3/a/z/some_file3.txt", false ),
1251 private function doTestPrepareAndClean( $path, $isOK ) {
1252 $backendName = $this->backendClass();
1254 $status = $this->prepare( array( 'dir' => dirname( $path ) ) );
1256 $this->assertGoodStatus( $status,
1257 "Preparing dir $path succeeded without warnings ($backendName)." );
1258 $this->assertEquals( true, $status->isOK(),
1259 "Preparing dir $path succeeded ($backendName)." );
1261 $this->assertEquals( false, $status->isOK(),
1262 "Preparing dir $path failed ($backendName)." );
1265 $status = $this->backend
->clean( array( 'dir' => dirname( $path ) ) );
1267 $this->assertGoodStatus( $status,
1268 "Cleaning dir $path succeeded without warnings ($backendName)." );
1269 $this->assertEquals( true, $status->isOK(),
1270 "Cleaning dir $path succeeded ($backendName)." );
1272 $this->assertEquals( false, $status->isOK(),
1273 "Cleaning dir $path failed ($backendName)." );
1277 public function testRecursiveClean() {
1278 $this->backend
= $this->singleBackend
;
1279 $this->doTestRecursiveClean();
1280 $this->tearDownFiles();
1282 $this->backend
= $this->multiBackend
;
1283 $this->doTestRecursiveClean();
1284 $this->tearDownFiles();
1287 private function doTestRecursiveClean() {
1288 $backendName = $this->backendClass();
1290 $base = self
::baseStorePath();
1292 "$base/unittest-cont1/e/a",
1293 "$base/unittest-cont1/e/a/b",
1294 "$base/unittest-cont1/e/a/b/c",
1295 "$base/unittest-cont1/e/a/b/c/d0",
1296 "$base/unittest-cont1/e/a/b/c/d1",
1297 "$base/unittest-cont1/e/a/b/c/d2",
1298 "$base/unittest-cont1/e/a/b/c/d0/1",
1299 "$base/unittest-cont1/e/a/b/c/d0/2",
1300 "$base/unittest-cont1/e/a/b/c/d1/3",
1301 "$base/unittest-cont1/e/a/b/c/d1/4",
1302 "$base/unittest-cont1/e/a/b/c/d2/5",
1303 "$base/unittest-cont1/e/a/b/c/d2/6"
1305 foreach ( $dirs as $dir ) {
1306 $status = $this->prepare( array( 'dir' => $dir ) );
1307 $this->assertGoodStatus( $status,
1308 "Preparing dir $dir succeeded without warnings ($backendName)." );
1311 if ( $this->backend
instanceof FSFileBackend
) {
1312 foreach ( $dirs as $dir ) {
1313 $this->assertEquals( true, $this->backend
->directoryExists( array( 'dir' => $dir ) ),
1314 "Dir $dir exists ($backendName)." );
1318 $status = $this->backend
->clean(
1319 array( 'dir' => "$base/unittest-cont1", 'recursive' => 1 ) );
1320 $this->assertGoodStatus( $status,
1321 "Recursive cleaning of dir $dir succeeded without warnings ($backendName)." );
1323 foreach ( $dirs as $dir ) {
1324 $this->assertEquals( false, $this->backend
->directoryExists( array( 'dir' => $dir ) ),
1325 "Dir $dir no longer exists ($backendName)." );
1329 // @TODO: testSecure
1331 public function testDoOperations() {
1332 $this->backend
= $this->singleBackend
;
1333 $this->tearDownFiles();
1334 $this->doTestDoOperations();
1335 $this->tearDownFiles();
1337 $this->backend
= $this->multiBackend
;
1338 $this->tearDownFiles();
1339 $this->doTestDoOperations();
1340 $this->tearDownFiles();
1343 private function doTestDoOperations() {
1344 $base = self
::baseStorePath();
1346 $fileA = "$base/unittest-cont1/e/a/b/fileA.txt";
1347 $fileAContents = '3tqtmoeatmn4wg4qe-mg3qt3 tq';
1348 $fileB = "$base/unittest-cont1/e/a/b/fileB.txt";
1349 $fileBContents = 'g-jmq3gpqgt3qtg q3GT ';
1350 $fileC = "$base/unittest-cont1/e/a/b/fileC.txt";
1351 $fileCContents = 'eigna[ogmewt 3qt g3qg flew[ag';
1352 $fileD = "$base/unittest-cont1/e/a/b/fileD.txt";
1354 $this->prepare( array( 'dir' => dirname( $fileA ) ) );
1355 $this->create( array( 'dst' => $fileA, 'content' => $fileAContents ) );
1356 $this->prepare( array( 'dir' => dirname( $fileB ) ) );
1357 $this->create( array( 'dst' => $fileB, 'content' => $fileBContents ) );
1358 $this->prepare( array( 'dir' => dirname( $fileC ) ) );
1359 $this->create( array( 'dst' => $fileC, 'content' => $fileCContents ) );
1360 $this->prepare( array( 'dir' => dirname( $fileD ) ) );
1362 $status = $this->backend
->doOperations( array(
1363 array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC, 'overwrite' => 1 ),
1364 // Now: A:<A>, B:<B>, C:<A>, D:<empty> (file:<orginal contents>)
1365 array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileA, 'overwriteSame' => 1 ),
1366 // Now: A:<A>, B:<B>, C:<A>, D:<empty>
1367 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileD, 'overwrite' => 1 ),
1368 // Now: A:<A>, B:<B>, C:<empty>, D:<A>
1369 array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileC ),
1370 // Now: A:<A>, B:<empty>, C:<B>, D:<A>
1371 array( 'op' => 'move', 'src' => $fileD, 'dst' => $fileA, 'overwriteSame' => 1 ),
1372 // Now: A:<A>, B:<empty>, C:<B>, D:<empty>
1373 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileA, 'overwrite' => 1 ),
1374 // Now: A:<B>, B:<empty>, C:<empty>, D:<empty>
1375 array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC ),
1376 // Now: A:<B>, B:<empty>, C:<B>, D:<empty>
1377 array( 'op' => 'move', 'src' => $fileA, 'dst' => $fileC, 'overwriteSame' => 1 ),
1378 // Now: A:<empty>, B:<empty>, C:<B>, D:<empty>
1379 array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileC, 'overwrite' => 1 ),
1381 array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileC, 'overwriteSame' => 1 ),
1383 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileC, 'overwrite' => 1 ),
1385 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileC, 'overwriteSame' => 1 ),
1387 array( 'op' => 'null' ),
1391 $this->assertGoodStatus( $status, "Operation batch succeeded" );
1392 $this->assertEquals( true, $status->isOK(), "Operation batch succeeded" );
1393 $this->assertEquals( 13, count( $status->success
),
1394 "Operation batch has correct success array" );
1396 $this->assertEquals( false, $this->backend
->fileExists( array( 'src' => $fileA ) ),
1397 "File does not exist at $fileA" );
1398 $this->assertEquals( false, $this->backend
->fileExists( array( 'src' => $fileB ) ),
1399 "File does not exist at $fileB" );
1400 $this->assertEquals( false, $this->backend
->fileExists( array( 'src' => $fileD ) ),
1401 "File does not exist at $fileD" );
1403 $this->assertEquals( true, $this->backend
->fileExists( array( 'src' => $fileC ) ),
1404 "File exists at $fileC" );
1405 $this->assertEquals( $fileBContents,
1406 $this->backend
->getFileContents( array( 'src' => $fileC ) ),
1407 "Correct file contents of $fileC" );
1408 $this->assertEquals( strlen( $fileBContents ),
1409 $this->backend
->getFileSize( array( 'src' => $fileC ) ),
1410 "Correct file size of $fileC" );
1411 $this->assertEquals( wfBaseConvert( sha1( $fileBContents ), 16, 36, 31 ),
1412 $this->backend
->getFileSha1Base36( array( 'src' => $fileC ) ),
1413 "Correct file SHA-1 of $fileC" );
1416 public function testDoOperationsPipeline() {
1417 $this->backend
= $this->singleBackend
;
1418 $this->tearDownFiles();
1419 $this->doTestDoOperationsPipeline();
1420 $this->tearDownFiles();
1422 $this->backend
= $this->multiBackend
;
1423 $this->tearDownFiles();
1424 $this->doTestDoOperationsPipeline();
1425 $this->tearDownFiles();
1428 // concurrency orientated
1429 private function doTestDoOperationsPipeline() {
1430 $base = self
::baseStorePath();
1432 $fileAContents = '3tqtmoeatmn4wg4qe-mg3qt3 tq';
1433 $fileBContents = 'g-jmq3gpqgt3qtg q3GT ';
1434 $fileCContents = 'eigna[ogmewt 3qt g3qg flew[ag';
1436 $tmpNameA = TempFSFile
::factory( "unittests_", 'txt' )->getPath();
1437 file_put_contents( $tmpNameA, $fileAContents );
1438 $tmpNameB = TempFSFile
::factory( "unittests_", 'txt' )->getPath();
1439 file_put_contents( $tmpNameB, $fileBContents );
1440 $tmpNameC = TempFSFile
::factory( "unittests_", 'txt' )->getPath();
1441 file_put_contents( $tmpNameC, $fileCContents );
1443 $this->filesToPrune
[] = $tmpNameA; # avoid file leaking
1444 $this->filesToPrune
[] = $tmpNameB; # avoid file leaking
1445 $this->filesToPrune
[] = $tmpNameC; # avoid file leaking
1447 $fileA = "$base/unittest-cont1/e/a/b/fileA.txt";
1448 $fileB = "$base/unittest-cont1/e/a/b/fileB.txt";
1449 $fileC = "$base/unittest-cont1/e/a/b/fileC.txt";
1450 $fileD = "$base/unittest-cont1/e/a/b/fileD.txt";
1452 $this->prepare( array( 'dir' => dirname( $fileA ) ) );
1453 $this->create( array( 'dst' => $fileA, 'content' => $fileAContents ) );
1454 $this->prepare( array( 'dir' => dirname( $fileB ) ) );
1455 $this->prepare( array( 'dir' => dirname( $fileC ) ) );
1456 $this->prepare( array( 'dir' => dirname( $fileD ) ) );
1458 $status = $this->backend
->doOperations( array(
1459 array( 'op' => 'store', 'src' => $tmpNameA, 'dst' => $fileA, 'overwriteSame' => 1 ),
1460 array( 'op' => 'store', 'src' => $tmpNameB, 'dst' => $fileB, 'overwrite' => 1 ),
1461 array( 'op' => 'store', 'src' => $tmpNameC, 'dst' => $fileC, 'overwrite' => 1 ),
1462 array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC, 'overwrite' => 1 ),
1463 // Now: A:<A>, B:<B>, C:<A>, D:<empty> (file:<orginal contents>)
1464 array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileA, 'overwriteSame' => 1 ),
1465 // Now: A:<A>, B:<B>, C:<A>, D:<empty>
1466 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileD, 'overwrite' => 1 ),
1467 // Now: A:<A>, B:<B>, C:<empty>, D:<A>
1468 array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileC ),
1469 // Now: A:<A>, B:<empty>, C:<B>, D:<A>
1470 array( 'op' => 'move', 'src' => $fileD, 'dst' => $fileA, 'overwriteSame' => 1 ),
1471 // Now: A:<A>, B:<empty>, C:<B>, D:<empty>
1472 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileA, 'overwrite' => 1 ),
1473 // Now: A:<B>, B:<empty>, C:<empty>, D:<empty>
1474 array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC ),
1475 // Now: A:<B>, B:<empty>, C:<B>, D:<empty>
1476 array( 'op' => 'move', 'src' => $fileA, 'dst' => $fileC, 'overwriteSame' => 1 ),
1477 // Now: A:<empty>, B:<empty>, C:<B>, D:<empty>
1478 array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileC, 'overwrite' => 1 ),
1480 array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileC, 'overwriteSame' => 1 ),
1482 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileC, 'overwrite' => 1 ),
1484 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileC, 'overwriteSame' => 1 ),
1486 array( 'op' => 'null' ),
1490 $this->assertGoodStatus( $status, "Operation batch succeeded" );
1491 $this->assertEquals( true, $status->isOK(), "Operation batch succeeded" );
1492 $this->assertEquals( 16, count( $status->success
),
1493 "Operation batch has correct success array" );
1495 $this->assertEquals( false, $this->backend
->fileExists( array( 'src' => $fileA ) ),
1496 "File does not exist at $fileA" );
1497 $this->assertEquals( false, $this->backend
->fileExists( array( 'src' => $fileB ) ),
1498 "File does not exist at $fileB" );
1499 $this->assertEquals( false, $this->backend
->fileExists( array( 'src' => $fileD ) ),
1500 "File does not exist at $fileD" );
1502 $this->assertEquals( true, $this->backend
->fileExists( array( 'src' => $fileC ) ),
1503 "File exists at $fileC" );
1504 $this->assertEquals( $fileBContents,
1505 $this->backend
->getFileContents( array( 'src' => $fileC ) ),
1506 "Correct file contents of $fileC" );
1507 $this->assertEquals( strlen( $fileBContents ),
1508 $this->backend
->getFileSize( array( 'src' => $fileC ) ),
1509 "Correct file size of $fileC" );
1510 $this->assertEquals( wfBaseConvert( sha1( $fileBContents ), 16, 36, 31 ),
1511 $this->backend
->getFileSha1Base36( array( 'src' => $fileC ) ),
1512 "Correct file SHA-1 of $fileC" );
1515 public function testDoOperationsFailing() {
1516 $this->backend
= $this->singleBackend
;
1517 $this->tearDownFiles();
1518 $this->doTestDoOperationsFailing();
1519 $this->tearDownFiles();
1521 $this->backend
= $this->multiBackend
;
1522 $this->tearDownFiles();
1523 $this->doTestDoOperationsFailing();
1524 $this->tearDownFiles();
1527 private function doTestDoOperationsFailing() {
1528 $base = self
::baseStorePath();
1530 $fileA = "$base/unittest-cont2/a/b/fileA.txt";
1531 $fileAContents = '3tqtmoeatmn4wg4qe-mg3qt3 tq';
1532 $fileB = "$base/unittest-cont2/a/b/fileB.txt";
1533 $fileBContents = 'g-jmq3gpqgt3qtg q3GT ';
1534 $fileC = "$base/unittest-cont2/a/b/fileC.txt";
1535 $fileCContents = 'eigna[ogmewt 3qt g3qg flew[ag';
1536 $fileD = "$base/unittest-cont2/a/b/fileD.txt";
1538 $this->prepare( array( 'dir' => dirname( $fileA ) ) );
1539 $this->create( array( 'dst' => $fileA, 'content' => $fileAContents ) );
1540 $this->prepare( array( 'dir' => dirname( $fileB ) ) );
1541 $this->create( array( 'dst' => $fileB, 'content' => $fileBContents ) );
1542 $this->prepare( array( 'dir' => dirname( $fileC ) ) );
1543 $this->create( array( 'dst' => $fileC, 'content' => $fileCContents ) );
1545 $status = $this->backend
->doOperations( array(
1546 array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC, 'overwrite' => 1 ),
1547 // Now: A:<A>, B:<B>, C:<A>, D:<empty> (file:<orginal contents>)
1548 array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileA, 'overwriteSame' => 1 ),
1549 // Now: A:<A>, B:<B>, C:<A>, D:<empty>
1550 array( 'op' => 'copy', 'src' => $fileB, 'dst' => $fileD, 'overwrite' => 1 ),
1551 // Now: A:<A>, B:<B>, C:<A>, D:<B>
1552 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileD ),
1553 // Now: A:<A>, B:<B>, C:<A>, D:<empty> (failed)
1554 array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileC, 'overwriteSame' => 1 ),
1555 // Now: A:<A>, B:<B>, C:<A>, D:<empty> (failed)
1556 array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileA, 'overwrite' => 1 ),
1557 // Now: A:<B>, B:<empty>, C:<A>, D:<empty>
1558 array( 'op' => 'delete', 'src' => $fileD ),
1559 // Now: A:<B>, B:<empty>, C:<A>, D:<empty>
1560 array( 'op' => 'null' ),
1562 ), array( 'force' => 1 ) );
1564 $this->assertNotEquals( array(), $status->errors
, "Operation had warnings" );
1565 $this->assertEquals( true, $status->isOK(), "Operation batch succeeded" );
1566 $this->assertEquals( 8, count( $status->success
),
1567 "Operation batch has correct success array" );
1569 $this->assertEquals( false, $this->backend
->fileExists( array( 'src' => $fileB ) ),
1570 "File does not exist at $fileB" );
1571 $this->assertEquals( false, $this->backend
->fileExists( array( 'src' => $fileD ) ),
1572 "File does not exist at $fileD" );
1574 $this->assertEquals( true, $this->backend
->fileExists( array( 'src' => $fileA ) ),
1575 "File does not exist at $fileA" );
1576 $this->assertEquals( true, $this->backend
->fileExists( array( 'src' => $fileC ) ),
1577 "File exists at $fileC" );
1578 $this->assertEquals( $fileBContents,
1579 $this->backend
->getFileContents( array( 'src' => $fileA ) ),
1580 "Correct file contents of $fileA" );
1581 $this->assertEquals( strlen( $fileBContents ),
1582 $this->backend
->getFileSize( array( 'src' => $fileA ) ),
1583 "Correct file size of $fileA" );
1584 $this->assertEquals( wfBaseConvert( sha1( $fileBContents ), 16, 36, 31 ),
1585 $this->backend
->getFileSha1Base36( array( 'src' => $fileA ) ),
1586 "Correct file SHA-1 of $fileA" );
1589 public function testGetFileList() {
1590 $this->backend
= $this->singleBackend
;
1591 $this->tearDownFiles();
1592 $this->doTestGetFileList();
1593 $this->tearDownFiles();
1595 $this->backend
= $this->multiBackend
;
1596 $this->tearDownFiles();
1597 $this->doTestGetFileList();
1598 $this->tearDownFiles();
1601 private function doTestGetFileList() {
1602 $backendName = $this->backendClass();
1603 $base = self
::baseStorePath();
1605 // Should have no errors
1606 $iter = $this->backend
->getFileList( array( 'dir' => "$base/unittest-cont-notexists" ) );
1609 "$base/unittest-cont1/e/test1.txt",
1610 "$base/unittest-cont1/e/test2.txt",
1611 "$base/unittest-cont1/e/test3.txt",
1612 "$base/unittest-cont1/e/subdir1/test1.txt",
1613 "$base/unittest-cont1/e/subdir1/test2.txt",
1614 "$base/unittest-cont1/e/subdir2/test3.txt",
1615 "$base/unittest-cont1/e/subdir2/test4.txt",
1616 "$base/unittest-cont1/e/subdir2/subdir/test1.txt",
1617 "$base/unittest-cont1/e/subdir2/subdir/test2.txt",
1618 "$base/unittest-cont1/e/subdir2/subdir/test3.txt",
1619 "$base/unittest-cont1/e/subdir2/subdir/test4.txt",
1620 "$base/unittest-cont1/e/subdir2/subdir/test5.txt",
1621 "$base/unittest-cont1/e/subdir2/subdir/sub/test0.txt",
1622 "$base/unittest-cont1/e/subdir2/subdir/sub/120-px-file.txt",
1627 foreach ( $files as $file ) {
1628 $this->prepare( array( 'dir' => dirname( $file ) ) );
1629 $ops[] = array( 'op' => 'create', 'content' => 'xxy', 'dst' => $file );
1631 $status = $this->backend
->doQuickOperations( $ops );
1632 $this->assertGoodStatus( $status,
1633 "Creation of files succeeded ($backendName)." );
1634 $this->assertEquals( true, $status->isOK(),
1635 "Creation of files succeeded with OK status ($backendName)." );
1642 "e/subdir1/test1.txt",
1643 "e/subdir1/test2.txt",
1644 "e/subdir2/test3.txt",
1645 "e/subdir2/test4.txt",
1646 "e/subdir2/subdir/test1.txt",
1647 "e/subdir2/subdir/test2.txt",
1648 "e/subdir2/subdir/test3.txt",
1649 "e/subdir2/subdir/test4.txt",
1650 "e/subdir2/subdir/test5.txt",
1651 "e/subdir2/subdir/sub/test0.txt",
1652 "e/subdir2/subdir/sub/120-px-file.txt",
1656 // Actual listing (no trailing slash)
1658 $iter = $this->backend
->getFileList( array( 'dir' => "$base/unittest-cont1" ) );
1659 foreach ( $iter as $file ) {
1664 $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
1666 // Actual listing (with trailing slash)
1668 $iter = $this->backend
->getFileList( array( 'dir' => "$base/unittest-cont1/" ) );
1669 foreach ( $iter as $file ) {
1674 $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
1684 "sub/120-px-file.txt",
1688 // Actual listing (no trailing slash)
1690 $iter = $this->backend
->getFileList( array( 'dir' => "$base/unittest-cont1/e/subdir2/subdir" ) );
1691 foreach ( $iter as $file ) {
1696 $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
1698 // Actual listing (with trailing slash)
1700 $iter = $this->backend
->getFileList( array( 'dir' => "$base/unittest-cont1/e/subdir2/subdir/" ) );
1701 foreach ( $iter as $file ) {
1706 $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
1708 // Actual listing (using iterator second time)
1710 foreach ( $iter as $file ) {
1715 $this->assertEquals( $expected, $list, "Correct file listing ($backendName), second iteration." );
1717 // Expected listing (top files only)
1727 // Actual listing (top files only)
1729 $iter = $this->backend
->getTopFileList( array( 'dir' => "$base/unittest-cont1/e/subdir2/subdir" ) );
1730 foreach ( $iter as $file ) {
1735 $this->assertEquals( $expected, $list, "Correct top file listing ($backendName)." );
1737 foreach ( $files as $file ) { // clean up
1738 $this->backend
->doOperation( array( 'op' => 'delete', 'src' => $file ) );
1741 $iter = $this->backend
->getFileList( array( 'dir' => "$base/unittest-cont1/not/exists" ) );
1742 foreach ( $iter as $iter ) {} // no errors
1745 public function testGetDirectoryList() {
1746 $this->backend
= $this->singleBackend
;
1747 $this->tearDownFiles();
1748 $this->doTestGetDirectoryList();
1749 $this->tearDownFiles();
1751 $this->backend
= $this->multiBackend
;
1752 $this->tearDownFiles();
1753 $this->doTestGetDirectoryList();
1754 $this->tearDownFiles();
1757 private function doTestGetDirectoryList() {
1758 $backendName = $this->backendClass();
1760 $base = self
::baseStorePath();
1762 "$base/unittest-cont1/e/test1.txt",
1763 "$base/unittest-cont1/e/test2.txt",
1764 "$base/unittest-cont1/e/test3.txt",
1765 "$base/unittest-cont1/e/subdir1/test1.txt",
1766 "$base/unittest-cont1/e/subdir1/test2.txt",
1767 "$base/unittest-cont1/e/subdir2/test3.txt",
1768 "$base/unittest-cont1/e/subdir2/test4.txt",
1769 "$base/unittest-cont1/e/subdir2/subdir/test1.txt",
1770 "$base/unittest-cont1/e/subdir3/subdir/test2.txt",
1771 "$base/unittest-cont1/e/subdir4/subdir/test3.txt",
1772 "$base/unittest-cont1/e/subdir4/subdir/test4.txt",
1773 "$base/unittest-cont1/e/subdir4/subdir/test5.txt",
1774 "$base/unittest-cont1/e/subdir4/subdir/sub/test0.txt",
1775 "$base/unittest-cont1/e/subdir4/subdir/sub/120-px-file.txt",
1780 foreach ( $files as $file ) {
1781 $this->prepare( array( 'dir' => dirname( $file ) ) );
1782 $ops[] = array( 'op' => 'create', 'content' => 'xxy', 'dst' => $file );
1784 $status = $this->backend
->doQuickOperations( $ops );
1785 $this->assertGoodStatus( $status,
1786 "Creation of files succeeded ($backendName)." );
1787 $this->assertEquals( true, $status->isOK(),
1788 "Creation of files succeeded with OK status ($backendName)." );
1790 $this->assertEquals( true,
1791 $this->backend
->directoryExists( array( 'dir' => "$base/unittest-cont1/e/subdir1" ) ),
1792 "Directory exists in ($backendName)." );
1793 $this->assertEquals( true,
1794 $this->backend
->directoryExists( array( 'dir' => "$base/unittest-cont1/e/subdir2/subdir" ) ),
1795 "Directory exists in ($backendName)." );
1796 $this->assertEquals( false,
1797 $this->backend
->directoryExists( array( 'dir' => "$base/unittest-cont1/e/subdir2/test1.txt" ) ),
1798 "Directory does not exists in ($backendName)." );
1806 // Actual listing (no trailing slash)
1808 $iter = $this->backend
->getTopDirectoryList( array( 'dir' => "$base/unittest-cont1" ) );
1809 foreach ( $iter as $file ) {
1814 $this->assertEquals( $expected, $list, "Correct top dir listing ($backendName)." );
1825 // Actual listing (no trailing slash)
1827 $iter = $this->backend
->getTopDirectoryList( array( 'dir' => "$base/unittest-cont1/e" ) );
1828 foreach ( $iter as $file ) {
1833 $this->assertEquals( $expected, $list, "Correct top dir listing ($backendName)." );
1835 // Actual listing (with trailing slash)
1837 $iter = $this->backend
->getTopDirectoryList( array( 'dir' => "$base/unittest-cont1/e/" ) );
1838 foreach ( $iter as $file ) {
1843 $this->assertEquals( $expected, $list, "Correct top dir listing ($backendName)." );
1851 // Actual listing (no trailing slash)
1853 $iter = $this->backend
->getTopDirectoryList( array( 'dir' => "$base/unittest-cont1/e/subdir2" ) );
1854 foreach ( $iter as $file ) {
1859 $this->assertEquals( $expected, $list, "Correct top dir listing ($backendName)." );
1861 // Actual listing (with trailing slash)
1863 $iter = $this->backend
->getTopDirectoryList( array( 'dir' => "$base/unittest-cont1/e/subdir2/" ) );
1864 foreach ( $iter as $file ) {
1869 $this->assertEquals( $expected, $list, "Correct top dir listing ($backendName)." );
1871 // Actual listing (using iterator second time)
1873 foreach ( $iter as $file ) {
1878 $this->assertEquals( $expected, $list, "Correct top dir listing ($backendName), second iteration." );
1880 // Expected listing (recursive)
1890 "e/subdir4/subdir/sub",
1894 // Actual listing (recursive)
1896 $iter = $this->backend
->getDirectoryList( array( 'dir' => "$base/unittest-cont1/" ) );
1897 foreach ( $iter as $file ) {
1902 $this->assertEquals( $expected, $list, "Correct dir listing ($backendName)." );
1904 // Expected listing (recursive)
1911 // Actual listing (recursive)
1913 $iter = $this->backend
->getDirectoryList( array( 'dir' => "$base/unittest-cont1/e/subdir4" ) );
1914 foreach ( $iter as $file ) {
1919 $this->assertEquals( $expected, $list, "Correct dir listing ($backendName)." );
1921 // Actual listing (recursive, second time)
1923 foreach ( $iter as $file ) {
1928 $this->assertEquals( $expected, $list, "Correct dir listing ($backendName)." );
1930 foreach ( $files as $file ) { // clean up
1931 $this->backend
->doOperation( array( 'op' => 'delete', 'src' => $file ) );
1934 $iter = $this->backend
->getDirectoryList( array( 'dir' => "$base/unittest-cont1/not/exists" ) );
1935 foreach ( $iter as $iter ) {} // no errors
1938 public function testLockCalls() {
1939 $this->backend
= $this->singleBackend
;
1940 $this->doTestLockCalls();
1943 private function doTestLockCalls() {
1944 $backendName = $this->backendClass();
1946 for ( $i=0; $i<50; $i++
) {
1952 "subdir1", // duplicate
1953 "subdir1/test1.txt",
1954 "subdir1/test2.txt",
1956 "subdir2", // duplicate
1957 "subdir2/test3.txt",
1958 "subdir2/test4.txt",
1960 "subdir2/subdir/test1.txt",
1961 "subdir2/subdir/test2.txt",
1962 "subdir2/subdir/test3.txt",
1963 "subdir2/subdir/test4.txt",
1964 "subdir2/subdir/test5.txt",
1965 "subdir2/subdir/sub",
1966 "subdir2/subdir/sub/test0.txt",
1967 "subdir2/subdir/sub/120-px-file.txt",
1970 $status = $this->backend
->lockFiles( $paths, LockManager
::LOCK_EX
);
1971 $this->assertEquals( array(), $status->errors
,
1972 "Locking of files succeeded ($backendName)." );
1973 $this->assertEquals( true, $status->isOK(),
1974 "Locking of files succeeded with OK status ($backendName)." );
1976 $status = $this->backend
->lockFiles( $paths, LockManager
::LOCK_SH
);
1977 $this->assertEquals( array(), $status->errors
,
1978 "Locking of files succeeded ($backendName)." );
1979 $this->assertEquals( true, $status->isOK(),
1980 "Locking of files succeeded with OK status ($backendName)." );
1982 $status = $this->backend
->unlockFiles( $paths, LockManager
::LOCK_SH
);
1983 $this->assertEquals( array(), $status->errors
,
1984 "Locking of files succeeded ($backendName)." );
1985 $this->assertEquals( true, $status->isOK(),
1986 "Locking of files succeeded with OK status ($backendName)." );
1988 $status = $this->backend
->unlockFiles( $paths, LockManager
::LOCK_EX
);
1989 $this->assertEquals( array(), $status->errors
,
1990 "Locking of files succeeded ($backendName)." );
1991 $this->assertEquals( true, $status->isOK(),
1992 "Locking of files succeeded with OK status ($backendName)." );
1996 // test helper wrapper for backend prepare() function
1997 private function prepare( array $params ) {
1998 return $this->backend
->prepare( $params );
2001 // test helper wrapper for backend prepare() function
2002 private function create( array $params ) {
2003 $params['op'] = 'create';
2004 return $this->backend
->doQuickOperations( array( $params ) );
2007 function tearDownFiles() {
2008 foreach ( $this->filesToPrune
as $file ) {
2011 $containers = array( 'unittest-cont1', 'unittest-cont2' );
2012 foreach ( $containers as $container ) {
2013 $this->deleteFiles( $container );
2015 $this->filesToPrune
= array();
2018 private function deleteFiles( $container ) {
2019 $base = self
::baseStorePath();
2020 $iter = $this->backend
->getFileList( array( 'dir' => "$base/$container" ) );
2022 foreach ( $iter as $file ) {
2023 $this->backend
->quickDelete( array( 'src' => "$base/$container/$file" ) );
2026 $this->backend
->clean( array( 'dir' => "$base/$container", 'recursive' => 1 ) );
2029 function assertBackendPathsConsistent( array $paths ) {
2030 if ( $this->backend
instanceof FileBackendMultiWrite
) {
2031 $status = $this->backend
->consistencyCheck( $paths );
2032 $this->assertGoodStatus( $status, "Files synced: " . implode( ',', $paths ) );
2036 function assertGoodStatus( $status, $msg ) {
2037 $this->assertEquals( print_r( array(), 1 ), print_r( $status->errors
, 1 ), $msg );