0ddc585f53a2cc6487ceae933532b97de2756b98
[lhc/web/wiklou.git] / maintenance / tests / RunSeleniumTests.php
1 #!/usr/bin/php
2 <?php
3 /**
4 * @file
5 * @ingroup Maintenance
6 * @copyright Copyright © Wikimedia Deuschland, 2009
7 * @author Hallo Welt! Medienwerkstatt GmbH
8 * @author Markus Glaser, Dan Nessett
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 * http://www.gnu.org/copyleft/gpl.html
24 */
25
26 define( 'SELENIUMTEST', true );
27
28 require_once( dirname( dirname( __FILE__ ) )."/Maintenance.php" );
29
30 class SeleniumTester extends Maintenance {
31 public function __construct() {
32 parent::__construct();
33
34 $this->addOption( 'port', 'Port used by selenium server' );
35 $this->addOption( 'host', 'Host selenium server' );
36 $this->addOption( 'browser', 'The browser he used during testing' );
37 $this->addOption( 'url', 'The Mediawiki installation to point to.' );
38 $this->addOption( 'list-browsers', 'List the available browsers.' );
39
40 $this->deleteOption( 'dbpass' );
41 $this->deleteOption( 'dbuser' );
42 $this->deleteOption( 'globals' );
43 $this->deleteOption( 'wiki' );
44 }
45
46 public function listBrowsers() {
47 global $wgSeleniumTestsBrowsers;
48
49 $desc = "Available browsers:\n";
50 foreach ($wgSeleniumTestsBrowsers as $k => $v) {
51 $desc .= " $k => $v\n";
52 }
53
54 echo $desc;
55 }
56
57 protected function runTests() {
58 global $wgSeleniumLogger, $wgSeleniumTestSuites;
59
60 SeleniumLoader::load();
61 $result = new PHPUnit_Framework_TestResult;
62 $wgSeleniumLogger = new SeleniumTestConsoleLogger;
63 $result->addListener( new SeleniumTestListener( $wgSeleniumLogger ) );
64
65 foreach ( $wgSeleniumTestSuites as $testSuiteName ) {
66 $suite = new $testSuiteName;
67 $suite->addTests();
68 try {
69 $suite->run( $result );
70 } catch ( Testing_Selenium_Exception $e ) {
71 throw new MWException( $e->getMessage() );
72 }
73 }
74 }
75
76 public function execute() {
77 global $wgSeleniumServerPort, $wgSeleniumTestsSeleniumHost,
78 $wgSeleniumTestsWikiUrl, $wgServer, $wgScriptPath;
79
80 if( $this->hasOption( 'list-browsers' ) ) {
81 $this->listBrowsers();
82 exit(0);
83 }
84
85 $wgSeleniumServerPort = $this->getOption( 'port', 4444 );
86 $wgSeleniumTestsSeleniumHost = $this->getOption( 'host', 'localhost' );
87 $wgSeleniumTestsWikiUrl = $this->getOption( 'test-url', $wgServer . $wgScriptPath );
88 $wgSeleniumTestsUseBrowser = $this->getOption( 'browser', 'firefox' );
89
90 $this->runTests();
91 }
92 }
93
94 $maintClass = "SeleniumTester";
95
96 require_once( DO_MAINTENANCE );