Seb35 has submitted this change and it was merged.

Change subject: Improvement of CLI scripts
......................................................................


Improvement of CLI scripts

Code:
* In case of error, exit codes in CLI were wrongly the same as
  HTTP return codes, but exit codes in CLI can only be between 0
  and 255, so documented some standard codes and implemented it
  (0=success, 1=missing wiki, 4=user error, 5=internal error)
* Deleted the method AbstractMediaWikiFarmScript::postmain which
  was not really useful
* Now AbstractMediaWikiFarmScript::premain and ::main return a
  boolean about success (and detailled error is in status property)
* Added methods AbstractMediaWikiFarmScript::rmdirr and ::copyr to
  recursively delete and copy directories, it will be useful to
  manage extensions with Composer
* Removed the use of "new static", which is not PHP 5.2 compatible,
  this temporarily break the performance test

Bugs:
* When a global array does not exist and we add some elements, a
  warning was trigerred in MediaWikiFarm::loadMediaWikiConfig
* Be sure wg* variables are syntactically correct for PHP, it was
  not the case for "wgUseExtensionConfirmEdit/QuestyCaptcha" but
  slash must be here in wfLoadExtension('ConfirmEdit/QuestyCaptcha')
  so remove the slash and any incorrect character after detecting
  extension loading mechanism

Change-Id: I02db05b939b968fca4b63fe57ea1bd8804c25b78
---
M .gitignore
M bin/mwscript.php
M src/AbstractMediaWikiFarmScript.php
M src/MediaWikiFarm.php
M src/MediaWikiFarmScript.php
M tests/phpunit/ConfigurationTest.php
M tests/phpunit/InstallationIndependantTest.php
M tests/phpunit/LoadingTest.php
M tests/phpunit/MediaWikiFarmScriptTest.php
M tests/phpunit/MediaWikiFarmTestCase.php
M tests/phpunit/data/config/extensionssettings.php
M tests/phpunit/data/config/settings.php
12 files changed, 298 insertions(+), 63 deletions(-)

Approvals:
  Seb35: Verified; Looks good to me, approved



diff --git a/.gitignore b/.gitignore
index 49fc920..fa4674d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,6 +3,8 @@
 .swp
 .*.swp
 *~
+.DS_Store
+*.kate-swp
 
 # Composer & npm
 /composer.lock
diff --git a/bin/mwscript.php b/bin/mwscript.php
index 0cc21ee..14751bf 100644
--- a/bin/mwscript.php
+++ b/bin/mwscript.php
@@ -21,9 +21,7 @@
 
 $wgMediaWikiFarmScript->load();
 
