Index: branches/FileBackend/phase3/tests/phpunit/includes/filerepo/TempLocalFileTest.php |
— | — | @@ -1,12 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | - |
5 | | -class TempLocalFileTest { |
6 | | - |
7 | | - |
8 | | - function provideFile() { |
9 | | - return array ( |
10 | | - array('path/to/file'); |
11 | | - ); |
12 | | - } |
13 | | -} // end class |
\ No newline at end of file |
Index: branches/FileBackend/phase3/tests/phpunit/includes/filerepo/FileBackendTest.php |
— | — | @@ -1,20 +1,146 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | - |
5 | 4 | class FileBackendTest extends MediaWikiTestCase { |
| 5 | + private $backend, $filesToPrune, $pathsToPrune; |
6 | 6 | |
| 7 | + function setUp() { |
| 8 | + global $IP; |
| 9 | + parent::setUp(); |
| 10 | + $this->backend = new FSFileBackend( array( |
| 11 | + 'name' => 'localtesting', |
| 12 | + 'lockManager' => 'fsLockManager', |
| 13 | + 'containerPaths' => array( |
| 14 | + 'cont1' => "$IP/tests/tempimages/cont1", |
| 15 | + 'cont2' => "$IP/tests/tempimages/cont2" ) |
| 16 | + ) ); |
| 17 | + $this->filesToPrune = array(); |
| 18 | + $this->pathsToPrune = array(); |
| 19 | + } |
7 | 20 | |
8 | | - /** |
9 | | - * |
10 | | - * @dataProvider provideTestFiles |
11 | | - */ |
12 | | - function testStore( $srcPath, $dstZone, $dstRel, $flags ) { |
| 21 | + private function basePath() { |
| 22 | + return 'mwstore://localtesting'; |
| 23 | + } |
13 | 24 | |
14 | | - } |
| 25 | + /** |
| 26 | + * @dataProvider provider_testStore |
| 27 | + */ |
| 28 | + public function testStore( $op, $source, $dest ) { |
| 29 | + $this->filesToPrune[] = $source; |
| 30 | + $this->pathsToPrune[] = $dest; |
15 | 31 | |
16 | | - function provideTestFiles() { |
17 | | - return array( |
18 | | - array('srcPath', 'dstZone', 'dstRel', 'flags') |
19 | | - ); |
20 | | - } |
21 | | -} // end class |
\ No newline at end of file |
| 32 | + file_put_contents( $source, "Unit test file" ); |
| 33 | + $status = $this->backend->doOperation( $op ); |
| 34 | + |
| 35 | + $this->assertEquals( true, $status->isOK(), |
| 36 | + "Store from $source to $dest succeeded." ); |
| 37 | + $this->assertEquals( true, $status->isGood(), |
| 38 | + "Store from $source to $dest succeeded without warnings." ); |
| 39 | + $this->assertEquals( true, file_exists( $source ), |
| 40 | + "Source file $source still exists." ); |
| 41 | + $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $dest ) ), |
| 42 | + "Destination file $dest exists." ); |
| 43 | + |
| 44 | + $props1 = FSFile::getPropsFromPath( $source ); |
| 45 | + $props2 = $this->backend->getFileProps( array( 'src' => $dest ) ); |
| 46 | + $this->assertEquals( $props1, $props2, |
| 47 | + "Source and destination have the same props." ); |
| 48 | + } |
| 49 | + |
| 50 | + public function provider_testStore() { |
| 51 | + $cases = array(); |
| 52 | + |
| 53 | + $tmpName = TempFSFile::factory( "unittests_", 'txt' )->getPath(); |
| 54 | + $toPath = $this->basePath() . '/cont1/fun/obj1.txt'; |
| 55 | + $op = array( 'op' => 'store', 'src' => $tmpName, 'dst' => $toPath ); |
| 56 | + $cases[] = array( |
| 57 | + $op, // operation |
| 58 | + $tmpName, // source |
| 59 | + $toPath, // dest |
| 60 | + ); |
| 61 | + |
| 62 | + $op['overwriteDest'] = true; |
| 63 | + $cases[] = array( |
| 64 | + $op, // operation |
| 65 | + $tmpName, // source |
| 66 | + $toPath, // dest |
| 67 | + ); |
| 68 | + |
| 69 | + return $cases; |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * @dataProvider provider_testCopy |
| 74 | + */ |
| 75 | + public function testCopy() { |
| 76 | + |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * @dataProvider provider_testMove |
| 81 | + */ |
| 82 | + public function testMove() { |
| 83 | + |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * @dataProvider provider_testDelete |
| 88 | + */ |
| 89 | + public function testDelete() { |
| 90 | + |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * @dataProvider provider_testCreate |
| 95 | + */ |
| 96 | + public function testCreate() { |
| 97 | + |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * @dataProvider provider_testConcatenate |
| 102 | + */ |
| 103 | + public function testConcatenate() { |
| 104 | + |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * @dataProvider provider_testPrepare |
| 109 | + */ |
| 110 | + public function testPrepare() { |
| 111 | + |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * @dataProvider provider_testSecure |
| 116 | + */ |
| 117 | + public function testSecure() { |
| 118 | + |
| 119 | + } |
| 120 | + |
| 121 | + /** |
| 122 | + * @dataProvider provider_testClean |
| 123 | + */ |
| 124 | + public function testClean() { |
| 125 | + |
| 126 | + } |
| 127 | + |
| 128 | + /** |
| 129 | + * @dataProvider provider_testGetLocalCopy |
| 130 | + */ |
| 131 | + public function testGetLocalCopy() { |
| 132 | + |
| 133 | + } |
| 134 | + |
| 135 | + function tearDown() { |
| 136 | + parent::tearDown(); |
| 137 | + foreach ( $this->filesToPrune as $file ) { |
| 138 | + @unlink( $file ); |
| 139 | + } |
| 140 | + foreach ( $this->pathsToPrune as $file ) { |
| 141 | + $this->backend->delete( array( 'src' => $file ) ); |
| 142 | + } |
| 143 | + $this->backend = null; |
| 144 | + $this->filesToPrune = array(); |
| 145 | + $this->pathsToPrune = array(); |
| 146 | + } |
| 147 | +} |