merged master some more
[lhc/web/wiklou.git] / tests / phpunit / includes / filerepo / StoreBatchTest.php
index 7979769..6abceeb 100644 (file)
@@ -1,29 +1,45 @@
 <?php
 /**
- * @group Filerepo
+ * @group FileRepo
  */
 class StoreBatchTest extends MediaWikiTestCase {
 
        public function setUp() {
+               global $wgFileBackends;
                parent::setUp();
-               
-               $this->repo = RepoGroup::singleton()->getLocalRepo();
+
+               # Forge a FSRepo object to not have to rely on local wiki settings
+               $tmpPrefix = wfTempDir() . '/storebatch-test-' . time() . '-' . mt_rand();
+               if ( $this->getCliArg( 'use-filebackend=' ) ) {
+                       $name = $this->getCliArg( 'use-filebackend=' );
+                       $useConfig = array();
+                       foreach ( $wgFileBackends as $conf ) {
+                               if ( $conf['name'] == $name ) {
+                                       $useConfig = $conf;
+                               }
+                       }
+                       $useConfig['name'] = 'local-testing'; // swap name
+                       $class = $useConfig['class'];
+                       $backend = new $class( $useConfig );
+               } else {
+                       $backend = new FSFileBackend( array(
+                               'name'        => 'local-testing',
+                               'lockManager' => 'nullLockManager',
+                               'containerPaths' => array(
+                                       'unittests-public'  => "{$tmpPrefix}-public",
+                                       'unittests-thumb'   => "{$tmpPrefix}-thumb",
+                                       'unittests-temp'    => "{$tmpPrefix}-temp",
+                                       'unittests-deleted' => "{$tmpPrefix}-deleted",
+                               )
+                       ) );
+               }
+               $this->repo = new FileRepo( array(
+                       'name'    => 'unittests',
+                       'backend' => $backend
+               ) );
+
                $this->date = gmdate( "YmdHis" );
                $this->createdFiles = array();
-               $this->users = array(
-                       'sysop' => new ApiTestUser(
-                               'Uploadstashtestsysop',
-                               'Upload Stash Test Sysop',
-                               'upload_stash_test_sysop@sample.com',
-                               array( 'sysop' )
-                       ),
-                       'uploader' => new ApiTestUser(
-                               'Uploadstashtestuser',
-                               'Upload Stash Test User',
-                               'upload_stash_test_user@sample.com',
-                               array()
-                       )
-               );
        }
 
        /**
@@ -43,8 +59,7 @@ class StoreBatchTest extends MediaWikiTestCase {
                $this->createdFiles[] = $result->value;
                return $result;
        }
-                                       
-       
+
        /**
         * Test storing a file using different flags.
         *
@@ -95,8 +110,13 @@ class StoreBatchTest extends MediaWikiTestCase {
        }
 
        public function tearDown() {
-               $this->repo->cleanupBatch( $this->createdFiles );
+               $this->repo->cleanupBatch( $this->createdFiles ); // delete files
+               foreach ( $this->createdFiles as $tmp ) { // delete dirs
+                       $tmp = $this->repo->resolveVirtualUrl( $tmp );
+                       while ( $tmp = FileBackend::parentStoragePath( $tmp ) ) {
+                               $this->repo->getBackend()->clean( array( 'dir' => $tmp ) );
+                       }
+               }
                parent::tearDown();
-               
        }
 }