Index: trunk/phase3/tests/phpunit/includes/filerepo/StoreBatchTest.php |
— | — | @@ -9,7 +9,7 @@ |
10 | 10 | parent::setUp(); |
11 | 11 | |
12 | 12 | # Forge a FSRepo object to not have to rely on local wiki settings |
13 | | - $this->tmpDir = wfTempDir() . '/store-batch-test-' . time() . '-' . mt_rand(); |
| 13 | + $tmpPrefix = wfTempDir() . '/storebatch-test-' . time() . '-' . mt_rand(); |
14 | 14 | if ( $this->getCliArg( 'use-filebackend=' ) ) { |
15 | 15 | $name = $this->getCliArg( 'use-filebackend=' ); |
16 | 16 | $useConfig = array(); |
— | — | @@ -19,16 +19,17 @@ |
20 | 20 | } |
21 | 21 | } |
22 | 22 | $useConfig['name'] = 'localtesting'; // swap name |
23 | | - $backend = new $conf['class']( $useConfig ); |
| 23 | + $class = $conf['class']; |
| 24 | + self::$backendToUse = new $class( $useConfig ); |
24 | 25 | } else { |
25 | 26 | $backend = new FSFileBackend( array( |
26 | 27 | 'name' => 'local-backend', |
27 | 28 | 'lockManager' => 'nullLockManager', |
28 | 29 | 'containerPaths' => array( |
29 | | - 'unittests-public' => $this->tmpDir . "/public", |
30 | | - 'unittests-thumb' => $this->tmpDir . "/thumb", |
31 | | - 'unittests-temp' => $this->tmpDir . "/temp", |
32 | | - 'unittests-deleted' => $this->tmpDir . "/deleted", |
| 30 | + 'unittests-public' => "{$tmpPrefix}-public", |
| 31 | + 'unittests-thumb' => "{$tmpPrefix}-thumb", |
| 32 | + 'unittests-temp' => "{$tmpPrefix}-temp", |
| 33 | + 'unittests-deleted' => "{$tmpPrefix}-deleted", |
33 | 34 | ) |
34 | 35 | ) ); |
35 | 36 | } |
Index: trunk/phase3/tests/phpunit/includes/filerepo/FileBackendTest.php |
— | — | @@ -5,13 +5,14 @@ |
6 | 6 | */ |
7 | 7 | class FileBackendTest extends MediaWikiTestCase { |
8 | 8 | private $backend, $multiBackend; |
9 | | - private $filesToPrune; |
| 9 | + private $filesToPrune = array(); |
| 10 | + private $dirsToPrune = array(); |
10 | 11 | private static $backendToUse; |
11 | 12 | |
12 | 13 | function setUp() { |
13 | 14 | global $wgFileBackends; |
14 | 15 | parent::setUp(); |
15 | | - $tmpDir = wfTempDir() . '/file-backend-test-' . time() . '-' . mt_rand(); |
| 16 | + $tmpPrefix = wfTempDir() . '/filebackend-unittest-' . time() . '-' . mt_rand(); |
16 | 17 | if ( $this->getCliArg( 'use-filebackend=' ) ) { |
17 | 18 | if ( self::$backendToUse ) { |
18 | 19 | $this->singleBackend = self::$backendToUse; |
— | — | @@ -24,7 +25,8 @@ |
25 | 26 | } |
26 | 27 | } |
27 | 28 | $useConfig['name'] = 'localtesting'; // swap name |
28 | | - self::$backendToUse = new $conf['class']( $useConfig ); |
| 29 | + $class = $conf['class']; |
| 30 | + self::$backendToUse = new $class( $useConfig ); |
29 | 31 | $this->singleBackend = self::$backendToUse; |
30 | 32 | } |
31 | 33 | } else { |
— | — | @@ -32,8 +34,8 @@ |
33 | 35 | 'name' => 'localtesting', |
34 | 36 | 'lockManager' => 'fsLockManager', |
35 | 37 | 'containerPaths' => array( |
36 | | - 'unittest-cont1' => "$tmpDir/localtesting/unittest-cont1", |
37 | | - 'unittest-cont2' => "$tmpDir/localtesting/unittest-cont2" ) |
| 38 | + 'unittest-cont1' => "{$tmpPrefix}-localtesting-cont1", |
| 39 | + 'unittest-cont2' => "{$tmpPrefix}-localtesting-cont2" ) |
38 | 40 | ) ); |
39 | 41 | } |
40 | 42 | $this->multiBackend = new FileBackendMultiWrite( array( |
— | — | @@ -45,8 +47,8 @@ |
46 | 48 | 'class' => 'FSFileBackend', |
47 | 49 | 'lockManager' => 'nullLockManager', |
48 | 50 | 'containerPaths' => array( |
49 | | - 'unittest-cont1' => "$tmpDir/localtestingmulti1/cont1", |
50 | | - 'unittest-cont2' => "$tmpDir/localtestingmulti1/unittest-cont2" ), |
| 51 | + 'unittest-cont1' => "{$tmpPrefix}-localtestingmulti1-cont1", |
| 52 | + 'unittest-cont2' => "{$tmpPrefix}-localtestingmulti1-cont2" ), |
51 | 53 | 'isMultiMaster' => false |
52 | 54 | ), |
53 | 55 | array( |
— | — | @@ -54,8 +56,8 @@ |
55 | 57 | 'class' => 'FSFileBackend', |
56 | 58 | 'lockManager' => 'nullLockManager', |
57 | 59 | 'containerPaths' => array( |
58 | | - 'unittest-cont1' => "$tmpDir/localtestingmulti2/cont1", |
59 | | - 'unittest-cont2' => "$tmpDir/localtestingmulti2/unittest-cont2" ), |
| 60 | + 'unittest-cont1' => "{$tmpPrefix}-localtestingmulti2-cont1", |
| 61 | + 'unittest-cont2' => "{$tmpPrefix}-localtestingmulti2-cont2" ), |
60 | 62 | 'isMultiMaster' => true |
61 | 63 | ) |
62 | 64 | ) |
— | — | @@ -74,24 +76,26 @@ |
75 | 77 | /** |
76 | 78 | * @dataProvider provider_testStore |
77 | 79 | */ |
78 | | - public function testStore( $op, $source, $dest ) { |
79 | | - $this->filesToPrune[] = $source; |
| 80 | + public function testStore( $op ) { |
| 81 | + $this->filesToPrune[] = $op['src']; |
80 | 82 | |
81 | 83 | $this->backend = $this->singleBackend; |
82 | 84 | $this->tearDownFiles(); |
83 | | - $this->doTestStore( $op, $source, $dest ); |
| 85 | + $this->doTestStore( $op ); |
84 | 86 | $this->tearDownFiles(); |
85 | 87 | |
86 | 88 | $this->backend = $this->multiBackend; |
87 | 89 | $this->tearDownFiles(); |
88 | | - $this->doTestStore( $op, $source, $dest ); |
| 90 | + $this->doTestStore( $op ); |
89 | 91 | $this->tearDownFiles(); |
90 | 92 | } |
91 | 93 | |
92 | | - function doTestStore( $op, $source, $dest ) { |
| 94 | + function doTestStore( $op ) { |
93 | 95 | $backendName = $this->backendClass(); |
94 | 96 | |
95 | | - $this->backend->prepare( array( 'dir' => dirname( $dest ) ) ); |
| 97 | + $source = $op['src']; |
| 98 | + $dest = $op['dst']; |
| 99 | + $this->prepare( array( 'dir' => dirname( $dest ) ) ); |
96 | 100 | |
97 | 101 | file_put_contents( $source, "Unit test file" ); |
98 | 102 | |
— | — | @@ -156,23 +160,25 @@ |
157 | 161 | /** |
158 | 162 | * @dataProvider provider_testCopy |
159 | 163 | */ |
160 | | - public function testCopy( $op, $source, $dest ) { |
| 164 | + public function testCopy( $op ) { |
161 | 165 | $this->backend = $this->singleBackend; |
162 | 166 | $this->tearDownFiles(); |
163 | | - $this->doTestCopy( $op, $source, $dest ); |
| 167 | + $this->doTestCopy( $op ); |
164 | 168 | $this->tearDownFiles(); |
165 | 169 | |
166 | 170 | $this->backend = $this->multiBackend; |
167 | 171 | $this->tearDownFiles(); |
168 | | - $this->doTestCopy( $op, $source, $dest ); |
| 172 | + $this->doTestCopy( $op ); |
169 | 173 | $this->tearDownFiles(); |
170 | 174 | } |
171 | 175 | |
172 | | - function doTestCopy( $op, $source, $dest ) { |
| 176 | + function doTestCopy( $op ) { |
173 | 177 | $backendName = $this->backendClass(); |
174 | 178 | |
175 | | - $this->backend->prepare( array( 'dir' => dirname( $source ) ) ); |
176 | | - $this->backend->prepare( array( 'dir' => dirname( $dest ) ) ); |
| 179 | + $source = $op['src']; |
| 180 | + $dest = $op['dst']; |
| 181 | + $this->prepare( array( 'dir' => dirname( $source ) ) ); |
| 182 | + $this->prepare( array( 'dir' => dirname( $dest ) ) ); |
177 | 183 | |
178 | 184 | $status = $this->backend->doOperation( |
179 | 185 | array( 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ) ); |
— | — | @@ -242,23 +248,25 @@ |
243 | 249 | /** |
244 | 250 | * @dataProvider provider_testMove |
245 | 251 | */ |
246 | | - public function testMove( $op, $source, $dest ) { |
| 252 | + public function testMove( $op ) { |
247 | 253 | $this->backend = $this->singleBackend; |
248 | 254 | $this->tearDownFiles(); |
249 | | - $this->doTestMove( $op, $source, $dest ); |
| 255 | + $this->doTestMove( $op ); |
250 | 256 | $this->tearDownFiles(); |
251 | 257 | |
252 | 258 | $this->backend = $this->multiBackend; |
253 | 259 | $this->tearDownFiles(); |
254 | | - $this->doTestMove( $op, $source, $dest ); |
| 260 | + $this->doTestMove( $op ); |
255 | 261 | $this->tearDownFiles(); |
256 | 262 | } |
257 | 263 | |
258 | | - private function doTestMove( $op, $source, $dest ) { |
| 264 | + private function doTestMove( $op ) { |
259 | 265 | $backendName = $this->backendClass(); |
260 | 266 | |
261 | | - $this->backend->prepare( array( 'dir' => dirname( $source ) ) ); |
262 | | - $this->backend->prepare( array( 'dir' => dirname( $dest ) ) ); |
| 267 | + $source = $op['src']; |
| 268 | + $dest = $op['dst']; |
| 269 | + $this->prepare( array( 'dir' => dirname( $source ) ) ); |
| 270 | + $this->prepare( array( 'dir' => dirname( $dest ) ) ); |
263 | 271 | |
264 | 272 | $status = $this->backend->doOperation( |
265 | 273 | array( 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ) ); |
— | — | @@ -329,22 +337,23 @@ |
330 | 338 | /** |
331 | 339 | * @dataProvider provider_testDelete |
332 | 340 | */ |
333 | | - public function testDelete( $op, $source, $withSource, $okStatus ) { |
| 341 | + public function testDelete( $op, $withSource, $okStatus ) { |
334 | 342 | $this->backend = $this->singleBackend; |
335 | 343 | $this->tearDownFiles(); |
336 | | - $this->doTestDelete( $op, $source, $withSource, $okStatus ); |
| 344 | + $this->doTestDelete( $op, $withSource, $okStatus ); |
337 | 345 | $this->tearDownFiles(); |
338 | 346 | |
339 | 347 | $this->backend = $this->multiBackend; |
340 | 348 | $this->tearDownFiles(); |
341 | | - $this->doTestDelete( $op, $source, $withSource, $okStatus ); |
| 349 | + $this->doTestDelete( $op, $withSource, $okStatus ); |
342 | 350 | $this->tearDownFiles(); |
343 | 351 | } |
344 | 352 | |
345 | | - private function doTestDelete( $op, $source, $withSource, $okStatus ) { |
| 353 | + private function doTestDelete( $op, $withSource, $okStatus ) { |
346 | 354 | $backendName = $this->backendClass(); |
347 | 355 | |
348 | | - $this->backend->prepare( array( 'dir' => dirname( $source ) ) ); |
| 356 | + $source = $op['src']; |
| 357 | + $this->prepare( array( 'dir' => dirname( $source ) ) ); |
349 | 358 | |
350 | 359 | if ( $withSource ) { |
351 | 360 | $status = $this->backend->doOperation( |
— | — | @@ -386,14 +395,12 @@ |
387 | 396 | $op = array( 'op' => 'delete', 'src' => $source ); |
388 | 397 | $cases[] = array( |
389 | 398 | $op, // operation |
390 | | - $source, // source |
391 | 399 | true, // with source |
392 | 400 | true // succeeds |
393 | 401 | ); |
394 | 402 | |
395 | 403 | $cases[] = array( |
396 | 404 | $op, // operation |
397 | | - $source, // source |
398 | 405 | false, // without source |
399 | 406 | false // fails |
400 | 407 | ); |
— | — | @@ -401,7 +408,6 @@ |
402 | 409 | $op['ignoreMissingSource'] = true; |
403 | 410 | $cases[] = array( |
404 | 411 | $op, // operation |
405 | | - $source, // source |
406 | 412 | false, // without source |
407 | 413 | true // succeeds |
408 | 414 | ); |
— | — | @@ -428,7 +434,7 @@ |
429 | 435 | $backendName = $this->backendClass(); |
430 | 436 | |
431 | 437 | $dest = $op['dst']; |
432 | | - $this->backend->prepare( array( 'dir' => dirname( $dest ) ) ); |
| 438 | + $this->prepare( array( 'dir' => dirname( $dest ) ) ); |
433 | 439 | |
434 | 440 | $oldText = 'blah...blah...waahwaah'; |
435 | 441 | if ( $alreadyExists ) { |
— | — | @@ -553,7 +559,7 @@ |
554 | 560 | // Create sources |
555 | 561 | $ops = array(); |
556 | 562 | foreach ( $srcs as $i => $source ) { |
557 | | - $this->backend->prepare( array( 'dir' => dirname( $source ) ) ); |
| 563 | + $this->prepare( array( 'dir' => dirname( $source ) ) ); |
558 | 564 | $ops[] = array( |
559 | 565 | 'op' => 'create', // operation |
560 | 566 | 'dst' => $source, // source |
— | — | @@ -662,15 +668,15 @@ |
663 | 669 | /** |
664 | 670 | * @dataProvider provider_testGetFileContents |
665 | 671 | */ |
666 | | - public function testGetFileContents( $src, $content ) { |
| 672 | + public function testGetFileContents( $source, $content ) { |
667 | 673 | $this->backend = $this->singleBackend; |
668 | 674 | $this->tearDownFiles(); |
669 | | - $this->doTestGetFileContents( $src, $content ); |
| 675 | + $this->doTestGetFileContents( $source, $content ); |
670 | 676 | $this->tearDownFiles(); |
671 | 677 | |
672 | 678 | $this->backend = $this->multiBackend; |
673 | 679 | $this->tearDownFiles(); |
674 | | - $this->doTestGetFileContents( $src, $content ); |
| 680 | + $this->doTestGetFileContents( $source, $content ); |
675 | 681 | $this->tearDownFiles(); |
676 | 682 | } |
677 | 683 | |
— | — | @@ -680,7 +686,7 @@ |
681 | 687 | public function doTestGetFileContents( $source, $content ) { |
682 | 688 | $backendName = $this->backendClass(); |
683 | 689 | |
684 | | - $this->backend->prepare( array( 'dir' => dirname( $source ) ) ); |
| 690 | + $this->prepare( array( 'dir' => dirname( $source ) ) ); |
685 | 691 | |
686 | 692 | $status = $this->backend->doOperation( |
687 | 693 | array( 'op' => 'create', 'content' => $content, 'dst' => $source ) ); |
— | — | @@ -710,22 +716,22 @@ |
711 | 717 | /** |
712 | 718 | * @dataProvider provider_testGetLocalCopy |
713 | 719 | */ |
714 | | - public function testGetLocalCopy( $src, $content ) { |
| 720 | + public function testGetLocalCopy( $source, $content ) { |
715 | 721 | $this->backend = $this->singleBackend; |
716 | 722 | $this->tearDownFiles(); |
717 | | - $this->doTestGetLocalCopy( $src, $content ); |
| 723 | + $this->doTestGetLocalCopy( $source, $content ); |
718 | 724 | $this->tearDownFiles(); |
719 | 725 | |
720 | 726 | $this->backend = $this->multiBackend; |
721 | 727 | $this->tearDownFiles(); |
722 | | - $this->doTestGetLocalCopy( $src, $content ); |
| 728 | + $this->doTestGetLocalCopy( $source, $content ); |
723 | 729 | $this->tearDownFiles(); |
724 | 730 | } |
725 | 731 | |
726 | 732 | public function doTestGetLocalCopy( $source, $content ) { |
727 | 733 | $backendName = $this->backendClass(); |
728 | 734 | |
729 | | - $this->backend->prepare( array( 'dir' => dirname( $source ) ) ); |
| 735 | + $this->prepare( array( 'dir' => dirname( $source ) ) ); |
730 | 736 | |
731 | 737 | $status = $this->backend->doOperation( |
732 | 738 | array( 'op' => 'create', 'content' => $content, 'dst' => $source ) ); |
— | — | @@ -753,22 +759,22 @@ |
754 | 760 | /** |
755 | 761 | * @dataProvider provider_testGetLocalReference |
756 | 762 | */ |
757 | | - public function testGetLocalReference( $src, $content ) { |
| 763 | + public function testGetLocalReference( $source, $content ) { |
758 | 764 | $this->backend = $this->singleBackend; |
759 | 765 | $this->tearDownFiles(); |
760 | | - $this->doTestGetLocalReference( $src, $content ); |
| 766 | + $this->doTestGetLocalReference( $source, $content ); |
761 | 767 | $this->tearDownFiles(); |
762 | 768 | |
763 | 769 | $this->backend = $this->multiBackend; |
764 | 770 | $this->tearDownFiles(); |
765 | | - $this->doTestGetLocalReference( $src, $content ); |
| 771 | + $this->doTestGetLocalReference( $source, $content ); |
766 | 772 | $this->tearDownFiles(); |
767 | 773 | } |
768 | 774 | |
769 | 775 | private function doTestGetLocalReference( $source, $content ) { |
770 | 776 | $backendName = $this->backendClass(); |
771 | 777 | |
772 | | - $this->backend->prepare( array( 'dir' => dirname( $source ) ) ); |
| 778 | + $this->prepare( array( 'dir' => dirname( $source ) ) ); |
773 | 779 | |
774 | 780 | $status = $this->backend->doOperation( |
775 | 781 | array( 'op' => 'create', 'content' => $content, 'dst' => $source ) ); |
— | — | @@ -799,9 +805,11 @@ |
800 | 806 | public function testPrepareAndClean( $path, $isOK ) { |
801 | 807 | $this->backend = $this->singleBackend; |
802 | 808 | $this->doTestPrepareAndClean( $path, $isOK ); |
| 809 | + $this->tearDownFiles(); |
803 | 810 | |
804 | 811 | $this->backend = $this->multiBackend; |
805 | 812 | $this->doTestPrepareAndClean( $path, $isOK ); |
| 813 | + $this->tearDownFiles(); |
806 | 814 | } |
807 | 815 | |
808 | 816 | function provider_testPrepareAndClean() { |
— | — | @@ -817,7 +825,7 @@ |
818 | 826 | function doTestPrepareAndClean( $path, $isOK ) { |
819 | 827 | $backendName = $this->backendClass(); |
820 | 828 | |
821 | | - $status = $this->backend->prepare( array( 'dir' => $path ) ); |
| 829 | + $status = $this->prepare( array( 'dir' => dirname( $path ) ) ); |
822 | 830 | if ( $isOK ) { |
823 | 831 | $this->assertEquals( array(), $status->errors, |
824 | 832 | "Preparing dir $path succeeded without warnings ($backendName)." ); |
— | — | @@ -828,7 +836,7 @@ |
829 | 837 | "Preparing dir $path failed ($backendName)." ); |
830 | 838 | } |
831 | 839 | |
832 | | - $status = $this->backend->clean( array( 'dir' => $path ) ); |
| 840 | + $status = $this->backend->clean( array( 'dir' => dirname( $path ) ) ); |
833 | 841 | if ( $isOK ) { |
834 | 842 | $this->assertEquals( array(), $status->errors, |
835 | 843 | "Cleaning dir $path succeeded without warnings ($backendName)." ); |
— | — | @@ -844,10 +852,16 @@ |
845 | 853 | |
846 | 854 | public function testDoOperations() { |
847 | 855 | $this->backend = $this->singleBackend; |
| 856 | + $this->tearDownFiles(); |
848 | 857 | $this->doTestDoOperations(); |
| 858 | + $this->tearDownFiles(); |
849 | 859 | |
850 | 860 | $this->backend = $this->multiBackend; |
| 861 | + $this->tearDownFiles(); |
851 | 862 | $this->doTestDoOperations(); |
| 863 | + $this->tearDownFiles(); |
| 864 | + |
| 865 | + // @TODO: test some cases where the ops should fail |
852 | 866 | } |
853 | 867 | |
854 | 868 | function doTestDoOperations() { |
— | — | @@ -861,11 +875,11 @@ |
862 | 876 | $fileCContents = 'eigna[ogmewt 3qt g3qg flew[ag'; |
863 | 877 | $fileD = "$base/unittest-cont1/a/b/fileD.txt"; |
864 | 878 | |
865 | | - $this->backend->prepare( array( 'dir' => dirname( $fileA ) ) ); |
| 879 | + $this->prepare( array( 'dir' => dirname( $fileA ) ) ); |
866 | 880 | $this->backend->create( array( 'dst' => $fileA, 'content' => $fileAContents ) ); |
867 | | - $this->backend->prepare( array( 'dir' => dirname( $fileB ) ) ); |
| 881 | + $this->prepare( array( 'dir' => dirname( $fileB ) ) ); |
868 | 882 | $this->backend->create( array( 'dst' => $fileB, 'content' => $fileBContents ) ); |
869 | | - $this->backend->prepare( array( 'dir' => dirname( $fileC ) ) ); |
| 883 | + $this->prepare( array( 'dir' => dirname( $fileC ) ) ); |
870 | 884 | $this->backend->create( array( 'dst' => $fileC, 'content' => $fileCContents ) ); |
871 | 885 | |
872 | 886 | $status = $this->backend->doOperations( array( |
— | — | @@ -920,8 +934,6 @@ |
921 | 935 | $this->assertEquals( wfBaseConvert( sha1( $fileBContents ), 16, 36, 31 ), |
922 | 936 | $this->backend->getFileSha1Base36( array( 'src' => $fileC ) ), |
923 | 937 | "Correct file SHA-1 of $fileC" ); |
924 | | - |
925 | | - // @TODO: test some cases where the ops should fail |
926 | 938 | } |
927 | 939 | |
928 | 940 | public function testGetFileList() { |
— | — | @@ -961,7 +973,7 @@ |
962 | 974 | $ops = array(); |
963 | 975 | foreach ( $files as $file ) { |
964 | 976 | $ops[] = array( 'op' => 'create', 'content' => 'xxy', 'dst' => $file ); |
965 | | - $this->backend->prepare( array( 'dir' => dirname( $file ) ) ); |
| 977 | + $this->prepare( array( 'dir' => dirname( $file ) ) ); |
966 | 978 | } |
967 | 979 | $status = $this->backend->doOperations( $ops ); |
968 | 980 | $this->assertEquals( array(), $status->errors, |
— | — | @@ -1040,40 +1052,54 @@ |
1041 | 1053 | |
1042 | 1054 | $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." ); |
1043 | 1055 | |
1044 | | - foreach ( $files as $file ) { |
1045 | | - $this->backend->doOperation( array( 'op' => 'delete', 'src' => "$base/$file" ) ); |
| 1056 | + foreach ( $files as $file ) { // clean up |
| 1057 | + $this->backend->doOperation( array( 'op' => 'delete', 'src' => $file ) ); |
1046 | 1058 | } |
| 1059 | + foreach ( $files as $file ) { // clean up |
| 1060 | + $this->recursiveClean( FileBackend::parentStoragePath( $file ) ); |
| 1061 | + } |
1047 | 1062 | |
1048 | 1063 | $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/not/exists" ) ); |
1049 | 1064 | foreach ( $iter as $iter ) {} // no errors |
1050 | 1065 | } |
1051 | 1066 | |
| 1067 | + private function prepare( array $params ) { |
| 1068 | + $this->dirsToPrune[] = $params['dir']; |
| 1069 | + return $this->backend->prepare( $params ); |
| 1070 | + } |
| 1071 | + |
1052 | 1072 | function tearDownFiles() { |
1053 | 1073 | foreach ( $this->filesToPrune as $file ) { |
1054 | 1074 | @unlink( $file ); |
1055 | 1075 | } |
1056 | 1076 | $containers = array( 'unittest-cont1', 'unittest-cont2', 'unittest-cont3' ); |
1057 | 1077 | foreach ( $containers as $container ) { |
1058 | | - $this->deleteFiles( $this->backend, $container ); |
| 1078 | + $this->deleteFiles( $container ); |
1059 | 1079 | } |
| 1080 | + foreach ( $this->dirsToPrune as $dir ) { |
| 1081 | + $this->recursiveClean( $dir ); |
| 1082 | + } |
| 1083 | + $this->filesToPrune = $this->dirsToPrune = array(); |
1060 | 1084 | } |
1061 | 1085 | |
1062 | | - private function deleteFiles( $backend, $container ) { |
| 1086 | + private function deleteFiles( $container ) { |
1063 | 1087 | $base = $this->baseStorePath(); |
1064 | | - $iter = $backend->getFileList( array( 'dir' => "$base/$container" ) ); |
| 1088 | + $iter = $this->backend->getFileList( array( 'dir' => "$base/$container" ) ); |
1065 | 1089 | if ( $iter ) { |
1066 | | - foreach ( $iter as $file ) { // delete files |
1067 | | - $backend->delete( array( 'src' => "$base/$container/$file" ), array( 'force' => 1 ) ); |
| 1090 | + foreach ( $iter as $file ) { |
| 1091 | + $this->backend->delete( array( 'src' => "$base/$container/$file" ), array( 'force' => 1 ) ); |
1068 | 1092 | } |
1069 | | - foreach ( $iter as $file ) { // delete dirs |
1070 | | - $tmp = $file; |
1071 | | - while ( $tmp = FileBackend::parentStoragePath( $tmp ) ) { |
1072 | | - $backend->clean( array( 'dir' => $tmp ) ); |
1073 | | - } |
1074 | | - } |
1075 | 1093 | } |
1076 | 1094 | } |
1077 | 1095 | |
| 1096 | + private function recursiveClean( $dir ) { |
| 1097 | + do { |
| 1098 | + if ( !$this->backend->clean( array( 'dir' => $dir ) )->isOK() ) { |
| 1099 | + break; |
| 1100 | + } |
| 1101 | + } while ( $dir = FileBackend::parentStoragePath( $dir ) ); |
| 1102 | + } |
| 1103 | + |
1078 | 1104 | function tearDown() { |
1079 | 1105 | parent::tearDown(); |
1080 | 1106 | } |