r71749 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71748‎ | r71749 | r71750 >
Date:20:52, 26 August 2010
Author:mah
Status:ok (Comments)
Tags:
Comment:
* Adapt the RunSeleniumTests.php to the Maintenance framework.
* Add Maintenance::deleteOption() for removing default options.
* Add Maintenance::addDescription() for updating the description.
Modified paths:
  • /trunk/phase3/maintenance/Maintenance.php (modified) (history)
  • /trunk/phase3/maintenance/tests/RunSeleniumTests.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/tests/RunSeleniumTests.php
@@ -1,3 +1,4 @@
 2+#!/usr/bin/php
23 <?php
34 /**
45 * @file
@@ -24,31 +25,72 @@
2526
2627 define( 'SELENIUMTEST', true );
2728
28 -require( dirname( __FILE__ ) . "/../commandLine.inc" );
29 -if ( isset( $options['help'] ) ) {
30 - echo <<<ENDS
31 -MediaWiki $wgVersion Selenium Framework tester
32 -Usage: php RunSeleniumTests.php [options...]
33 -Options:
34 -ENDS;
35 - exit( 1 );
36 -}
 29+require_once( dirname( dirname( __FILE__ ) )."/Maintenance.php" );
3730
38 -if ( isset( $options['port'] ) ) {
39 - $wgSeleniumServerPort = (int) $options['port'];
40 -}
 31+class SeleniumTester extends Maintenance {
 32+ public function __construct() {
 33+ parent::__construct();
4134
42 -SeleniumLoader::load();
 35+ $this->addOption( 'port', 'Port used by selenium server' );
 36+ $this->addOption( 'host', 'Host selenium server' );
 37+ $this->addOption( 'browser', 'The browser he used during testing' );
 38+ $this->addOption( 'url', 'The Mediawiki installation to point to.' );
 39+ $this->addOption( 'list-browsers', 'List the available browsers.' );
4340
44 -$result = new PHPUnit_Framework_TestResult;
45 -$wgSeleniumLogger = new SeleniumTestConsoleLogger;
46 -$result->addListener( new SeleniumTestListener( $wgSeleniumLogger ) );
 41+ $this->deleteOption( 'dbpass' );
 42+ $this->deleteOption( 'dbuser' );
 43+ $this->deleteOption( 'globals' );
 44+ $this->deleteOption( 'wiki' );
 45+ }
4746
48 -foreach ( $wgSeleniumTestSuites as $testSuiteName ) {
49 - $suite = new $testSuiteName;
50 - $suite->addTests();
51 - $suite->run( $result );
 47+ public function listBrowsers() {
 48+ global $wgSeleniumTestsBrowsers;
 49+
 50+ $desc = "Available browsers:\n";
 51+ foreach ($wgSeleniumTestsBrowsers as $k => $v) {
 52+ $desc .= " $k => $v\n";
 53+ }
 54+
 55+ echo $desc;
 56+ }
 57+
 58+ protected function runTests() {
 59+ global $wgSeleniumLogger, $wgSeleniumTestSuites;
 60+
 61+ SeleniumLoader::load();
 62+ $result = new PHPUnit_Framework_TestResult;
 63+ $wgSeleniumLogger = new SeleniumTestConsoleLogger;
 64+ $result->addListener( new SeleniumTestListener( $wgSeleniumLogger ) );
 65+
 66+ foreach ( $wgSeleniumTestSuites as $testSuiteName ) {
 67+ $suite = new $testSuiteName;
 68+ $suite->addTests();
 69+ try {
 70+ $suite->run( $result );
 71+ } catch ( Testing_Selenium_Exception $e ) {
 72+ throw new MWException( $e->getMessage() );
 73+ }
 74+ }
 75+ }
 76+
 77+ public function execute() {
 78+ global $wgSeleniumServerPort, $wgSeleniumTestsSeleniumHost,
 79+ $wgSeleniumTestsWikiUrl, $wgServer, $wgScriptPath;
 80+
 81+ if( $this->hasOption( 'list-browsers' ) ) {
 82+ $this->listBrowsers();
 83+ exit(0);
 84+ }
 85+
 86+ $wgSeleniumServerPort = $this->getOption( 'port', 4444 );
 87+ $wgSeleniumTestsSeleniumHost = $this->getOption( 'host', 'localhost' );
 88+ $wgSeleniumTestsWikiUrl = $this->getOption( 'test-url', $wgServer . $wgScriptPath );
 89+ $wgSeleniumTestsUseBrowser = $this->getOption( 'browser', 'firefox' );
 90+
 91+ $this->runTests();
 92+ }
5293 }
5394
 95+$maintClass = "SeleniumTester";
 96+
 97+require_once( DO_MAINTENANCE );
Index: trunk/phase3/maintenance/Maintenance.php
@@ -158,6 +158,22 @@
159159 }
160160
161161 /**
 162+ * Remove an option. Useful for removing options that won't be used in your script.
 163+ * @param $name String: the option to remove.
 164+ */
 165+ protected function deleteOption( $name ) {
 166+ unset( $this->mParams[$name] );
 167+ }
 168+
 169+ /**
 170+ * Set the description text.
 171+ * @param $text String: the text of the description
 172+ */
 173+ protected function addDescription( $text ) {
 174+ $this->mDescription = $text;
 175+ }
 176+
 177+ /**
162178 * Does a given argument exist?
163179 * @param $argId Integer: the integer value (from zero) for the arg
164180 * @return Boolean
@@ -770,7 +786,7 @@
771787
772788 if ( !is_readable( $settingsFile ) ) {
773789 $this->error( "A copy of your installation's LocalSettings.php\n" .
774 - "must exist and be readable in the source directory.", true );
 790+ "must exist and be readable in the source directory.", true );
775791 }
776792 $wgCommandLineMode = true;
777793 return $settingsFile;

Comments

#Comment by Platonides (talk | contribs)   23:04, 30 August 2010

$wgSeleniumTestsUseBrowser should have been in the list of globals

#Comment by MarkAHershberger (talk | contribs)   01:04, 4 September 2010

see r72340

#Comment by Platonides (talk | contribs)   14:53, 4 September 2010
)

Status & tagging log