-$wgMediaWikiFarmScript->main();
-
-if( $wgMediaWikiFarmScript->status == 200 ) {
+if( $wgMediaWikiFarmScript->main() ) {
 
        # Execute the script
        require $wgMediaWikiFarmScript->argv[0];
diff --git a/src/AbstractMediaWikiFarmScript.php 
b/src/AbstractMediaWikiFarmScript.php
index 1c0e972..328930b 100644
--- a/src/AbstractMediaWikiFarmScript.php
+++ b/src/AbstractMediaWikiFarmScript.php
@@ -16,6 +16,13 @@
  * Using a class instead of a raw script it better for testability purposes 
and to use
  * less global variables (in fact none; the only global variable written are 
for
  * compatibility purposes, e.g. PHPUnit expects $_SERVER['argv']).
+ *
+ * It is recommended to use the following values for status (in CLI, it must 
be a number
+ * between 0 and 255) and explain it in long help:
+ *   - 0 = success
+ *   - 1 = missing wiki (similar to HTTP 404)
+ *   - 4 = user error, like a missing parameter (similar to HTTP 400)
+ *   - 5 = internal error in farm configuration (similar to HTTP 500)
  */
 abstract class AbstractMediaWikiFarmScript {
 
@@ -152,9 +159,7 @@
                @include_once dirname( dirname( __FILE__ ) ) . 
'/config/MediaWikiFarmDirectories.php';
 
                # Load MediaWikiFarm class symbol
-               // @codingStandardsIgnoreStart 
MediaWiki.Usage.DirUsage.FunctionFound
                require_once dirname( dirname( __FILE__ ) ) . 
'/src/MediaWikiFarm.php';
-               // @codingStandardsIgnoreEnd
        }
 
        /**
@@ -162,7 +167,7 @@
         *
         * NB: although it can be seen as superfluous, this is required in some 
cases to wipe off
         * the presence of MediaWikiFarm. The MediaWiki script 
'tests/phpunit/phpunit.php' and PHPUnit
-        * need it (precisely $_SERVER['argv']; the other are for consistency).
+        * need it (precisely $_SERVER['argv']; the others are for consistency).
         * Perhaps in the future some other globals will be changed, like in 
$_SERVER: PWD, PHP_SELF,
         * SCRIPT_NAME, SCRIPT_FILENAME, PATH_TRANSLATED, if it is needed.
         *
@@ -182,42 +187,28 @@
        /**
         * Main program for the script, preliminary part.
         *
-        * Although it returns void, the 'status' property can say if there was 
an error or not,
-        * and if it becomes different than 0, the main program will (should) 
return.
-        *
-        * @return void.
+        * @return bool If false, the main program should return.
         */
        function premain() {
 
                # Return usage
                if( $this->argc == 2 && ( $this->argv[1] == '-h' || 
$this->argv[1] == '--help' ) ) {
                        $this->usage( true );
-                       $this->status = 204;
-                       return;
+                       return false;
                }
+
+               return true;
        }
 
        /**
         * Main program for the script, preliminary part.
         *
-        * Although it returns void, the 'status' property says if there was an 
error or not.
+        * This function return true in case of success (else false), but a 
more detailled status should be indicated in
+        * the object property 'status'.
         *
-        * @return void.
+        * @return bool If false, there was an error in the program.
         */
        abstract function main();
-
-       /**
-        * Main program for the script, postliminary part.
-        *
-        * @return void.
-        */
-       function postmain() {
-
-               # Export symbols
-               $this->exportArguments();
-
-               $this->status = 200;
-       }
 
        /**
         * Post-execution of the main script, only needed in the case 
'maintenance/update.php' is run (see main documentation).
@@ -225,4 +216,109 @@
         * @return void.
         */
        function restInPeace() {}
+
+
+
+       /*
+        * Utility functions
+        * ----------------- */
+
+       /**
+        * Recursively delete a directory.
+        *
+        * @param string $dir Directory path.
+        * @param bool $deleteDir Delete the root directory (or leave it empty).
+        * @return void.
+        */
+       static function rmdirr( $dir, $deleteDir = true ) {
+
+               if( !is_dir( $dir ) ) {
+                       if( is_file( $dir ) || is_link( $dir ) ) {
+                               unlink( $dir );
+                       }
+                       return;
+               }
+
+               $files = array_diff( scandir( $dir ), array( '.', '..' ) );
+               foreach( $files as $file ) {
+                       if( is_dir( $dir . '/' . $file ) ) {
+                               self::rmdirr( $dir . '/' . $file );
+                       } else {
+                               unlink( $dir . '/' . $file );
+                       }
+               }
+
+               if( $deleteDir ) {
+                       rmdir( $dir );
+               }
+       }
+
+       /**
+        * Recursively copy a directory.
+        *
+        * @param string $source Source path, can be a normal file or a 
directory.
+        * @param string $dest Destination path, should be a directory.
+        * @param bool $force If true, delete the destination directory before 
beginning.
+        * @param string[] $blacklist Regular expression to blacklist some 
files; if begins
+        *                 with '/', only files from the root directory will be 
considered.
+        * @param string[] $whitelist Regular expression to whitelist only some 
files; if begins
+        *                 with '/', only files from the root directory will be 
considered.
+        * @param string $base Internal parameter to track the base directory.
+        * @return void.
+        */
+       function copyr( $source, $dest, $force = false, $blacklist = array(), 
$whitelist = null, $base = '' ) {
+
+               # Return if we are considering a blacklisted file
+               foreach( $blacklist as $file ) {
+                       if( preg_match( '|' . ( $file{0} == '/' ? '^' : '' ) . 
$file . '$|', $base ) ) {
+                               return;
+                       }
+               }
+
+               # Return if we are considering a non-whitelisted file
+               if( is_array( $whitelist ) && $base ) {
+                       $isWhitelisted = false;
+                       foreach( $whitelist as $file ) {
+                               if( preg_match( '|' . ( $file{0} == '/' ? '^' : 
'' ) . $file . '$|', $base ) ) {
+                                       $isWhitelisted = true;
+                                       break;
+                               }
+                       }
+                       if( !$isWhitelisted ) {
+                               return;
+                       }
+               }
+
+               # Delete the destination directory (only in the first call, not 
in recursion)
+               if( $force && is_dir( $dest ) ) {
+                       self::rmdirr( $dest, false );
+               }
+               /*elseif( is_dir( $source ) ) {
+                       $dest = dirname( $dest );
+               }*/
+
+               # Leaf: file; stop the recursion by copying the file
+               if( is_file( $source ) ) {
+                       if( !is_dir( $dest ) ) {
+                               mkdir( $dest );
+                       }
+                       copy( $source, $dest . '/' . basename( $source ) );
+               }
+
+               # General node: directory - continue the recursion by calling 
the function on files and directories
+               elseif( is_dir( $source ) ) {
+                       $files = array_diff( scandir( $source ), array( '.', 
'..' ) );
+                       if( !is_dir( $dest ) ) {
+                               mkdir( $dest );
+                       }
+                       foreach( $files as $file ) {
+                               if( is_file( $source . '/' . $file ) ) {
+                                       self::copyr( $source . '/' . $file, 
$dest, false, $blacklist, $whitelist, $base . '/' . $file );
+                               }
+                               elseif( is_dir( $source . '/' . $file ) ) {
+                                       self::copyr( $source . '/' . $file, 
$dest . '/' . $file, false, $blacklist, $whitelist, $base . '/' . $file );
+                               }
+                       }
+               }
+       }
 }
