Index: trunk/phase3/maintenance/tests/RunSeleniumTests.php |
— | — | @@ -1,3 +1,4 @@ |
| 2 | +#!/usr/bin/php |
2 | 3 | <?php |
3 | 4 | /** |
4 | 5 | * @file |
— | — | @@ -24,31 +25,72 @@ |
25 | 26 | |
26 | 27 | define( 'SELENIUMTEST', true ); |
27 | 28 | |
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" ); |
37 | 30 | |
38 | | -if ( isset( $options['port'] ) ) { |
39 | | - $wgSeleniumServerPort = (int) $options['port']; |
40 | | -} |
| 31 | +class SeleniumTester extends Maintenance { |
| 32 | + public function __construct() { |
| 33 | + parent::__construct(); |
41 | 34 | |
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.' ); |
43 | 40 | |
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 | + } |
47 | 46 | |
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 | + } |
52 | 93 | } |
53 | 94 | |
| 95 | +$maintClass = "SeleniumTester"; |
| 96 | + |
| 97 | +require_once( DO_MAINTENANCE ); |
Index: trunk/phase3/maintenance/Maintenance.php |
— | — | @@ -158,6 +158,22 @@ |
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
| 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 | + /** |
162 | 178 | * Does a given argument exist? |
163 | 179 | * @param $argId Integer: the integer value (from zero) for the arg |
164 | 180 | * @return Boolean |
— | — | @@ -770,7 +786,7 @@ |
771 | 787 | |
772 | 788 | if ( !is_readable( $settingsFile ) ) { |
773 | 789 | $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 ); |
775 | 791 | } |
776 | 792 | $wgCommandLineMode = true; |
777 | 793 | return $settingsFile; |