Seb35 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/394974 )

Change subject: Alternative declaration of wikis for small setups
......................................................................

Alternative declaration of wikis for small setups

This was suggested in T181212 and will improve the first experience
with MediaWikiFarm, but could be also useful for small setups.

Bug: T181212
Change-Id: I314e1a953d53b0540a8c78ec8e01aaddebd95c85
---
M src/MediaWikiFarm.php
M tests/phpunit/MonoversionInstallationTest.php
M tests/phpunit/data/config/farms.php
3 files changed, 56 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MediaWikiFarm 
refs/changes/74/394974/1

diff --git a/src/MediaWikiFarm.php b/src/MediaWikiFarm.php
index 365cbf8..71596cd 100644
--- a/src/MediaWikiFarm.php
+++ b/src/MediaWikiFarm.php
@@ -929,21 +929,27 @@
                        }
                        $value = $this->variables[ '$' . strtolower( $key ) ];
 
-                       # If every values are correct, continue
-                       if( !array_key_exists( 'file', $variable ) || 
!is_string( $variable['file'] ) ) {
+                       # Get the values
+                       if( array_key_exists( 'file', $variable ) && is_string( 
$variable['file'] ) ) {
+
+                               # Really check if the variable is in the 
listing file
+                               $filename = $this->replaceVariables( 
$variable['file'] );
+                               $choices = $this->readFile( $filename, 
$this->configDir );
+                               if( $choices === false ) {
+                                       throw new MWFConfigurationException( 
'Missing or badly formatted file \'' . $variable['file'] .
+                                               '\' defining existing values 
for variable \'' . $key . '\''
+                                       );
+                               }
+                               $this->farmConfig['coreconfig'][] = $filename;
+
+                       } elseif( array_key_exists( 'values', $variable ) && 
is_array( $variable['values'] ) ) {
+
+                               $choices = $variable['values'];
+
+                       } else {
                                $explicitExistence = 
$explicitExistenceUnderScrutiny ? false : $explicitExistence;
                                continue;
                        }
-
-                       # Really check if the variable is in the listing file
-                       $filename = $this->replaceVariables( $variable['file'] 
);
-                       $choices = $this->readFile( $filename, $this->configDir 
);
-                       if( $choices === false ) {
-                               throw new MWFConfigurationException( 'Missing 
or badly formatted file \'' . $variable['file'] .
-                                       '\' defining existing values for 
variable \'' . $key . '\''
-                               );
-                       }
-                       $this->farmConfig['coreconfig'][] = $filename;
 
                        # Check if the array is a simple list of wiki 
identifiers without version information…
                        if( array_keys( $choices ) === range( 0, count( 
$choices ) - 1 ) ) {
diff --git a/tests/phpunit/MonoversionInstallationTest.php 
b/tests/phpunit/MonoversionInstallationTest.php
index baf9435..9244abe 100644
--- a/tests/phpunit/MonoversionInstallationTest.php
+++ b/tests/phpunit/MonoversionInstallationTest.php
@@ -169,6 +169,24 @@
        }
 
        /**
+        * Test a existing host in a farm with a “values” variable without 
version defined inside.
+        */
+       function testVariableValuesWithoutVersion() {
+
+               $farm = self::constructMediaWikiFarm( 
'a.testfarm-monoversion-with-values-variable-without-version.example.org' );
+               $this->assertTrue( $farm->checkExistence() );
+       }
+
+       /**
+        * Test a nonexistant host in a farm with a “values” variable without 
version defined inside.
+        */
+       function testVariableValuesWithoutVersionNonexistant() {
+
+               $farm = self::constructMediaWikiFarm( 
'c.testfarm-monoversion-with-values-variable-without-version.example.org' );
+               $this->assertFalse( $farm->checkExistence() );
+       }
+
+       /**
         * Test a existing host in a farm with a file variable with version 
defined inside.
         */
        function testVariableFileWithVersion() {
diff --git a/tests/phpunit/data/config/farms.php 
b/tests/phpunit/data/config/farms.php
index c90206d..88d4ead 100644
--- a/tests/phpunit/data/config/farms.php
+++ b/tests/phpunit/data/config/farms.php
@@ -134,6 +134,26 @@
                ),
        ),
 
+       'testfarm-monoversion-with-values-variable-without-version' => array(
+
+               'server' => 
'(?P<wiki>[a-z])\.testfarm-monoversion-with-values-variable-without-version\.example\.org',
+               'variables' => array(
+                       array( 'variable' => 'wiki',
+                              'values' => array( 'a', 'b' ), ),
+               ),
+               'suffix' => 'testfarm',
+               'wikiID' => '$wikitestfarm',
+               'HTTP404' => 'phpunitHTTP404.php',
+               'config' => array(
+                       array( 'file' => 'settings.php',
+                              'key' => 'default',
+                       ),
+                       array( 'file' => 'LocalSettings.php',
+                              'executable' => true,
+                       ),
+               ),
+       ),
+
        'testfarm-multiversion-with-file-variable-with-version' => array(
 
                'server' => 
'(?P<wiki>[a-z])\.testfarm-multiversion-with-file-variable-with-version\.example\.org',

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I314e1a953d53b0540a8c78ec8e01aaddebd95c85
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MediaWikiFarm
Gerrit-Branch: master
Gerrit-Owner: Seb35 <se...@seb35.fr>

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

Reply via email to