diff --git a/src/MediaWikiFarm.php b/src/MediaWikiFarm.php
index 0b24d82..98d3994 100644
--- a/src/MediaWikiFarm.php
+++ b/src/MediaWikiFarm.php
@@ -219,7 +219,7 @@
 
                try {
                        # Initialise object
-                       $wgMediaWikiFarm = new static( $host, 
$wgMediaWikiFarmConfigDir, $wgMediaWikiFarmCodeDir, $wgMediaWikiFarmCacheDir, 
$entryPoint );
+                       $wgMediaWikiFarm = new MediaWikiFarm( $host, 
$wgMediaWikiFarmConfigDir, $wgMediaWikiFarmCodeDir, $wgMediaWikiFarmCacheDir, 
$entryPoint );
 
                        # Check existence
                        $exists = $wgMediaWikiFarm->checkExistence();
@@ -353,6 +353,9 @@
                # Merge general array parameters into global variables
                foreach( $this->configuration['arrays'] as $setting => $value ) 
{
 
+                       if( !array_key_exists( $setting, $GLOBALS ) ) {
+                               $GLOBALS[$setting] = array();
+                       }
                        $GLOBALS[$setting] = self::arrayMerge( 
$GLOBALS[$setting], $value );
                }
 
@@ -1302,15 +1305,18 @@
                                $loadingMechanism = 
$this->detectLoadingMechanism( 'extension', $name );
                                if( !is_null( $loadingMechanism ) ) {
                                        
$this->configuration['extensions'][$name] = $loadingMechanism;
-                                       $settings['wgUseExtension'.$name] = 
true;
-                                       continue;
+                                       
$settings['wgUseExtension'.preg_replace( '/[^a-zA-Z0-9_\x7f\xff]/', '', $name 
)] = true;
+                               } else {
+                                       $loadingMechanism = 
$this->detectLoadingMechanism( 'skin', $name );
+                                       if( !is_null( $loadingMechanism ) ) {
+                                               
$this->configuration['skins'][$name] = $loadingMechanism;
+                                               
$settings['wgUseSkin'.preg_replace( '/[^a-zA-Z0-9_\x7f\xff]/', '', $name )] = 
true;
+                                       }
                                }
-
-                               $loadingMechanism = 
$this->detectLoadingMechanism( 'skin', $name );
-                               if( !is_null( $loadingMechanism ) ) {
-                                       $this->configuration['skins'][$name] = 
$loadingMechanism;
-                                       $settings['wgUseSkin'.$name] = true;
-                               }
+                       }
+                       if( preg_match( '/[^a-zA-Z0-9_\x7f\xff]/', $setting ) ) 
{
+                               $settings[preg_replace( 
'/[^a-zA-Z0-9_\x7f\xff]/', '', $setting )] = $settings[$setting];
+                               unset( $settings[$setting] );
                        }
                }
        }
@@ -1398,6 +1404,12 @@
                $localSettings .= "\n# General settings\n";
                foreach( $configuration['settings'] as $setting => $value ) {
                        $localSettings .= "\$$setting = " . var_export( $value, 
true ) . ";\n";
+               }
+
+               # Array settings
+               $localSettings .= "\n# Array settings\n";
+               foreach( $configuration['arrays'] as $setting => $value ) {
+                       $localSettings .= "if( !array_key_exists( '$setting', 
\$GLOBALS ) ) {\n\t\$GLOBALS['$setting'] = array();\n}\n";
                }
                foreach( $configuration['arrays'] as $setting => $value ) {
                        $localSettings .= self::writeArrayAssignment( $value, 
"\$$setting" );
@@ -1510,9 +1522,9 @@
                $files[] = $dir . 'FunctionsTest.php';
                $files[] = $dir . 'InstallationIndependantTest.php';
                $files[] = $dir . 'LoadingTest.php';
+               $files[] = $dir . 'MediaWikiFarmScriptTest.php';
                $files[] = $dir . 'MonoversionInstallationTest.php';
                $files[] = $dir . 'MultiversionInstallationTest.php';
-               $files[] = $dir . 'ScriptTest.php';
 
                return true;
        }
