Merge "[FileBackend] Added more tests and fixed some local copy/reference bugs."
authorDemon <chadh@wikimedia.org>
Thu, 18 Oct 2012 18:37:24 +0000 (18:37 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 18 Oct 2012 18:37:24 +0000 (18:37 +0000)
includes/filebackend/FSFileBackend.php
tests/phpunit/includes/filerepo/FileBackendTest.php

index 0922919..dd43f82 100644 (file)
@@ -670,8 +670,8 @@ class FSFileBackend extends FileBackendStore {
 
                foreach ( $params['srcs'] as $src ) {
                        $source = $this->resolveToFSPath( $src );
-                       if ( $source === null ) {
-                               $fsFiles[$src] = null; // invalid path
+                       if ( $source === null || !is_file( $source ) ) {
+                               $fsFiles[$src] = null; // invalid path or file does not exist
                        } else {
                                $fsFiles[$src] = new FSFile( $source );
                        }
@@ -700,7 +700,9 @@ class FSFileBackend extends FileBackendStore {
                                } else {
                                        $tmpPath = $tmpFile->getPath();
                                        // Copy the source file over the temp file
+                                       wfSuppressWarnings();
                                        $ok = copy( $source, $tmpPath );
+                                       wfRestoreWarnings();
                                        if ( !$ok ) {
                                                $tmpFiles[$src] = null;
                                        } else {
index f159d5d..7201eec 100644 (file)
@@ -1113,6 +1113,32 @@ class FileBackendTest extends MediaWikiTestCase {
                return $cases;
        }
 
+       public function testGetLocalCopyAndReference404() {
+               $this->backend = $this->singleBackend;
+               $this->tearDownFiles();
+               $this->doTestGetLocalCopyAndReference404();
+               $this->tearDownFiles();
+
+               $this->backend = $this->multiBackend;
+               $this->tearDownFiles();
+               $this->doTestGetLocalCopyAndReference404();
+               $this->tearDownFiles();
+       }
+
+       public function doTestGetLocalCopyAndReference404() {
+               $backendName = $this->backendClass();
+
+               $base = self::baseStorePath();
+
+               $tmpFile = $this->backend->getLocalCopy( array(
+                       'src' => "$base/unittest-cont1/not-there" ) );
+               $this->assertEquals( null, $tmpFile, "Local copy of not existing file is null ($backendName)." );
+
+               $tmpFile = $this->backend->getLocalReference( array(
+                       'src' => "$base/unittest-cont1/not-there" ) );
+               $this->assertEquals( null, $tmpFile, "Local ref of not existing file is null ($backendName)." );
+       }
+
        /**
         * @dataProvider provider_testPrepareAndClean
         */