Index: trunk/phase3/tests/phpunit/MediaWikiPHPUnitCommand.php |
— | — | @@ -5,6 +5,7 @@ |
6 | 6 | static $additionalOptions = array( |
7 | 7 | 'regex=' => false, |
8 | 8 | 'file=' => false, |
| 9 | + 'use-filebackend=' => false, |
9 | 10 | 'keep-uploads' => false, |
10 | 11 | 'use-normal-tables' => false, |
11 | 12 | 'reuse-db' => false, |
Index: trunk/phase3/tests/phpunit/includes/filerepo/StoreBatchTest.php |
— | — | @@ -5,22 +5,36 @@ |
6 | 6 | class StoreBatchTest extends MediaWikiTestCase { |
7 | 7 | |
8 | 8 | public function setUp() { |
| 9 | + global $wgFileBackends; |
9 | 10 | parent::setUp(); |
10 | 11 | |
11 | 12 | # Forge a FSRepo object to not have to rely on local wiki settings |
12 | 13 | $this->tmpDir = wfTempDir() . '/store-batch-test-' . time() . '-' . mt_rand(); |
13 | | - $this->repo = new FSRepo( array( |
14 | | - 'name' => 'test', |
15 | | - 'backend' => new FSFileBackend( array( |
| 14 | + if ( $this->getCliArg( 'use-filebackend=' ) ) { |
| 15 | + $name = $this->getCliArg( 'use-filebackend=' ); |
| 16 | + $useConfig = array(); |
| 17 | + foreach ( $wgFileBackends as $conf ) { |
| 18 | + if ( $conf['name'] == $name ) { |
| 19 | + $useConfig = $conf; |
| 20 | + } |
| 21 | + } |
| 22 | + $useConfig['name'] = 'localtesting'; // swap name |
| 23 | + $backend = new $conf['class']( $useConfig ); |
| 24 | + } else { |
| 25 | + $backend = new FSFileBackend( array( |
16 | 26 | 'name' => 'local-backend', |
17 | 27 | 'lockManager' => 'nullLockManager', |
18 | 28 | 'containerPaths' => array( |
19 | | - 'test-public' => $this->tmpDir . "/public", |
20 | | - 'test-thumb' => $this->tmpDir . "/thumb", |
21 | | - 'test-temp' => $this->tmpDir . "/temp", |
22 | | - 'test-deleted' => $this->tmpDir . "/deleted", |
| 29 | + 'unittests-public' => $this->tmpDir . "/public", |
| 30 | + 'unittests-thumb' => $this->tmpDir . "/thumb", |
| 31 | + 'unittests-temp' => $this->tmpDir . "/temp", |
| 32 | + 'unittests-deleted' => $this->tmpDir . "/deleted", |
23 | 33 | ) |
24 | | - ) ) |
| 34 | + ) ); |
| 35 | + } |
| 36 | + $this->repo = new FileRepo( array( |
| 37 | + 'name' => 'unittests', |
| 38 | + 'backend' => $backend |
25 | 39 | ) ); |
26 | 40 | |
27 | 41 | $this->date = gmdate( "YmdHis" ); |
Index: trunk/phase3/tests/phpunit/includes/filerepo/FileBackendTest.php |
— | — | @@ -5,18 +5,31 @@ |
6 | 6 | */ |
7 | 7 | class FileBackendTest extends MediaWikiTestCase { |
8 | 8 | private $backend, $multiBackend; |
9 | | - private $filesToPrune, $pathsToPrune; |
| 9 | + private $filesToPrune; |
10 | 10 | |
11 | 11 | function setUp() { |
| 12 | + global $wgFileBackends; |
12 | 13 | parent::setUp(); |
13 | 14 | $tmpDir = wfTempDir() . '/file-backend-test-' . time() . '-' . mt_rand(); |
14 | | - $this->singleBackend = new FSFileBackend( array( |
15 | | - 'name' => 'localtesting', |
16 | | - 'lockManager' => 'fsLockManager', |
17 | | - 'containerPaths' => array( |
18 | | - 'cont1' => "$tmpDir/localtesting/cont1", |
19 | | - 'cont2' => "$tmpDir/localtesting/cont2" ) |
20 | | - ) ); |
| 15 | + if ( $this->getCliArg( 'use-filebackend=' ) ) { |
| 16 | + $name = $this->getCliArg( 'use-filebackend=' ); |
| 17 | + $useConfig = array(); |
| 18 | + foreach ( $wgFileBackends as $conf ) { |
| 19 | + if ( $conf['name'] == $name ) { |
| 20 | + $useConfig = $conf; |
| 21 | + } |
| 22 | + } |
| 23 | + $useConfig['name'] = 'localtesting'; // swap name |
| 24 | + $this->singleBackend = new $conf['class']( $useConfig ); |
| 25 | + } else { |
| 26 | + $this->singleBackend = new FSFileBackend( array( |
| 27 | + 'name' => 'localtesting', |
| 28 | + 'lockManager' => 'fsLockManager', |
| 29 | + 'containerPaths' => array( |
| 30 | + 'unittest-cont1' => "$tmpDir/localtesting/unittest-cont1", |
| 31 | + 'unittest-cont2' => "$tmpDir/localtesting/unittest-cont2" ) |
| 32 | + ) ); |
| 33 | + } |
21 | 34 | $this->multiBackend = new FileBackendMultiWrite( array( |
22 | 35 | 'name' => 'localtesting', |
23 | 36 | 'lockManager' => 'fsLockManager', |
— | — | @@ -26,8 +39,8 @@ |
27 | 40 | 'class' => 'FSFileBackend', |
28 | 41 | 'lockManager' => 'nullLockManager', |
29 | 42 | 'containerPaths' => array( |
30 | | - 'cont1' => "$tmpDir/localtestingmulti1/cont1", |
31 | | - 'cont2' => "$tmpDir/localtestingmulti1/cont2" ), |
| 43 | + 'unittest-cont1' => "$tmpDir/localtestingmulti1/cont1", |
| 44 | + 'unittest-cont2' => "$tmpDir/localtestingmulti1/unittest-cont2" ), |
32 | 45 | 'isMultiMaster' => false |
33 | 46 | ), |
34 | 47 | array( |
— | — | @@ -35,13 +48,13 @@ |
36 | 49 | 'class' => 'FSFileBackend', |
37 | 50 | 'lockManager' => 'nullLockManager', |
38 | 51 | 'containerPaths' => array( |
39 | | - 'cont1' => "$tmpDir/localtestingmulti2/cont1", |
40 | | - 'cont2' => "$tmpDir/localtestingmulti2/cont2" ), |
| 52 | + 'unittest-cont1' => "$tmpDir/localtestingmulti2/cont1", |
| 53 | + 'unittest-cont2' => "$tmpDir/localtestingmulti2/unittest-cont2" ), |
41 | 54 | 'isMultiMaster' => true |
42 | 55 | ) |
43 | 56 | ) |
44 | 57 | ) ); |
45 | | - $this->filesToPrune = $this->pathsToPrune = array(); |
| 58 | + $this->filesToPrune = array(); |
46 | 59 | } |
47 | 60 | |
48 | 61 | private function baseStorePath() { |
— | — | @@ -57,13 +70,14 @@ |
58 | 71 | */ |
59 | 72 | public function testStore( $op, $source, $dest ) { |
60 | 73 | $this->filesToPrune[] = $source; |
61 | | - $this->pathsToPrune[] = $dest; |
62 | 74 | |
63 | 75 | $this->backend = $this->singleBackend; |
| 76 | + $this->tearDownFiles(); |
64 | 77 | $this->doTestStore( $op, $source, $dest ); |
65 | 78 | $this->tearDownFiles(); |
66 | 79 | |
67 | 80 | $this->backend = $this->multiBackend; |
| 81 | + $this->tearDownFiles(); |
68 | 82 | $this->doTestStore( $op, $source, $dest ); |
69 | 83 | $this->tearDownFiles(); |
70 | 84 | } |
— | — | @@ -101,7 +115,7 @@ |
102 | 116 | $cases = array(); |
103 | 117 | |
104 | 118 | $tmpName = TempFSFile::factory( "unittests_", 'txt' )->getPath(); |
105 | | - $toPath = $this->baseStorePath() . '/cont1/fun/obj1.txt'; |
| 119 | + $toPath = $this->baseStorePath() . '/unittest-cont1/fun/obj1.txt'; |
106 | 120 | $op = array( 'op' => 'store', 'src' => $tmpName, 'dst' => $toPath ); |
107 | 121 | $cases[] = array( |
108 | 122 | $op, // operation |
— | — | @@ -116,6 +130,8 @@ |
117 | 131 | $toPath, // dest |
118 | 132 | ); |
119 | 133 | |
| 134 | + // @TODO: test overwriteSame |
| 135 | + |
120 | 136 | return $cases; |
121 | 137 | } |
122 | 138 | |
— | — | @@ -123,14 +139,13 @@ |
124 | 140 | * @dataProvider provider_testCopy |
125 | 141 | */ |
126 | 142 | public function testCopy( $op, $source, $dest ) { |
127 | | - $this->pathsToPrune[] = $source; |
128 | | - $this->pathsToPrune[] = $dest; |
129 | | - |
130 | 143 | $this->backend = $this->singleBackend; |
| 144 | + $this->tearDownFiles(); |
131 | 145 | $this->doTestCopy( $op, $source, $dest ); |
132 | 146 | $this->tearDownFiles(); |
133 | 147 | |
134 | 148 | $this->backend = $this->multiBackend; |
| 149 | + $this->tearDownFiles(); |
135 | 150 | $this->doTestCopy( $op, $source, $dest ); |
136 | 151 | $this->tearDownFiles(); |
137 | 152 | } |
— | — | @@ -172,8 +187,8 @@ |
173 | 188 | public function provider_testCopy() { |
174 | 189 | $cases = array(); |
175 | 190 | |
176 | | - $source = $this->baseStorePath() . '/cont1/file.txt'; |
177 | | - $dest = $this->baseStorePath() . '/cont2/fileMoved.txt'; |
| 191 | + $source = $this->baseStorePath() . '/unittest-cont1/file.txt'; |
| 192 | + $dest = $this->baseStorePath() . '/unittest-cont2/fileMoved.txt'; |
178 | 193 | |
179 | 194 | $op = array( 'op' => 'copy', 'src' => $source, 'dst' => $dest ); |
180 | 195 | $cases[] = array( |
— | — | @@ -196,19 +211,18 @@ |
197 | 212 | * @dataProvider provider_testMove |
198 | 213 | */ |
199 | 214 | public function testMove( $op, $source, $dest ) { |
200 | | - $this->pathsToPrune[] = $source; |
201 | | - $this->pathsToPrune[] = $dest; |
202 | | - |
203 | 215 | $this->backend = $this->singleBackend; |
| 216 | + $this->tearDownFiles(); |
204 | 217 | $this->doTestMove( $op, $source, $dest ); |
205 | 218 | $this->tearDownFiles(); |
206 | 219 | |
207 | 220 | $this->backend = $this->multiBackend; |
| 221 | + $this->tearDownFiles(); |
208 | 222 | $this->doTestMove( $op, $source, $dest ); |
209 | 223 | $this->tearDownFiles(); |
210 | 224 | } |
211 | 225 | |
212 | | - public function doTestMove( $op, $source, $dest ) { |
| 226 | + private function doTestMove( $op, $source, $dest ) { |
213 | 227 | $backendName = $this->backendClass(); |
214 | 228 | |
215 | 229 | $this->backend->prepare( array( 'dir' => dirname( $source ) ) ); |
— | — | @@ -247,8 +261,8 @@ |
248 | 262 | public function provider_testMove() { |
249 | 263 | $cases = array(); |
250 | 264 | |
251 | | - $source = $this->baseStorePath() . '/cont1/file.txt'; |
252 | | - $dest = $this->baseStorePath() . '/cont2/fileMoved.txt'; |
| 265 | + $source = $this->baseStorePath() . '/unittest-cont1/file.txt'; |
| 266 | + $dest = $this->baseStorePath() . '/unittest-cont2/fileMoved.txt'; |
253 | 267 | |
254 | 268 | $op = array( 'op' => 'move', 'src' => $source, 'dst' => $dest ); |
255 | 269 | $cases[] = array( |
— | — | @@ -271,18 +285,18 @@ |
272 | 286 | * @dataProvider provider_testDelete |
273 | 287 | */ |
274 | 288 | public function testDelete( $op, $source, $withSource, $okStatus ) { |
275 | | - $this->pathsToPrune[] = $source; |
276 | | - |
277 | 289 | $this->backend = $this->singleBackend; |
| 290 | + $this->tearDownFiles(); |
278 | 291 | $this->doTestDelete( $op, $source, $withSource, $okStatus ); |
279 | 292 | $this->tearDownFiles(); |
280 | 293 | |
281 | 294 | $this->backend = $this->multiBackend; |
| 295 | + $this->tearDownFiles(); |
282 | 296 | $this->doTestDelete( $op, $source, $withSource, $okStatus ); |
283 | 297 | $this->tearDownFiles(); |
284 | 298 | } |
285 | 299 | |
286 | | - public function doTestDelete( $op, $source, $withSource, $okStatus ) { |
| 300 | + private function doTestDelete( $op, $source, $withSource, $okStatus ) { |
287 | 301 | $backendName = $this->backendClass(); |
288 | 302 | |
289 | 303 | $this->backend->prepare( array( 'dir' => dirname( $source ) ) ); |
— | — | @@ -322,7 +336,7 @@ |
323 | 337 | public function provider_testDelete() { |
324 | 338 | $cases = array(); |
325 | 339 | |
326 | | - $source = $this->baseStorePath() . '/cont1/myfacefile.txt'; |
| 340 | + $source = $this->baseStorePath() . '/unittest-cont1/myfacefile.txt'; |
327 | 341 | |
328 | 342 | $op = array( 'op' => 'delete', 'src' => $source ); |
329 | 343 | $cases[] = array( |
— | — | @@ -354,18 +368,18 @@ |
355 | 369 | * @dataProvider provider_testCreate |
356 | 370 | */ |
357 | 371 | public function testCreate( $op, $dest, $alreadyExists, $okStatus, $newSize ) { |
358 | | - $this->pathsToPrune[] = $dest; |
359 | | - |
360 | 372 | $this->backend = $this->singleBackend; |
| 373 | + $this->tearDownFiles(); |
361 | 374 | $this->doTestCreate( $op, $dest, $alreadyExists, $okStatus, $newSize ); |
362 | 375 | $this->tearDownFiles(); |
363 | 376 | |
364 | 377 | $this->backend = $this->multiBackend; |
| 378 | + $this->tearDownFiles(); |
365 | 379 | $this->doTestCreate( $op, $dest, $alreadyExists, $okStatus, $newSize ); |
366 | 380 | $this->tearDownFiles(); |
367 | 381 | } |
368 | 382 | |
369 | | - public function doTestCreate( $op, $dest, $alreadyExists, $okStatus, $newSize ) { |
| 383 | + private function doTestCreate( $op, $dest, $alreadyExists, $okStatus, $newSize ) { |
370 | 384 | $backendName = $this->backendClass(); |
371 | 385 | |
372 | 386 | $this->backend->prepare( array( 'dir' => dirname( $dest ) ) ); |
— | — | @@ -418,7 +432,7 @@ |
419 | 433 | public function provider_testCreate() { |
420 | 434 | $cases = array(); |
421 | 435 | |
422 | | - $source = $this->baseStorePath() . '/cont2/myspacefile.txt'; |
| 436 | + $source = $this->baseStorePath() . '/unittest-cont2/myspacefile.txt'; |
423 | 437 | |
424 | 438 | $dummyText = 'hey hey'; |
425 | 439 | $op = array( 'op' => 'create', 'content' => $dummyText, 'dst' => $source ); |
— | — | @@ -454,14 +468,15 @@ |
455 | 469 | * @dataProvider provider_testConcatenate |
456 | 470 | */ |
457 | 471 | public function testConcatenate( $op, $srcs, $srcsContent, $alreadyExists, $okStatus ) { |
458 | | - $this->pathsToPrune = array_merge( $this->pathsToPrune, $srcs ); |
459 | 472 | $this->filesToPrune[] = $op['dst']; |
460 | 473 | |
461 | 474 | $this->backend = $this->singleBackend; |
| 475 | + $this->tearDownFiles(); |
462 | 476 | $this->doTestConcatenate( $op, $srcs, $srcsContent, $alreadyExists, $okStatus ); |
463 | 477 | $this->tearDownFiles(); |
464 | 478 | |
465 | 479 | $this->backend = $this->multiBackend; |
| 480 | + $this->tearDownFiles(); |
466 | 481 | $this->doTestConcatenate( $op, $srcs, $srcsContent, $alreadyExists, $okStatus ); |
467 | 482 | $this->tearDownFiles(); |
468 | 483 | } |
— | — | @@ -535,16 +550,16 @@ |
536 | 551 | $rand = mt_rand( 0, 2000000000 ) . time(); |
537 | 552 | $dest = wfTempDir() . "/randomfile!$rand.txt"; |
538 | 553 | $srcs = array( |
539 | | - $this->baseStorePath() . '/cont1/file1.txt', |
540 | | - $this->baseStorePath() . '/cont1/file2.txt', |
541 | | - $this->baseStorePath() . '/cont1/file3.txt', |
542 | | - $this->baseStorePath() . '/cont1/file4.txt', |
543 | | - $this->baseStorePath() . '/cont1/file5.txt', |
544 | | - $this->baseStorePath() . '/cont1/file6.txt', |
545 | | - $this->baseStorePath() . '/cont1/file7.txt', |
546 | | - $this->baseStorePath() . '/cont1/file8.txt', |
547 | | - $this->baseStorePath() . '/cont1/file9.txt', |
548 | | - $this->baseStorePath() . '/cont1/file10.txt' |
| 554 | + $this->baseStorePath() . '/unittest-cont1/file1.txt', |
| 555 | + $this->baseStorePath() . '/unittest-cont1/file2.txt', |
| 556 | + $this->baseStorePath() . '/unittest-cont1/file3.txt', |
| 557 | + $this->baseStorePath() . '/unittest-cont1/file4.txt', |
| 558 | + $this->baseStorePath() . '/unittest-cont1/file5.txt', |
| 559 | + $this->baseStorePath() . '/unittest-cont1/file6.txt', |
| 560 | + $this->baseStorePath() . '/unittest-cont1/file7.txt', |
| 561 | + $this->baseStorePath() . '/unittest-cont1/file8.txt', |
| 562 | + $this->baseStorePath() . '/unittest-cont1/file9.txt', |
| 563 | + $this->baseStorePath() . '/unittest-cont1/file10.txt' |
549 | 564 | ); |
550 | 565 | $content = array( |
551 | 566 | 'egfage', |
— | — | @@ -583,13 +598,13 @@ |
584 | 599 | * @dataProvider provider_testGetFileContents |
585 | 600 | */ |
586 | 601 | public function testGetFileContents( $src, $content ) { |
587 | | - $this->pathsToPrune[] = $src; |
588 | | - |
589 | 602 | $this->backend = $this->singleBackend; |
| 603 | + $this->tearDownFiles(); |
590 | 604 | $this->doTestGetFileContents( $src, $content ); |
591 | 605 | $this->tearDownFiles(); |
592 | 606 | |
593 | 607 | $this->backend = $this->multiBackend; |
| 608 | + $this->tearDownFiles(); |
594 | 609 | $this->doTestGetFileContents( $src, $content ); |
595 | 610 | $this->tearDownFiles(); |
596 | 611 | } |
— | — | @@ -604,8 +619,10 @@ |
605 | 620 | |
606 | 621 | $status = $this->backend->doOperation( |
607 | 622 | array( 'op' => 'create', 'content' => $content, 'dst' => $source ) ); |
| 623 | + $this->assertEquals( array(), $status->errors, |
| 624 | + "Creation of file at $source succeeded ($backendName)." ); |
608 | 625 | $this->assertEquals( true, $status->isOK(), |
609 | | - "Creation of file at $source succeeded ($backendName)." ); |
| 626 | + "Creation of file at $source succeeded with OK status ($backendName)." ); |
610 | 627 | |
611 | 628 | $newContents = $this->backend->getFileContents( array( 'src' => $source ) ); |
612 | 629 | $this->assertNotEquals( false, $newContents, |
— | — | @@ -619,8 +636,8 @@ |
620 | 637 | $cases = array(); |
621 | 638 | |
622 | 639 | $base = $this->baseStorePath(); |
623 | | - $cases[] = array( "$base/cont1/b/z/some_file.txt", "some file contents" ); |
624 | | - $cases[] = array( "$base/cont1/b/some-other_file.txt", "more file contents" ); |
| 640 | + $cases[] = array( "$base/unittest-cont1/b/z/some_file.txt", "some file contents" ); |
| 641 | + $cases[] = array( "$base/unittest-cont1/b/some-other_file.txt", "more file contents" ); |
625 | 642 | |
626 | 643 | return $cases; |
627 | 644 | } |
— | — | @@ -629,13 +646,13 @@ |
630 | 647 | * @dataProvider provider_testGetLocalCopy |
631 | 648 | */ |
632 | 649 | public function testGetLocalCopy( $src, $content ) { |
633 | | - $this->pathsToPrune[] = $src; |
634 | | - |
635 | 650 | $this->backend = $this->singleBackend; |
| 651 | + $this->tearDownFiles(); |
636 | 652 | $this->doTestGetLocalCopy( $src, $content ); |
637 | 653 | $this->tearDownFiles(); |
638 | 654 | |
639 | 655 | $this->backend = $this->multiBackend; |
| 656 | + $this->tearDownFiles(); |
640 | 657 | $this->doTestGetLocalCopy( $src, $content ); |
641 | 658 | $this->tearDownFiles(); |
642 | 659 | } |
— | — | @@ -662,8 +679,8 @@ |
663 | 680 | $cases = array(); |
664 | 681 | |
665 | 682 | $base = $this->baseStorePath(); |
666 | | - $cases[] = array( "$base/cont1/a/z/some_file.txt", "some file contents" ); |
667 | | - $cases[] = array( "$base/cont1/a/some-other_file.txt", "more file contents" ); |
| 683 | + $cases[] = array( "$base/unittest-cont1/a/z/some_file.txt", "some file contents" ); |
| 684 | + $cases[] = array( "$base/unittest-cont1/a/some-other_file.txt", "more file contents" ); |
668 | 685 | |
669 | 686 | return $cases; |
670 | 687 | } |
— | — | @@ -672,18 +689,18 @@ |
673 | 690 | * @dataProvider provider_testGetLocalReference |
674 | 691 | */ |
675 | 692 | public function testGetLocalReference( $src, $content ) { |
676 | | - $this->pathsToPrune[] = $src; |
677 | | - |
678 | 693 | $this->backend = $this->singleBackend; |
| 694 | + $this->tearDownFiles(); |
679 | 695 | $this->doTestGetLocalReference( $src, $content ); |
680 | 696 | $this->tearDownFiles(); |
681 | 697 | |
682 | 698 | $this->backend = $this->multiBackend; |
| 699 | + $this->tearDownFiles(); |
683 | 700 | $this->doTestGetLocalReference( $src, $content ); |
684 | 701 | $this->tearDownFiles(); |
685 | 702 | } |
686 | 703 | |
687 | | - public function doTestGetLocalReference( $source, $content ) { |
| 704 | + private function doTestGetLocalReference( $source, $content ) { |
688 | 705 | $backendName = $this->backendClass(); |
689 | 706 | |
690 | 707 | $this->backend->prepare( array( 'dir' => dirname( $source ) ) ); |
— | — | @@ -705,8 +722,8 @@ |
706 | 723 | $cases = array(); |
707 | 724 | |
708 | 725 | $base = $this->baseStorePath(); |
709 | | - $cases[] = array( "$base/cont1/a/z/some_file.txt", "some file contents" ); |
710 | | - $cases[] = array( "$base/cont1/a/some-other_file.txt", "more file contents" ); |
| 726 | + $cases[] = array( "$base/unittest-cont1/a/z/some_file.txt", "some file contents" ); |
| 727 | + $cases[] = array( "$base/unittest-cont1/a/some-other_file.txt", "more file contents" ); |
711 | 728 | |
712 | 729 | return $cases; |
713 | 730 | } |
— | — | @@ -725,9 +742,10 @@ |
726 | 743 | function provider_testPrepareAndClean() { |
727 | 744 | $base = $this->baseStorePath(); |
728 | 745 | return array( |
729 | | - array( "$base/cont1/a/z/some_file1.txt", true ), |
730 | | - array( "$base/cont2/a/z/some_file2.txt", true ), |
731 | | - array( "$base/cont3/a/z/some_file3.txt", false ), |
| 746 | + array( "$base/unittest-cont1/a/z/some_file1.txt", true ), |
| 747 | + array( "$base/unittest-cont2/a/z/some_file2.txt", true ), |
| 748 | + # Specific to FS backend with no basePath field set |
| 749 | + #array( "$base/unittest-cont3/a/z/some_file3.txt", false ), |
732 | 750 | ); |
733 | 751 | } |
734 | 752 | |
— | — | @@ -770,19 +788,14 @@ |
771 | 789 | function doTestDoOperations() { |
772 | 790 | $base = $this->baseStorePath(); |
773 | 791 | |
774 | | - $fileA = "$base/cont1/a/b/fileA.txt"; |
| 792 | + $fileA = "$base/unittest-cont1/a/b/fileA.txt"; |
775 | 793 | $fileAContents = '3tqtmoeatmn4wg4qe-mg3qt3 tq'; |
776 | | - $fileB = "$base/cont1/a/b/fileB.txt"; |
| 794 | + $fileB = "$base/unittest-cont1/a/b/fileB.txt"; |
777 | 795 | $fileBContents = 'g-jmq3gpqgt3qtg q3GT '; |
778 | | - $fileC = "$base/cont1/a/b/fileC.txt"; |
| 796 | + $fileC = "$base/unittest-cont1/a/b/fileC.txt"; |
779 | 797 | $fileCContents = 'eigna[ogmewt 3qt g3qg flew[ag'; |
780 | | - $fileD = "$base/cont1/a/b/fileD.txt"; |
| 798 | + $fileD = "$base/unittest-cont1/a/b/fileD.txt"; |
781 | 799 | |
782 | | - $this->pathsToPrune[] = $fileA; |
783 | | - $this->pathsToPrune[] = $fileB; |
784 | | - $this->pathsToPrune[] = $fileC; |
785 | | - $this->pathsToPrune[] = $fileD; |
786 | | - |
787 | 800 | $this->backend->prepare( array( 'dir' => dirname( $fileA ) ) ); |
788 | 801 | $this->backend->create( array( 'dst' => $fileA, 'content' => $fileAContents ) ); |
789 | 802 | $this->backend->prepare( array( 'dir' => dirname( $fileB ) ) ); |
— | — | @@ -846,35 +859,36 @@ |
847 | 860 | |
848 | 861 | public function testGetFileList() { |
849 | 862 | $this->backend = $this->singleBackend; |
| 863 | + $this->tearDownFiles(); |
850 | 864 | $this->doTestGetFileList(); |
851 | 865 | $this->tearDownFiles(); |
852 | 866 | |
853 | 867 | $this->backend = $this->multiBackend; |
| 868 | + $this->tearDownFiles(); |
854 | 869 | $this->doTestGetFileList(); |
855 | 870 | $this->tearDownFiles(); |
856 | 871 | } |
857 | 872 | |
858 | | - public function doTestGetFileList() { |
| 873 | + private function doTestGetFileList() { |
859 | 874 | $backendName = $this->backendClass(); |
860 | 875 | |
861 | 876 | $base = $this->baseStorePath(); |
862 | 877 | $files = array( |
863 | | - "$base/cont1/test1.txt", |
864 | | - "$base/cont1/test2.txt", |
865 | | - "$base/cont1/test3.txt", |
866 | | - "$base/cont1/subdir1/test1.txt", |
867 | | - "$base/cont1/subdir1/test2.txt", |
868 | | - "$base/cont1/subdir2/test3.txt", |
869 | | - "$base/cont1/subdir2/test4.txt", |
870 | | - "$base/cont1/subdir2/subdir/test1.txt", |
871 | | - "$base/cont1/subdir2/subdir/test2.txt", |
872 | | - "$base/cont1/subdir2/subdir/test3.txt", |
873 | | - "$base/cont1/subdir2/subdir/test4.txt", |
874 | | - "$base/cont1/subdir2/subdir/test5.txt", |
875 | | - "$base/cont1/subdir2/subdir/sub/test0.txt", |
876 | | - "$base/cont1/subdir2/subdir/sub/120-px-file.txt", |
| 878 | + "$base/unittest-cont1/test1.txt", |
| 879 | + "$base/unittest-cont1/test2.txt", |
| 880 | + "$base/unittest-cont1/test3.txt", |
| 881 | + "$base/unittest-cont1/subdir1/test1.txt", |
| 882 | + "$base/unittest-cont1/subdir1/test2.txt", |
| 883 | + "$base/unittest-cont1/subdir2/test3.txt", |
| 884 | + "$base/unittest-cont1/subdir2/test4.txt", |
| 885 | + "$base/unittest-cont1/subdir2/subdir/test1.txt", |
| 886 | + "$base/unittest-cont1/subdir2/subdir/test2.txt", |
| 887 | + "$base/unittest-cont1/subdir2/subdir/test3.txt", |
| 888 | + "$base/unittest-cont1/subdir2/subdir/test4.txt", |
| 889 | + "$base/unittest-cont1/subdir2/subdir/test5.txt", |
| 890 | + "$base/unittest-cont1/subdir2/subdir/sub/test0.txt", |
| 891 | + "$base/unittest-cont1/subdir2/subdir/sub/120-px-file.txt", |
877 | 892 | ); |
878 | | - $this->pathsToPrune = array_merge( $this->pathsToPrune, $files ); |
879 | 893 | |
880 | 894 | // Add the files |
881 | 895 | $ops = array(); |
— | — | @@ -883,8 +897,10 @@ |
884 | 898 | $this->backend->prepare( array( 'dir' => dirname( $file ) ) ); |
885 | 899 | } |
886 | 900 | $status = $this->backend->doOperations( $ops ); |
| 901 | + $this->assertEquals( array(), $status->errors, |
| 902 | + "Creation of files succeeded ($backendName)." ); |
887 | 903 | $this->assertEquals( true, $status->isOK(), |
888 | | - "Creation of files succeeded ($backendName)." ); |
| 904 | + "Creation of files succeeded with OK status ($backendName)." ); |
889 | 905 | |
890 | 906 | // Expected listing |
891 | 907 | $expected = array( |
— | — | @@ -907,7 +923,7 @@ |
908 | 924 | |
909 | 925 | // Actual listing (no trailing slash) |
910 | 926 | $list = array(); |
911 | | - $iter = $this->backend->getFileList( array( 'dir' => "$base/cont1" ) ); |
| 927 | + $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1" ) ); |
912 | 928 | foreach ( $iter as $file ) { |
913 | 929 | $list[] = $file; |
914 | 930 | } |
— | — | @@ -917,7 +933,7 @@ |
918 | 934 | |
919 | 935 | // Actual listing (with trailing slash) |
920 | 936 | $list = array(); |
921 | | - $iter = $this->backend->getFileList( array( 'dir' => "$base/cont1/" ) ); |
| 937 | + $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/" ) ); |
922 | 938 | foreach ( $iter as $file ) { |
923 | 939 | $list[] = $file; |
924 | 940 | } |
— | — | @@ -925,11 +941,43 @@ |
926 | 942 | |
927 | 943 | $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." ); |
928 | 944 | |
| 945 | + // Expected listing |
| 946 | + $expected = array( |
| 947 | + "test1.txt", |
| 948 | + "test2.txt", |
| 949 | + "test3.txt", |
| 950 | + "test4.txt", |
| 951 | + "test5.txt", |
| 952 | + "sub/test0.txt", |
| 953 | + "sub/120-px-file.txt", |
| 954 | + ); |
| 955 | + sort( $expected ); |
| 956 | + |
| 957 | + // Actual listing (no trailing slash) |
| 958 | + $list = array(); |
| 959 | + $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/subdir2/subdir" ) ); |
| 960 | + foreach ( $iter as $file ) { |
| 961 | + $list[] = $file; |
| 962 | + } |
| 963 | + sort( $list ); |
| 964 | + |
| 965 | + $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." ); |
| 966 | + |
| 967 | + // Actual listing (with trailing slash) |
| 968 | + $list = array(); |
| 969 | + $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/subdir2/subdir/" ) ); |
| 970 | + foreach ( $iter as $file ) { |
| 971 | + $list[] = $file; |
| 972 | + } |
| 973 | + sort( $list ); |
| 974 | + |
| 975 | + $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." ); |
| 976 | + |
929 | 977 | foreach ( $files as $file ) { |
930 | 978 | $this->backend->doOperation( array( 'op' => 'delete', 'src' => "$base/$file" ) ); |
931 | 979 | } |
932 | 980 | |
933 | | - $iter = $this->backend->getFileList( array( 'dir' => "$base/cont1/not/exists" ) ); |
| 981 | + $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/not/exists" ) ); |
934 | 982 | foreach ( $iter as $iter ) {} // no errors |
935 | 983 | } |
936 | 984 | |
— | — | @@ -937,11 +985,22 @@ |
938 | 986 | foreach ( $this->filesToPrune as $file ) { |
939 | 987 | @unlink( $file ); |
940 | 988 | } |
941 | | - foreach ( $this->pathsToPrune as $file ) { |
942 | | - $this->backend->doOperation( array( 'op' => 'delete', 'src' => $file ) ); |
943 | | - $tmp = $file; |
944 | | - while ( $tmp = FileBackend::parentStoragePath( $tmp ) ) { |
945 | | - $this->backend->clean( array( 'dir' => $tmp ) ); |
| 989 | + $containers = array( 'unittest-cont1', 'unittest-cont2', 'unittest-cont3' ); |
| 990 | + foreach ( $containers as $container ) { |
| 991 | + $this->deleteFiles( $this->backend, $container ); |
| 992 | + } |
| 993 | + } |
| 994 | + |
| 995 | + private function deleteFiles( $backend, $container ) { |
| 996 | + $base = $this->baseStorePath(); |
| 997 | + $iter = $backend->getFileList( array( 'dir' => "$base/$container" ) ); |
| 998 | + if ( $iter ) { |
| 999 | + foreach ( $iter as $file ) { |
| 1000 | + $backend->doOperation( array( 'op' => 'delete', 'src' => "$base/$container/$file" ) ); |
| 1001 | + $tmp = $file; |
| 1002 | + while ( $tmp = FileBackend::parentStoragePath( $tmp ) ) { |
| 1003 | + $backend->clean( array( 'dir' => $tmp ) ); |
| 1004 | + } |
946 | 1005 | } |
947 | 1006 | } |
948 | 1007 | } |