Merge "Revert "Adding sanity check to Title::isRedirect().""
[lhc/web/wiklou.git] / tests / phpunit / includes / filerepo / FileBackendTest.php
index 8da54e2..2b94778 100644 (file)
@@ -7,7 +7,6 @@
 class FileBackendTest extends MediaWikiTestCase {
        private $backend, $multiBackend;
        private $filesToPrune = array();
-       private $dirsToPrune = array();
        private static $backendToUse;
 
        function setUp() {
@@ -652,6 +651,54 @@ class FileBackendTest extends MediaWikiTestCase {
                return $cases;
        }
 
+       public function testDoQuickOperations() {
+               $this->backend = $this->singleBackend;
+               $this->doTestDoQuickOperations();
+               $this->tearDownFiles();
+
+               $this->backend = $this->multiBackend;
+               $this->doTestDoQuickOperations();
+               $this->tearDownFiles();
+       }
+
+       private function doTestDoQuickOperations() {
+               $backendName = $this->backendClass();
+
+               $base = $this->baseStorePath();
+               $files = array(
+                       "$base/unittest-cont1/fileA.a",
+                       "$base/unittest-cont1/fileB.a",
+                       "$base/unittest-cont1/fileC.a"
+               );
+               $ops = array();
+               $purgeOps = array();
+               foreach ( $files as $path ) {
+                       $status = $this->prepare( array( 'dir' => dirname( $path ) ) );
+                       $this->assertGoodStatus( $status,
+                               "Preparing $path succeeded without warnings ($backendName)." );
+                       $ops[] = array( 'op' => 'create', 'dst' => $path, 'content' => mt_rand(0,50000) );
+                       $purgeOps[] = array( 'op' => 'delete', 'src' => $path );
+               }
+               $purgeOps[] = array( 'op' => 'null' );
+               $status = $this->backend->doQuickOperations( $ops );
+               $this->assertGoodStatus( $status,
+                       "Creation of source files succeeded ($backendName)." );
+
+               foreach ( $files as $file ) {
+                       $this->assertTrue( $this->backend->fileExists( array( 'src' => $file ) ),
+                               "File $file exists." );
+               }
+
+               $status = $this->backend->doQuickOperations( $purgeOps );
+               $this->assertGoodStatus( $status,
+                       "Quick deletion of source files succeeded ($backendName)." );
+
+               foreach ( $files as $file ) {
+                       $this->assertFalse( $this->backend->fileExists( array( 'src' => $file ) ),
+                               "File $file purged." );
+               }
+       }
+
        /**
         * @dataProvider provider_testConcatenate
         */
@@ -803,7 +850,7 @@ class FileBackendTest extends MediaWikiTestCase {
 
                if ( $alreadyExists ) {
                        $this->prepare( array( 'dir' => dirname( $path ) ) );
-                       $status = $this->backend->create( array( 'dst' => $path, 'content' => $content ) );
+                       $status = $this->create( array( 'dst' => $path, 'content' => $content ) );
                        $this->assertGoodStatus( $status,
                                "Creation of file at $path succeeded ($backendName)." );
 
@@ -813,14 +860,14 @@ class FileBackendTest extends MediaWikiTestCase {
 
                        $this->assertEquals( strlen( $content ), $size,
                                "Correct file size of '$path'" );
-                       $this->assertTrue( abs( time() - wfTimestamp( TS_UNIX, $time ) ) < 5,
+                       $this->assertTrue( abs( time() - wfTimestamp( TS_UNIX, $time ) ) < 10,
                                "Correct file timestamp of '$path'" );
 
                        $size = $stat['size'];
                        $time = $stat['mtime'];
                        $this->assertEquals( strlen( $content ), $size,
                                "Correct file size of '$path'" );
-                       $this->assertTrue( abs( time() - wfTimestamp( TS_UNIX, $time ) ) < 5,
+                       $this->assertTrue( abs( time() - wfTimestamp( TS_UNIX, $time ) ) < 10,
                                "Correct file timestamp of '$path'" );
                } else {
                        $size = $this->backend->getFileSize( array( 'src' => $path ) );
@@ -952,8 +999,7 @@ class FileBackendTest extends MediaWikiTestCase {
 
                $this->prepare( array( 'dir' => dirname( $source ) ) );
 
-               $status = $this->backend->doOperation(
-                       array( 'op' => 'create', 'content' => $content, 'dst' => $source ) );
+               $status = $this->create( array( 'content' => $content, 'dst' => $source ) );
                $this->assertGoodStatus( $status,
                        "Creation of file at $source succeeded ($backendName)." );
 
@@ -1034,7 +1080,7 @@ class FileBackendTest extends MediaWikiTestCase {
                $this->tearDownFiles();
        }
 
-       function doTestRecursiveClean() {
+       private function doTestRecursiveClean() {
                $backendName = $this->backendClass();
 
                $base = $this->baseStorePath();
@@ -1122,11 +1168,11 @@ class FileBackendTest extends MediaWikiTestCase {
                $fileD = "$base/unittest-cont1/a/b/fileD.txt";
 
                $this->prepare( array( 'dir' => dirname( $fileA ) ) );
-               $this->backend->create( array( 'dst' => $fileA, 'content' => $fileAContents ) );
+               $this->create( array( 'dst' => $fileA, 'content' => $fileAContents ) );
                $this->prepare( array( 'dir' => dirname( $fileB ) ) );
-               $this->backend->create( array( 'dst' => $fileB, 'content' => $fileBContents ) );
+               $this->create( array( 'dst' => $fileB, 'content' => $fileBContents ) );
                $this->prepare( array( 'dir' => dirname( $fileC ) ) );
-               $this->backend->create( array( 'dst' => $fileC, 'content' => $fileCContents ) );
+               $this->create( array( 'dst' => $fileC, 'content' => $fileCContents ) );
                $this->prepare( array( 'dir' => dirname( $fileD ) ) );
 
                $status = $this->backend->doOperations( array(
@@ -1184,7 +1230,7 @@ class FileBackendTest extends MediaWikiTestCase {
        }
 
        // concurrency orientated
-       function doTestDoOperations2() {
+       private function doTestDoOperations2() {
                $base = $this->baseStorePath();
 
                $fileAContents = '3tqtmoeatmn4wg4qe-mg3qt3 tq';
@@ -1208,7 +1254,7 @@ class FileBackendTest extends MediaWikiTestCase {
                $fileD = "$base/unittest-cont1/a/b/fileD.txt";
 
                $this->prepare( array( 'dir' => dirname( $fileA ) ) );
-               $this->backend->create( array( 'dst' => $fileA, 'content' => $fileAContents ) );
+               $this->create( array( 'dst' => $fileA, 'content' => $fileAContents ) );
                $this->prepare( array( 'dir' => dirname( $fileB ) ) );
                $this->prepare( array( 'dir' => dirname( $fileC ) ) );
                $this->prepare( array( 'dir' => dirname( $fileD ) ) );
@@ -1270,7 +1316,7 @@ class FileBackendTest extends MediaWikiTestCase {
                        "Correct file SHA-1 of $fileC" );
        }
 
-       function doTestDoOperationsFailing() {
+       private function doTestDoOperationsFailing() {
                $base = $this->baseStorePath();
 
                $fileA = "$base/unittest-cont2/a/b/fileA.txt";
@@ -1282,11 +1328,11 @@ class FileBackendTest extends MediaWikiTestCase {
                $fileD = "$base/unittest-cont2/a/b/fileD.txt";
 
                $this->prepare( array( 'dir' => dirname( $fileA ) ) );
-               $this->backend->create( array( 'dst' => $fileA, 'content' => $fileAContents ) );
+               $this->create( array( 'dst' => $fileA, 'content' => $fileAContents ) );
                $this->prepare( array( 'dir' => dirname( $fileB ) ) );
-               $this->backend->create( array( 'dst' => $fileB, 'content' => $fileBContents ) );
+               $this->create( array( 'dst' => $fileB, 'content' => $fileBContents ) );
                $this->prepare( array( 'dir' => dirname( $fileC ) ) );
-               $this->backend->create( array( 'dst' => $fileC, 'content' => $fileCContents ) );
+               $this->create( array( 'dst' => $fileC, 'content' => $fileCContents ) );
 
                $status = $this->backend->doOperations( array(
                        array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC, 'overwrite' => 1 ),
@@ -1371,7 +1417,7 @@ class FileBackendTest extends MediaWikiTestCase {
                        $this->prepare( array( 'dir' => dirname( $file ) ) );
                        $ops[] = array( 'op' => 'create', 'content' => 'xxy', 'dst' => $file );
                }
-               $status = $this->backend->doOperations( $ops );
+               $status = $this->backend->doQuickOperations( $ops );
                $this->assertGoodStatus( $status,
                        "Creation of files succeeded ($backendName)." );
                $this->assertEquals( true, $status->isOK(),
@@ -1524,7 +1570,7 @@ class FileBackendTest extends MediaWikiTestCase {
                        $this->prepare( array( 'dir' => dirname( $file ) ) );
                        $ops[] = array( 'op' => 'create', 'content' => 'xxy', 'dst' => $file );
                }
-               $status = $this->backend->doOperations( $ops );
+               $status = $this->backend->doQuickOperations( $ops );
                $this->assertGoodStatus( $status,
                        "Creation of files succeeded ($backendName)." );
                $this->assertEquals( true, $status->isOK(),
@@ -1721,10 +1767,15 @@ class FileBackendTest extends MediaWikiTestCase {
 
        // test helper wrapper for backend prepare() function
        private function prepare( array $params ) {
-               $this->dirsToPrune[] = $params['dir'];
                return $this->backend->prepare( $params );
        }
 
+       // test helper wrapper for backend prepare() function
+       private function create( array $params ) {
+               $params['op'] = 'create';
+               return $this->backend->doQuickOperations( array( $params ) );
+       }
+
        function tearDownFiles() {
                foreach ( $this->filesToPrune as $file ) {
                        @unlink( $file );
@@ -1733,10 +1784,7 @@ class FileBackendTest extends MediaWikiTestCase {
                foreach ( $containers as $container ) {
                        $this->deleteFiles( $container );
                }
-               foreach ( $this->dirsToPrune as $dir ) {
-                       $this->recursiveClean( $dir );
-               }
-               $this->filesToPrune = $this->dirsToPrune = array();
+               $this->filesToPrune = array();
        }
 
        private function deleteFiles( $container ) {
@@ -1748,10 +1796,7 @@ class FileBackendTest extends MediaWikiTestCase {
                                        array( 'force' => 1, 'nonLocking' => 1 ) );
                        }
                }
-       }
-
-       private function recursiveClean( $dir ) {
-               $this->backend->clean( array( 'dir' => $dir, 'recursive' => 1 ) );
+               $this->backend->clean( array( 'dir' => "$base/$container", 'recursive' => 1 ) );
        }
 
        function assertGoodStatus( $status, $msg ) {