From 60c32c1f075f14b00bb02f38d07de89f8de1fcc5 Mon Sep 17 00:00:00 2001 From: "Mark A. Hershberger" Date: Thu, 26 Aug 2010 20:52:21 +0000 Subject: [PATCH] * Adapt the RunSeleniumTests.php to the Maintenance framework. * Add Maintenance::deleteOption() for removing default options. * Add Maintenance::addDescription() for updating the description. --- maintenance/Maintenance.php | 18 +++++- maintenance/tests/RunSeleniumTests.php | 86 +++++++++++++++++++------- 2 files changed, 81 insertions(+), 23 deletions(-) diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index 4fcbc44631..a649e42e33 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -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; diff --git a/maintenance/tests/RunSeleniumTests.php b/maintenance/tests/RunSeleniumTests.php index 080aadb825..0ddc585f53 100644 --- a/maintenance/tests/RunSeleniumTests.php +++ b/maintenance/tests/RunSeleniumTests.php @@ -1,3 +1,4 @@ +#!/usr/bin/php 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 ); -- 2.20.1