diff --git a/src/MediaWikiFarmScript.php b/src/MediaWikiFarmScript.php
index 05df818..d894999 100644
--- a/src/MediaWikiFarmScript.php
+++ b/src/MediaWikiFarmScript.php
@@ -51,6 +51,12 @@
     | For easier use, you can alias it in your shell:
     |
     |     alias mwscript='php $fullPath'
+    |
+    | Return codes:
+    | 0 = success
+    | 1 = missing wiki (similar to HTTP 404)
+    | 4 = user error, like a missing parameter (similar to HTTP 400)
+    | 5 = internal error in farm configuration (similar to HTTP 500)
 
 HELP;
        }
@@ -58,24 +64,24 @@
        /**
         * Main program for the script.
         *
-        * Although it returns void, the 'status' property says if there was an 
error or not.
+        * This function return true in case of success (else false), but a 
more detailled status should be indicated in
+        * the object property 'status'.
         *
-        * @return void.
+        * @return bool If false, there was an error in the program.
         */
        function main() {
 
                # Manage mandatory arguments.
-               $this->premain();
-               if( $this->status ) {
-                       return;
+               if( !$this->premain() ) {
+                       return false;
                }
 
                # Get wiki
                $this->host = $this->getParam( 'wiki' );
                if( is_null( $this->host ) ) {
                        $this->usage();
-                       $this->status = 400;
-                       return;
+                       $this->status = 4;
+                       return false;
                }
 
                # Get script
@@ -86,8 +92,8 @@
 
                if( is_null( $this->script ) ) {
                        $this->usage();
-                       $this->status = 400;
-                       return;
+                       $this->status = 4;
+                       return false;
                }
 
                # Replace the caller script by the MediaWiki script
@@ -97,14 +103,17 @@
 
                # Initialise the requested version
                $code = MediaWikiFarm::load( $this->script, $this->host );
-               if( $code != 200 ) {
-                       $this->status = $code;
-                       return;
+               if( $code == 404 ) {
+                       $this->status = 1;
+                       return false;
+               } elseif( $code == 500 ) {
+                       $this->status = 5;
+                       return false;
                }
                if( !is_file( $this->script ) ) {
                        echo "Script not found.\n";
-                       $this->status = 400;
-                       return;
+                       $this->status = 4;
+                       return false;
                }
 
 
@@ -125,7 +134,10 @@
 
 PARAMS;
 
-               $this->postmain();
+               # Export symbols
+               $this->exportArguments();
+
+               return true;
        }
 
        /**
diff --git a/tests/phpunit/ConfigurationTest.php 
b/tests/phpunit/ConfigurationTest.php
index 0305610..1100a0c 100644
--- a/tests/phpunit/ConfigurationTest.php
+++ b/tests/phpunit/ConfigurationTest.php
@@ -49,6 +49,7 @@
                                'wgUseSkinMonoBook' => false,
                                'wgUseExtensionParserFunctions' => true,
                                'wgUseExtensionCentralAuth' => false,
+                               'wgUseExtensionConfirmEdit/QuestyCaptcha' => 
true,
                                'wgUseLocalExtensionSmartLinks' => true,
                                'wgUseLocalExtensionChangeTabs' => false,
                                'wgServer' => 
'https://a.testfarm-monoversion.example.org',
@@ -141,6 +142,9 @@
                $farm->getMediaWikiConfig();
                $config = $farm->getConfiguration( 'settings' );
                $this->assertTrue( $config['wgUsePathInfo'] );
+               $this->assertFalse( array_key_exists( 
'wgUseExtensionConfirmEdit/QuestyCaptcha', $config ) );
+               $this->assertTrue( array_key_exists( 
'wgUseExtensionConfirmEditQuestyCaptcha', $config ) );
+               $this->assertFalse( 
$config['wgUseExtensionConfirmEditQuestyCaptcha'] );
 
                # Re-load to use config cache
                $farm = new MediaWikiFarm( 
'b.testfarm-multiversion-test-extensions.example.org',
@@ -150,6 +154,9 @@
                $farm->getMediaWikiConfig( true );
                $config = $farm->getConfiguration( 'settings' );
                $this->assertTrue( $config['wgUsePathInfo'] );
+               $this->assertFalse( array_key_exists( 
'wgUseExtensionConfirmEdit/QuestyCaptcha', $config ) );
+               $this->assertTrue( array_key_exists( 
'wgUseExtensionConfirmEditQuestyCaptcha', $config ) );
+               $this->assertFalse( 
$config['wgUseExtensionConfirmEditQuestyCaptcha'] );
 
                $this->assertEquals(
                        self::$wgMediaWikiFarmCacheDir . 
'/testfarm-multiversion-test-extensions'
diff --git a/tests/phpunit/InstallationIndependantTest.php 
b/tests/phpunit/InstallationIndependantTest.php
index 3ed79a0..8a627cf 100644
--- a/tests/phpunit/InstallationIndependantTest.php
+++ b/tests/phpunit/InstallationIndependantTest.php
@@ -438,6 +438,20 @@
 \$wgMemCachedServers = array (
   0 => '127.0.0.1:11211',
 );
+
+# Array settings
+if( !array_key_exists( 'wgExtraNamespaces', \$GLOBALS ) ) {
+       \$GLOBALS['wgExtraNamespaces'] = array();
+}
+if( !array_key_exists( 'wgNamespaceAliases', \$GLOBALS ) ) {
+       \$GLOBALS['wgNamespaceAliases'] = array();
+}
+if( !array_key_exists( 'wgFileExtensions', \$GLOBALS ) ) {
+       \$GLOBALS['wgFileExtensions'] = array();
+}
+if( !array_key_exists( 'wgVirtualRestConfig', \$GLOBALS ) ) {
+       \$GLOBALS['wgVirtualRestConfig'] = array();
+}
 \$wgExtraNamespaces[100] = 'Bibliography';
 \$wgNamespaceAliases['Bibliography'] = 100;
 \$wgFileExtensions[] = 'djvu';
diff --git a/tests/phpunit/LoadingTest.php b/tests/phpunit/LoadingTest.php
index d430ae2..6acc395 100644
--- a/tests/phpunit/LoadingTest.php
+++ b/tests/phpunit/LoadingTest.php
@@ -91,6 +91,11 @@
                                'wgUseSkinTestSkinRequireOnce' => true,
                                'wgUseSkinTestSkinComposer' => true,
                        ),
+                       'arrays' => array(
+                               'wgFileExtensions' => array(
+                                       0 => 'djvu',
+                               ),
+                       ),
                        'extensions' => array(
                                'TestExtensionWfLoadExtension' => 
'wfLoadExtension',
                                'TestExtensionBiLoading' => 'wfLoadExtension',
@@ -105,6 +110,7 @@
                        ),
                );
                $this->backupGlobalVariables( array_keys( $result['settings'] ) 
);
+               $this->backupAndUnsetGlobalVariable( 'wgFileExtensions' );
 
                $exists = MediaWikiFarm::load( 'index.php', 
'a.testfarm-multiversion-test-extensions.example.org' );
                $this->assertEquals( 200, $exists );
@@ -112,6 +118,7 @@
 
                $wgMediaWikiFarm->loadMediaWikiConfig();
                $this->assertEquals( $result['settings'], 
$wgMediaWikiFarm->getConfiguration( 'settings' ) );
+               $this->assertEquals( $result['arrays'], 
$wgMediaWikiFarm->getConfiguration( 'arrays' ) );
                $this->assertEquals( $result['extensions'], 
$wgMediaWikiFarm->getConfiguration( 'extensions' ) );
                $this->assertEquals( $result['skins'], 
$wgMediaWikiFarm->getConfiguration( 'skins' ) );
 
@@ -125,6 +132,8 @@
 
                # Check that $result['settings'] (whose all values are 'true') 
is a subset of $trueGlobals
                $this->assertEmpty( array_diff( array_keys( $result['settings'] 
), $trueGlobals ) );
+               $this->assertTrue( array_key_exists( 'wgFileExtensions', 
$GLOBALS ) );
+               $this->assertEquals( $result['arrays']['wgFileExtensions'], 
$GLOBALS['wgFileExtensions'] );
 
                # Check that extensions+skins are in ExtensionRegistry queue
                if( class_exists( 'ExtensionRegistry' ) ) {
@@ -179,6 +188,7 @@
 
                                'wgUseExtensionTestExtensionMissing' => false,
                                'wgUseSkinTestSkinMissing' => false,
+                               'wgUseExtensionConfirmEditQuestyCaptcha' => 
false,
                                'wgUseTestExtensionMissing' => true,
                                'wgUseTestSkinMissing' => true,
 
diff --git a/tests/phpunit/MediaWikiFarmScriptTest.php 
b/tests/phpunit/MediaWikiFarmScriptTest.php
index 92415e9..012624b 100644
--- a/tests/phpunit/MediaWikiFarmScriptTest.php
+++ b/tests/phpunit/MediaWikiFarmScriptTest.php
@@ -54,6 +54,12 @@
     | For easier use, you can alias it in your shell:
     |
     |     alias mwscript='php $mwscriptPath'
+    |
+    | Return codes:
+    | 0 = success
+    | 1 = missing wiki (similar to HTTP 404)
+    | 4 = user error, like a missing parameter (similar to HTTP 400)
+    | 5 = internal error in farm configuration (similar to HTTP 500)
 
 
 HELP;
@@ -124,7 +130,7 @@
 
                $wgMediaWikiFarmScript->main();
 
-               $this->assertEquals( 204, $wgMediaWikiFarmScript->status );
+               $this->assertEquals( 0, $wgMediaWikiFarmScript->status );
        }
 
        /**
@@ -144,7 +150,7 @@
 
                $wgMediaWikiFarmScript->main();
 
-               $this->assertEquals( 204, $wgMediaWikiFarmScript->status );
+               $this->assertEquals( 0, $wgMediaWikiFarmScript->status );
        }
 
        /**
@@ -250,7 +256,7 @@
 
                $wgMediaWikiFarmScript->main();
 
-               $this->assertEquals( 400, $wgMediaWikiFarmScript->status );
+               $this->assertEquals( 4, $wgMediaWikiFarmScript->status );
        }
 
        /**
@@ -271,7 +277,7 @@
 
                $wgMediaWikiFarmScript->main();
 
-               $this->assertEquals( 400, $wgMediaWikiFarmScript->status );
+               $this->assertEquals( 4, $wgMediaWikiFarmScript->status );
                $this->assertNull( $wgMediaWikiFarmScript->script );
                $this->assertEquals( 1, $wgMediaWikiFarmScript->argc );
                $this->assertEquals( array( self::$mwscriptPath ), 
$wgMediaWikiFarmScript->argv );
@@ -308,8 +314,46 @@
 
                $wgMediaWikiFarmScript->main();
 
-               $this->assertEquals( 404, $wgMediaWikiFarmScript->status );
+               $this->assertEquals( 1, $wgMediaWikiFarmScript->status );
                $this->assertEquals( 
'c.testfarm-monoversion-with-file-variable-without-version.example.org', 
$wgMediaWikiFarmScript->host );
+               $this->assertEquals( 'maintenance/showJobs.php', 
$wgMediaWikiFarmScript->script );
+               $this->assertEquals( 1, $wgMediaWikiFarmScript->argc );
+               $this->assertEquals( array( 'maintenance/showJobs.php' ), 
$wgMediaWikiFarmScript->argv );
+       }
+
+       /**
+        * Test internal problem.
+        *
+        * @backupGlobals enabled
+        * @covers MediaWikiFarmScript::main
+        * @uses MediaWikiFarmScript::__construct
+        * @uses MediaWikiFarmScript::getParam
+        * @uses AbstractMediaWikiFarmScript::__construct
+        * @uses AbstractMediaWikiFarmScript::premain
+        * @uses MediaWikiFarm::load
+        * @uses MediaWikiFarm::__construct
+        * @uses MediaWikiFarm::selectFarm
+        * @uses MediaWikiFarm::checkExistence
+        * @uses MediaWikiFarm::checkHostVariables
+        * @uses MediaWikiFarm::setVariable
+        * @uses MediaWikiFarm::replaceVariables
+        * @uses MediaWikiFarm::readFile
+        */
+       function testInternalProblem() {
+
+               $this->backupAndUnsetGlobalVariable( 'wgMediaWikiFarm' );
+               $this->backupAndSetGlobalVariable( 'wgMediaWikiFarmConfigDir', 
self::$wgMediaWikiFarmConfigDir );
+               $this->backupAndSetGlobalVariable( 'wgMediaWikiFarmCodeDir', 
null );
+               $this->backupAndSetGlobalVariable( 'wgMediaWikiFarmCacheDir', 
false );
+
+               $wgMediaWikiFarmScript = new MediaWikiFarmScript( 3,
+                       array( self::$mwscriptPath, 
'--wiki=a.testfarm-with-badly-formatted-file-variable.example.org', 'showJobs' )
+               );
+
+               $wgMediaWikiFarmScript->main();
+
+               $this->assertEquals( 5, $wgMediaWikiFarmScript->status );
+               $this->assertEquals( 
'a.testfarm-with-badly-formatted-file-variable.example.org', 
$wgMediaWikiFarmScript->host );
                $this->assertEquals( 'maintenance/showJobs.php', 
$wgMediaWikiFarmScript->script );
                $this->assertEquals( 1, $wgMediaWikiFarmScript->argc );
                $this->assertEquals( array( 'maintenance/showJobs.php' ), 
$wgMediaWikiFarmScript->argv );
@@ -348,7 +392,7 @@
 
                $wgMediaWikiFarmScript->main();
 
-               $this->assertEquals( 400, $wgMediaWikiFarmScript->status );
+               $this->assertEquals( 4, $wgMediaWikiFarmScript->status );
                $this->assertEquals( 'a.testfarm-monoversion.example.org', 
$wgMediaWikiFarmScript->host );
                $this->assertEquals( 'maintenance/veryMissingScript.php', 
$wgMediaWikiFarmScript->script );
                $this->assertEquals( 1, $wgMediaWikiFarmScript->argc );
@@ -361,7 +405,6 @@
         * @backupGlobals enabled
         * @covers MediaWikiFarmScript::main
         * @covers AbstractMediaWikiFarmScript::premain
-        * @covers AbstractMediaWikiFarmScript::postmain
         * @uses MediaWikiFarmScript::__construct
         * @uses MediaWikiFarmScript::getParam
         * @uses MediaWikiFarmScript::exportArguments
@@ -405,7 +448,7 @@
 
                $wgMediaWikiFarmScript->main();
 
-               $this->assertEquals( 200, $wgMediaWikiFarmScript->status );
+               $this->assertEquals( 0, $wgMediaWikiFarmScript->status );
                $this->assertEquals( 'a.testfarm-monoversion.example.org', 
$wgMediaWikiFarmScript->host );
                $this->assertEquals( 'maintenance/showJobs.php', 
$wgMediaWikiFarmScript->script );
                $this->assertEquals( 1, $wgMediaWikiFarmScript->argc );
@@ -423,7 +466,6 @@
         * @uses MediaWikiFarmScript::exportArguments
         * @uses AbstractMediaWikiFarmScript::__construct
         * @uses AbstractMediaWikiFarmScript::premain
-        * @uses AbstractMediaWikiFarmScript::postmain
         * @uses MediaWikiFarm::load
         * @uses MediaWikiFarm::__construct
         * @uses MediaWikiFarm::selectFarm
@@ -466,10 +508,39 @@
                $wgMediaWikiFarmScript->main();
                $wgMediaWikiFarmScript->restInPeace();
 
-               $this->assertEquals( 200, $wgMediaWikiFarmScript->status );
+               $this->assertEquals( 0, $wgMediaWikiFarmScript->status );
 
                # For coverage
                unset( $GLOBALS['wgMediaWikiFarm'] );
                $wgMediaWikiFarmScript->restInPeace();
        }
+
+       /**
+        * Test routines for copying and deleting directories.
+        *
+        * @covers MediaWikiFarmScript::copyr
+        * @covers MediaWikiFarmScript::rmdirr
+        * @uses MediaWikiFarmScript::__construct
+        * @uses AbstractMediaWikiFarmScript::__construct
+        */
+       function testRecursiveCopyAndDelete() {
+
+               $wgMediaWikiFarmScript = new MediaWikiFarmScript( 3, array( 
self::$mwscriptPath, '--wiki=a.testfarm-monoversion.example.org', 'showJobs' ) 
);
+
+               MediaWikiFarmScript::copyr( self::$wgMediaWikiFarmCodeDir2 . 
'/vstub', dirname( __FILE__ ) . '/data/copie', true, array( 
'/skins/TestSkinEmpty', 'TestSkinRequireOnce' ) );
+               MediaWikiFarmScript::copyr( self::$wgMediaWikiFarmCodeDir2 . 
'/vstub/includes/DefaultSettings.php', dirname( __FILE__ ) . 
'/data/copie/newdir', true );
+               $this->assertTrue( is_file( dirname( __FILE__ ) . 
'/data/copie/includes/DefaultSettings.php' ) );
+               $this->assertTrue( is_file( dirname( __FILE__ ) . 
'/data/copie/newdir/DefaultSettings.php' ) );
+               $this->assertFalse( file_exists( dirname( __FILE__ ) . 
'/data/copie/skins/TestSkinEmpty' ) );
+               $this->assertFalse( file_exists( dirname( __FILE__ ) . 
'/data/copie/skins/TestSkinRequireOnce' ) );
+
+               MediaWikiFarmScript::rmdirr( dirname( __FILE__ ) . 
'/data/copie/includes/DefaultSettings.php', true );
+               $this->assertFalse( file_exists( dirname( __FILE__ ) . 
'/data/copie/includes/DefaultSettings.php' ) );
+
+               MediaWikiFarmScript::copyr( self::$wgMediaWikiFarmCodeDir2 . 
'/vstub', dirname( __FILE__ ) . '/data/copie', true, array(), array( '/', 
'/includes', '/includes/.*' ) );
+               $this->assertTrue( is_file( dirname( __FILE__ ) . 
'/data/copie/includes/DefaultSettings.php' ) );
+
+               MediaWikiFarmScript::rmdirr( dirname( __FILE__ ) . 
'/data/copie', true );
+               $this->assertFalse( file_exists( dirname( __FILE__ ) . 
'/data/copie' ) );
+       }
 }
diff --git a/tests/phpunit/MediaWikiFarmTestCase.php 
b/tests/phpunit/MediaWikiFarmTestCase.php
index 36d025a..5228ce0 100644
--- a/tests/phpunit/MediaWikiFarmTestCase.php
+++ b/tests/phpunit/MediaWikiFarmTestCase.php
@@ -13,8 +13,11 @@
        /** @var string Configuration directory for tests. */
        public static $wgMediaWikiFarmConfigDir = '';
 
-       /** @var string Code directory for tests. */
+       /** @var string Code directory of the real installation. */
        public static $wgMediaWikiFarmCodeDir = '';
+
+       /** @var string Code directory created for tests. */
+       public static $wgMediaWikiFarmCodeDir2 = '';
 
        /** @var string Cache directory for tests. */
        public static $wgMediaWikiFarmCacheDir = '';
@@ -72,6 +75,7 @@
                # Set test configuration parameters
                self::$wgMediaWikiFarmConfigDir = dirname( __FILE__ ) . 
'/data/config';
                self::$wgMediaWikiFarmCodeDir = dirname( $IP );
+               self::$wgMediaWikiFarmCodeDir2 = dirname( __FILE__ ) . 
'/data/mediawiki';
                self::$wgMediaWikiFarmCacheDir = dirname( __FILE__ ) . 
'/data/cache';
 
                # Create versions.php: the list of existing values for variable 
'$WIKIID' with their associated versions
diff --git a/tests/phpunit/data/config/extensionssettings.php 
b/tests/phpunit/data/config/extensionssettings.php
index d6f0cbc..c478294 100644
--- a/tests/phpunit/data/config/extensionssettings.php
+++ b/tests/phpunit/data/config/extensionssettings.php
@@ -25,12 +25,20 @@
        'wgUseTestSkinComposer' => array(
                'atestextensionsfarm' => true,
        ),
+       '+wgFileExtensions' => array(
+               'atestextensionsfarm' => array(
+                       0 => 'djvu',
+               ),
+       ),
        'wgUseExtensionTestExtensionWfLoadExtension' => array(
                'btestextensionsfarm' => true,
        ),
        'wgUseSkinTestSkinWfLoadSkin' => array(
                'btestextensionsfarm' => true,
        ),
+       'wgUseExtensionConfirmEdit/QuestyCaptcha' => array(
+               'btestextensionsfarm' => true,
+       ),
        'wgUsePathInfo' => array(
                'btestextensionsfarm' => true,
        ),
diff --git a/tests/phpunit/data/config/settings.php 
b/tests/phpunit/data/config/settings.php
index e68681e..f08fc2d 100644
--- a/tests/phpunit/data/config/settings.php
+++ b/tests/phpunit/data/config/settings.php
@@ -36,6 +36,7 @@
        # Extensions
        'wgUseExtensionParserFunctions' => true,
        'wgUseExtensionCentralAuth' => false,
+       'wgUseExtensionConfirmEdit/QuestyCaptcha' => true,
 
        # Local extensions (flags used in some PHP file)
        'wgUseLocalExtensionSmartLinks' => true,

-- 
To view, visit https://gerrit.wikimedia.org/r/311624
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I02db05b939b968fca4b63fe57ea1bd8804c25b78
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MediaWikiFarm
Gerrit-Branch: master
Gerrit-Owner: Seb35 <seb35wikipe...@gmail.com>
Gerrit-Reviewer: Seb35 <seb35wikipe...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to