* Adapt the RunSeleniumTests.php to the Maintenance framework.
authorMark A. Hershberger <mah@users.mediawiki.org>
Thu, 26 Aug 2010 20:52:21 +0000 (20:52 +0000)
committerMark A. Hershberger <mah@users.mediawiki.org>
Thu, 26 Aug 2010 20:52:21 +0000 (20:52 +0000)
* Add Maintenance::deleteOption() for removing default options.
* Add Maintenance::addDescription() for updating the description.

maintenance/Maintenance.php
maintenance/tests/RunSeleniumTests.php

index 4fcbc44..a649e42 100644 (file)
@@ -157,6 +157,22 @@ abstract class Maintenance {
                );
        }
 
+       /**
+        * Remove an option.  Useful for removing options that won't be used in your script.
+        * @param $name String: the option to remove.
+        */
+       protected function deleteOption( $name ) {
+               unset( $this->mParams[$name] );
+       }
+
+       /**
+        * Set the description text.
+        * @param $text String: the text of the description
+        */
+       protected function addDescription( $text ) {
+               $this->mDescription = $text;
+       }
+
        /**
         * Does a given argument exist?
         * @param $argId Integer: the integer value (from zero) for the arg
@@ -770,7 +786,7 @@ abstract class Maintenance {
 
                if ( !is_readable( $settingsFile ) ) {
                        $this->error( "A copy of your installation's LocalSettings.php\n" .
-                                               "must exist and be readable in the source directory.", true );
+                                               "must exist and be readable in the source directory.", true );
                }
                $wgCommandLineMode = true;
                return $settingsFile;
index 080aadb..0ddc585 100644 (file)
@@ -1,3 +1,4 @@
+#!/usr/bin/php
 <?php
 /**
  * @file
 
 define( 'SELENIUMTEST', true );
 
-require( dirname( __FILE__ ) . "/../commandLine.inc" );
-if ( isset( $options['help'] ) ) {
-       echo <<<ENDS
-MediaWiki $wgVersion Selenium Framework tester
-Usage: php RunSeleniumTests.php [options...]
-Options:
---port=<TCP port> Port used by selenium server to accept commands
---help            Show this help message
-ENDS;
-       exit( 1 );
-}
+require_once( dirname( dirname( __FILE__ ) )."/Maintenance.php" );
 
-if ( isset( $options['port'] ) ) {
-       $wgSeleniumServerPort = (int) $options['port'];
-}
+class SeleniumTester extends Maintenance {
+       public function __construct() {
+               parent::__construct();
+
+               $this->addOption( 'port', 'Port used by selenium server' );
+               $this->addOption( 'host', 'Host selenium server' );
+               $this->addOption( 'browser', 'The browser he used during testing' );
+               $this->addOption( 'url', 'The Mediawiki installation to point to.' );
+               $this->addOption( 'list-browsers', 'List the available browsers.' );
+
+               $this->deleteOption( 'dbpass' );
+               $this->deleteOption( 'dbuser' );
+               $this->deleteOption( 'globals' );
+               $this->deleteOption( 'wiki' );
+       }
+
+       public function listBrowsers() {
+               global $wgSeleniumTestsBrowsers;
+
+               $desc = "Available browsers:\n";
+               foreach ($wgSeleniumTestsBrowsers as $k => $v) {
+                       $desc .= "  $k => $v\n";
+               }
 
-SeleniumLoader::load();
+               echo $desc;
+       }
 
-$result = new PHPUnit_Framework_TestResult;
-$wgSeleniumLogger = new SeleniumTestConsoleLogger;
-$result->addListener( new SeleniumTestListener( $wgSeleniumLogger ) );
+       protected function runTests() {
+               global $wgSeleniumLogger, $wgSeleniumTestSuites;
 
-foreach ( $wgSeleniumTestSuites as $testSuiteName ) {
-       $suite = new $testSuiteName;
-       $suite->addTests();
-       $suite->run( $result );
+               SeleniumLoader::load();
+               $result = new PHPUnit_Framework_TestResult;
+               $wgSeleniumLogger = new SeleniumTestConsoleLogger;
+               $result->addListener( new SeleniumTestListener( $wgSeleniumLogger ) );
+
+               foreach ( $wgSeleniumTestSuites as $testSuiteName ) {
+                       $suite = new $testSuiteName;
+                       $suite->addTests();
+                       try {
+                               $suite->run( $result );
+                       } catch ( Testing_Selenium_Exception $e ) {
+                               throw new MWException( $e->getMessage() );
+                       }
+               }
+       }
+
+       public function execute() {
+               global $wgSeleniumServerPort, $wgSeleniumTestsSeleniumHost,
+                       $wgSeleniumTestsWikiUrl, $wgServer, $wgScriptPath;
+
+               if( $this->hasOption( 'list-browsers' ) ) {
+                       $this->listBrowsers();
+                       exit(0);
+               }
+
+               $wgSeleniumServerPort = $this->getOption( 'port', 4444 );
+               $wgSeleniumTestsSeleniumHost = $this->getOption( 'host', 'localhost' );
+               $wgSeleniumTestsWikiUrl = $this->getOption( 'test-url', $wgServer . $wgScriptPath );
+               $wgSeleniumTestsUseBrowser = $this->getOption( 'browser', 'firefox' );
+
+               $this->runTests();
+       }
 }
 
+$maintClass = "SeleniumTester";
+
+require_once( DO_MAINTENANCE );