41b30440413ff713b54f223bbe33b958beb2707f
[lhc/web/wiklou.git] / maintenance / tests / RunSeleniumTests.php
1 <?php
2 /**
3 * @file
4 * @ingroup Maintenance
5 * @copyright Copyright © Wikimedia Deuschland, 2009
6 * @author Hallo Welt! Medienwerkstatt GmbH
7 * @author Markus Glaser
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
23 */
24
25 define( 'MEDIAWIKI', true );
26 define( 'SELENIUMTEST', true );
27
28 // Here, you can override standard setting
29 if ( file_exists( 'selenium/LocalSeleniumSettings.php' ) ) {
30 include_once 'selenium/LocalSeleniumSettings.php';
31 } else {
32 echo "You must provide local settings in LocalSeleniumSettings.php\n";
33 die( -1 );
34 }
35
36 // Command line only
37 if ( $wgSeleniumTestsRunMode == 'cli' && php_sapi_name() != 'cli' ) {
38 echo "Must be run from the command line.\n";
39 die( -1 );
40 }
41
42 // Get command line parameters
43 if ( $wgSeleniumTestsRunMode == 'cli' ) {
44 require_once( dirname( __FILE__ ) . '/../commandLine.inc' );
45 if ( isset( $options['help'] ) ) {
46 echo <<<ENDS
47 MediaWiki $wgVersion Selenium Framework tester
48 Usage: php RunSeleniumTests.php [options...]
49 Options:
50 --port=<TCP port> Port used by selenium server to accept commands
51 --help Show this help message
52 ENDS;
53 exit( 0 );
54 }
55
56 if ( isset( $options['port'] ) ) {
57 $wgSeleniumServerPort = (int) $options['port'];
58 }
59 }
60
61 // requires PHPUnit 3.4
62 require_once 'Testing/Selenium.php';
63 require_once 'PHPUnit/Framework.php';
64 require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
65
66 // include seleniumTestsuite
67 require_once 'selenium/SeleniumTestHTMLLogger.php';
68 require_once 'selenium/SeleniumTestConsoleLogger.php';
69 require_once 'selenium/SeleniumTestListener.php';
70 require_once 'selenium/Selenium.php';
71 require_once 'selenium/SeleniumTestSuite.php';
72 require_once 'selenium/SeleniumTestCase.php';
73
74 $result = new PHPUnit_Framework_TestResult;
75 switch ( $wgSeleniumTestsRunMode ) {
76 case 'html':
77 $logger = new SeleniumTestHTMLLogger;
78 break;
79 case 'cli':
80 $logger = new SeleniumTestConsoleLogger;
81 break;
82 }
83
84 $result->addListener( new SeleniumTestListener( $logger ) );
85
86 $wgSeleniumTestSuites = array();
87
88 // include tests
89 // Todo: include automatically
90 if ( is_array( $wgSeleniumTestIncludes ) ) {
91 foreach ( $wgSeleniumTestIncludes as $include ) {
92 include_once $include;
93 }
94 }
95
96 // run tests
97 foreach ( $wgSeleniumTestSuites as $suite ) {
98 $suite->run( $result );
99 }