r68555 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68554‎ | r68555 | r68556 >
Date:05:55, 25 June 2010
Author:tstarling
Status:deferred
Tags:
Comment:
* Integrated the selenium tests into MediaWiki properly, and removed the insecure LocalSeleniumSettings.php concept.
* Removed the insecure web entry point hiding in the maintenance directory, in RunSeleniumTests.php. Replaced it with a special page interface, with CSRF protection and access control. If you wanted a secure web entry point, then I suppose this is how it would be done, but I think it should be killed ASAP.
* As in r68544, removed as many require() calls as possible, since nobody seems to know how to do them properly. Made the usual changes to make classes autoloader-compatible: class constants instead of define(), no file-scope registration code.
Modified paths:
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/SpecialPage.php (modified) (history)
  • /trunk/phase3/includes/User.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialSelenium.php (added) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/maintenance/tests/RunSeleniumTests.php (modified) (history)
  • /trunk/phase3/maintenance/tests/selenium/LocalSeleniumSettings.php.sample (deleted) (history)
  • /trunk/phase3/maintenance/tests/selenium/Selenium.php (modified) (history)
  • /trunk/phase3/maintenance/tests/selenium/SeleniumLoader.php (added) (history)
  • /trunk/phase3/maintenance/tests/selenium/SeleniumTestCase.php (modified) (history)
  • /trunk/phase3/maintenance/tests/selenium/SeleniumTestConsoleLogger.php (modified) (history)
  • /trunk/phase3/maintenance/tests/selenium/SeleniumTestHTMLLogger.php (modified) (history)
  • /trunk/phase3/maintenance/tests/selenium/SeleniumTestListener.php (modified) (history)
  • /trunk/phase3/maintenance/tests/selenium/SeleniumTestSuite.php (modified) (history)
  • /trunk/phase3/maintenance/tests/selenium/SimpleSeleniumTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/tests/RunSeleniumTests.php
@@ -22,79 +22,33 @@
2323 * http://www.gnu.org/copyleft/gpl.html
2424 */
2525
26 -define( 'MEDIAWIKI', true );
2726 define( 'SELENIUMTEST', true );
2827
29 -// Here, you can override standard setting
30 -if ( file_exists( 'selenium/LocalSeleniumSettings.php' ) ) {
31 - include_once 'selenium/LocalSeleniumSettings.php';
32 -} else {
33 - echo "You must provide local settings in LocalSeleniumSettings.php\n";
34 - die( -1 );
35 -}
36 -
37 -// Command line only
38 -if ( $wgSeleniumTestsRunMode == 'cli' && php_sapi_name() != 'cli' ) {
39 - echo "Must be run from the command line.\n";
40 - die( -1 );
41 -}
42 -
43 -// Get command line parameters
44 -if ( $wgSeleniumTestsRunMode == 'cli' ) {
45 - require_once( dirname( __FILE__ ) . '/../commandLine.inc' );
46 - if ( isset( $options['help'] ) ) {
47 - echo <<<ENDS
 28+require( dirname( __FILE__ ) . "/../commandLine.inc" );
 29+if ( isset( $options['help'] ) ) {
 30+ echo <<<ENDS
4831 MediaWiki $wgVersion Selenium Framework tester
4932 Usage: php RunSeleniumTests.php [options...]
5033 Options:
51 - --port=<TCP port> Port used by selenium server to accept commands
52 - --help Show this help message
 34+--port=<TCP port> Port used by selenium server to accept commands
 35+--help Show this help message
5336 ENDS;
54 - exit( 0 );
55 - }
 37+ exit( 1 );
 38+}
5639
57 - if ( isset( $options['port'] ) ) {
58 - $wgSeleniumServerPort = (int) $options['port'];
59 - }
 40+if ( isset( $options['port'] ) ) {
 41+ $wgSeleniumServerPort = (int) $options['port'];
6042 }
6143
62 -// requires PHPUnit 3.4
63 -require_once 'Testing/Selenium.php';
64 -require_once 'PHPUnit/Framework.php';
65 -require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
 44+SeleniumLoader::load();
6645
67 -// include seleniumTestsuite
68 -require_once 'selenium/SeleniumTestHTMLLogger.php';
69 -require_once 'selenium/SeleniumTestConsoleLogger.php';
70 -require_once 'selenium/SeleniumTestListener.php';
71 -require_once 'selenium/Selenium.php';
72 -require_once 'selenium/SeleniumTestSuite.php';
73 -require_once 'selenium/SeleniumTestCase.php';
74 -
7546 $result = new PHPUnit_Framework_TestResult;
76 -switch ( $wgSeleniumTestsRunMode ) {
77 - case 'html':
78 - $logger = new SeleniumTestHTMLLogger;
79 - break;
80 - case 'cli':
81 - $logger = new SeleniumTestConsoleLogger;
82 - break;
83 -}
84 -
 47+$logger = new SeleniumTestConsoleLogger;
8548 $result->addListener( new SeleniumTestListener( $logger ) );
8649
87 -$wgSeleniumTestSuites = array();
88 -
89 -// include tests
90 -// Todo: include automatically
91 -if ( is_array( $wgSeleniumTestIncludes ) ) {
92 - foreach ( $wgSeleniumTestIncludes as $include ) {
93 - include_once $include;
94 - }
 50+$suite = new SeleniumTestSuite;
 51+foreach ( $wgSeleniumTests as $testClass ) {
 52+ $suite->addTest( new $testClass );
9553 }
 54+$suite->run( $result );
9655
97 -// run tests
98 -foreach ( $wgSeleniumTestSuites as $suite ) {
99 - $suite->run( $result );
100 -}
101 -
Index: trunk/phase3/maintenance/tests/selenium/LocalSeleniumSettings.php.sample
@@ -1,51 +0,0 @@
2 -<?php
3 -// This template file contains variables that should be localized.
4 -// The line (specifying the location of the PHP/PEAR libraries) must be
5 -// first. Moving it to a position later in the file will almost certainly
6 -// cause an error.
7 -
8 -// In order to use this file, first copy it to LocalSeleniumSettings.php.
9 -// Then edit the information to conform to the local environment. You
10 -// will almost certainly have to uncomment the line set_include_path ... and
11 -// change the string 'PEAR' to the path to your PEAR library, e.g.,
12 -// '/usr/share/php/PEAR' for a Debian based Linux system.
13 -// The edited file must appear in the ../tests/selenium directory.
14 -
15 -// include path. Set 'PEAR" to '/path/to/PEAR/library'
16 -
17 -// URL: http://localhost/tests/RunSeleniumTests.php
18 -#set_include_path( get_include_path() . PATH_SEPARATOR . 'PEAR' );
19 -
20 -// Hostname of selenium server
21 -$wgSeleniumTestsSeleniumHost = 'localhost';
22 -
23 -// URL of the wiki to be tested. Consult web server configuration.
24 -$wgSeleniumTestsWikiUrl = 'http://localhost';
25 -
26 -// Port used by selenium server (optional - default is 4444)
27 -$wgSeleniumServerPort = 4444;
28 -
29 -// Wiki login. Used by Selenium to log onto the wiki
30 -$wgSeleniumTestsWikiUser = 'Wikisysop';
31 -$wgSeleniumTestsWikiPassword = 'password';
32 -
33 -// Common browsers on Windows platform. Modify for other platforms or
34 -// other Windows browsers
35 -// Use the *chrome handler in order to be able to test file uploads
36 -// further solution suggestions: http://www.brokenbuild.com/blog/2007/06/07/testing-file-uploads-with-selenium-rc-and-firefoxor-reducing-javascript-security-in-firefox-for-fun-and-profit/
37 -// $wgSeleniumTestsBrowsers['firefox'] = '*firefox c:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe';
38 -$wgSeleniumTestsBrowsers['firefox'] = '*firefox /usr/bin/firefox';
39 -$wgSeleniumTestsBrowsers['iexplorer'] = '*iexploreproxy';
40 -$wgSeleniumTestsBrowsers['opera'] = '*chrome /usr/bin/opera';
41 -
42 -// Actually, use this browser
43 -$wgSeleniumTestsUseBrowser = 'firefox';
44 -
45 -// Set command line mode
46 -$wgSeleniumTestsRunMode = 'cli';
47 -
48 -// List of tests to be included by default
49 -$wgSeleniumTestIncludes = array(
50 - 'selenium/SimpleSeleniumTest.php'
51 -);
52 -?>
\ No newline at end of file
Index: trunk/phase3/maintenance/tests/selenium/SeleniumTestSuite.php
@@ -1,17 +1,13 @@
22 <?php
3 -if ( !defined( 'MEDIAWIKI' ) || !defined( 'SELENIUMTEST' ) ) {
4 - echo "This script cannot be run standalone";
5 - exit( 1 );
6 -}
73
8 -// Do not add line break after test output
9 -define( 'MW_TESTLOGGER_CONTINUE_LINE', 1 );
10 -define( 'MW_TESTLOGGER_RESULT_OK', 2 );
11 -define( 'MW_TESTLOGGER_RESULT_ERROR', 3 );
12 -
134 class SeleniumTestSuite extends PHPUnit_Framework_TestSuite {
145 private $selenium;
156
 7+ // Do not add line break after test output
 8+ const CONTINUE_LINE = 1;
 9+ const RESULT_OK = 2;
 10+ const RESULT_ERROR = 3;
 11+
1612 public function setUp() {
1713 $this->selenium = Selenium::getInstance();
1814 $this->selenium->start();
Index: trunk/phase3/maintenance/tests/selenium/SimpleSeleniumTest.php
@@ -1,31 +1,21 @@
22 <?php
33
4 -if (!defined('MEDIAWIKI') || !defined('SELENIUMTEST')) {
5 - echo "This script cannot be run standalone";
6 - exit(1);
7 -}
8 -
9 -// create test suite
10 -$wgSeleniumTestSuites['SimpleSeleniumTest'] = new SeleniumTestSuite('Simple Selenium Test');
11 -$wgSeleniumTestSuites['SimpleSeleniumTest']->addTest(new SimpleSeleniumTest());
12 -
134 class SimpleSeleniumTest extends SeleniumTestCase
145 {
156 public $name = "Basic selenium test";
167
178 public function runTest()
189 {
19 - global $wgSeleniumTestsWikiUrl;
20 - $this->open($wgSeleniumTestsWikiUrl.'/index.php?title=Selenium&action=edit');
21 - $this->type("wpTextbox1", "This is a basic test");
22 - $this->click("wpPreview");
23 - $this->waitForPageToLoad(10000);
 10+ $this->open( Selenium::getBaseUrl() . '/index.php?title=Selenium&action=edit' );
 11+ $this->type( "wpTextbox1", "This is a basic test" );
 12+ $this->click( "wpPreview" );
 13+ $this->waitForPageToLoad( 10000 );
2414
2515 // check result
26 - $source = $this->getText("//div[@id='wikiPreview']/p");
27 - $correct = strstr($source, "This is a basic test");
28 - $this->assertEquals($correct, true);
 16+ $source = $this->getText( "//div[@id='wikiPreview']/p" );
 17+ $correct = strstr( $source, "This is a basic test" );
 18+ $this->assertEquals( $correct, true );
2919
3020 }
3121
32 -}
\ No newline at end of file
 22+}
Index: trunk/phase3/maintenance/tests/selenium/SeleniumTestCase.php
@@ -1,9 +1,4 @@
22 <?php
3 -if ( !defined( 'MEDIAWIKI' ) || !defined( 'SELENIUMTEST' ) ) {
4 - echo "This script cannot be run standalone";
5 - exit( 1 );
6 -}
7 -
83 class SeleniumTestCase extends PHPUnit_Framework_TestCase { // PHPUnit_Extensions_SeleniumTestCase
94 protected $selenium;
105
@@ -31,4 +26,4 @@
3227 $this->assertRegExp( "/$text/", $innerHTML );
3328 }
3429
35 -}
\ No newline at end of file
 30+}
Index: trunk/phase3/maintenance/tests/selenium/Selenium.php
@@ -4,21 +4,16 @@
55 * This is implemented as a singleton.
66 */
77
8 -if ( !defined( 'MEDIAWIKI' ) || !defined( 'SELENIUMTEST' ) ) {
9 - echo "This script cannot be run standalone";
10 - exit( 1 );
11 -}
12 -
138 class Selenium extends Testing_Selenium {
149 protected static $_instance = null;
1510 public $isStarted = false;
1611
1712 public static function getInstance() {
1813 global $wgSeleniumTestsBrowsers, $wgSeleniumTestsSeleniumHost, $wgSeleniumTestsUseBrowser;
19 - global $wgSeleniumTestsWikiUrl, $wgSeleniumServerPort;
 14+ global $wgSeleniumServerPort;
2015 if ( null === self::$_instance ) {
2116 self::$_instance = new self( $wgSeleniumTestsBrowsers[$wgSeleniumTestsUseBrowser],
22 - $wgSeleniumTestsWikiUrl,
 17+ self::getBaseUrl(),
2318 $wgSeleniumTestsSeleniumHost,
2419 $wgSeleniumServerPort );
2520 }
@@ -36,23 +31,27 @@
3732 $this->isStarted = false;
3833 }
3934
 35+ static function getBaseUrl() {
 36+ global $wgSeleniumTestsWikiUrl, $wgServer, $wgScriptPath;
 37+ if ( $wgSeleniumTestsWikiUrl ) {
 38+ return $wgSeleniumTestsWikiUrl;
 39+ } else {
 40+ return $wgServer . $wgScriptPath;
 41+ }
 42+ }
 43+
4044 public function login() {
41 - global $wgSeleniumTestsWikiUser, $wgSeleniumTestsWikiPassword, $wgSeleniumTestsWikiUrl, $wgVersion;
 45+ global $wgSeleniumTestsWikiUser, $wgSeleniumTestsWikiPassword;
4246
43 - $this->open( $wgSeleniumTestsWikiUrl . '/index.php?title=Special:Userlogin' );
 47+ $this->open( self::getBaseUrl() . '/index.php?title=Special:Userlogin' );
4448 $this->type( 'wpName1', $wgSeleniumTestsWikiUser );
4549 $this->type( 'wpPassword1', $wgSeleniumTestsWikiPassword );
46 - if (version_compare($wgVersion, '1.15.2', '>=')) {
47 - $this->click( "//input[@id='wpLoginAttempt']" );
48 - } else {
49 - $this->click( "//input[@id='wpLoginattempt']" );
50 - }
 50+ $this->click( "//input[@id='wpLoginAttempt']" );
5151 $value = $this->doCommand( 'assertTitle', array( 'Login successful*' ) );
5252 }
5353
5454 public function loadPage( $title, $action ) {
55 - global $wgSeleniumTestsWikiUrl;
56 - $this->open( $wgSeleniumTestsWikiUrl . '/index.php?title=' . $title . '&action=' . $action );
 55+ $this->open( self::getBaseUrl() . '/index.php?title=' . $title . '&action=' . $action );
5756 }
5857
5958 // Prevent external cloning
Index: trunk/phase3/maintenance/tests/selenium/SeleniumTestConsoleLogger.php
@@ -1,8 +1,4 @@
22 <?php
3 -if ( !defined( 'MEDIAWIKI' ) || !defined( 'SELENIUMTEST' ) ) {
4 - echo "This script cannot be run standalone";
5 - exit( 1 );
6 -}
73
84 class SeleniumTestConsoleLogger {
95 public function __construct() {
@@ -17,13 +13,13 @@
1814
1915 public function write( $message, $mode = false ) {
2016 $out = '';
21 - // if ( $mode == MW_TESTLOGGER_RESULT_OK ) $out .= '<font color="green">';
 17+ // if ( $mode == SeleniumTestSuite::RESULT_OK ) $out .= '<font color="green">';
2218 $out .= htmlentities( $message );
23 - // if ( $mode == MW_TESTLOGGER_RESULT_OK ) $out .= '</font>';
24 - if ( $mode != MW_TESTLOGGER_CONTINUE_LINE ) {
 19+ // if ( $mode == SeleniumTestSuite::RESULT_OK ) $out .= '</font>';
 20+ if ( $mode != SeleniumTestSuite::CONTINUE_LINE ) {
2521 $out .= "\n";
2622 }
2723
2824 echo $out;
2925 }
30 -}
\ No newline at end of file
 26+}
Index: trunk/phase3/maintenance/tests/selenium/SeleniumTestHTMLLogger.php
@@ -1,22 +1,10 @@
22 <?php
3 -if ( !defined( 'MEDIAWIKI' ) || !defined( 'SELENIUMTEST' ) ) {
4 - echo "This script cannot be run standalone";
5 - exit( 1 );
6 -}
73
84 class SeleniumTestHTMLLogger {
9 - public function __construct() {
10 - // Prepare testsuite for immediate output
11 - @ini_set( 'zlib.output_compression', 0 );
12 - @ini_set( 'implicit_flush', 1 );
13 - for ( $i = 0; $i < ob_get_level(); $i++ ) {
14 - ob_end_flush();
15 - }
16 - ob_implicit_flush( 1 );
17 -
18 - // Output some style information
19 - echo '<style>
20 - pre {
 5+ public function setHeaders() {
 6+ global $wgOut;
 7+ $wgOut->addHeadItem( 'selenium', '<style>
 8+ .selenium pre {
219 overflow-x: auto; /* Use horizontal scroller if needed; for Firefox 2, not needed in Firefox 3 */
2210 white-space: pre-wrap; /* css-3 */
2311 white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */
@@ -25,22 +13,23 @@
2614 /* width: 99%; */
2715 word-wrap: break-word; /* Internet Explorer 5.5+ */
2816 }
29 - </style>';
 17+ </style>' );
3018 }
3119
3220 public function write( $message, $mode = false ) {
 21+ global $wgOut;
3322 $out = '';
34 - if ( $mode == MW_TESTLOGGER_RESULT_OK ) {
 23+ if ( $mode == SeleniumTestSuite::RESULT_OK ) {
3524 $out .= '<font color="green">';
3625 }
37 - $out .= htmlentities( $message );
38 - if ( $mode == MW_TESTLOGGER_RESULT_OK ) {
 26+ $out .= htmlspecialchars( $message );
 27+ if ( $mode == SeleniumTestSuite::RESULT_OK ) {
3928 $out .= '</font>';
4029 }
41 - if ( $mode != MW_TESTLOGGER_CONTINUE_LINE ) {
 30+ if ( $mode != SeleniumTestSuite::CONTINUE_LINE ) {
4231 $out .= '<br />';
4332 }
4433
45 - echo $out;
 34+ $wgOut->addHTML( $out );
4635 }
47 -}
\ No newline at end of file
 36+}
Index: trunk/phase3/maintenance/tests/selenium/SeleniumTestListener.php
@@ -1,8 +1,4 @@
22 <?php
3 -if ( !defined( 'MEDIAWIKI' ) || !defined( 'SELENIUMTEST' ) ) {
4 - echo "This script cannot be run standalone";
5 - exit( 1 );
6 -}
73
84 class SeleniumTestListener implements PHPUnit_Framework_TestListener {
95 private $logger;
@@ -39,13 +35,13 @@
4036 public function startTest( PHPUnit_Framework_Test $test ) {
4137 $this->logger->write(
4238 'Testing ' . $test->getName() . ' ... ',
43 - MW_TESTLOGGER_CONTINUE_LINE
 39+ SeleniumTestSuite::CONTINUE_LINE
4440 );
4541 }
4642
4743 public function endTest( PHPUnit_Framework_Test $test, $time ) {
4844 if ( !$test->hasFailed() ) {
49 - $this->logger->write( 'OK', MW_TESTLOGGER_RESULT_OK );
 45+ $this->logger->write( 'OK', SeleniumTestSuite::RESULT_OK );
5046 $this->tests_ok++;
5147 }
5248 }
Index: trunk/phase3/maintenance/tests/selenium/SeleniumLoader.php
@@ -0,0 +1,9 @@
 2+<?php
 3+
 4+class SeleniumLoader {
 5+ static function load() {
 6+ require_once( 'Testing/Selenium.php' );
 7+ require_once( 'PHPUnit/Framework.php' );
 8+ require_once( 'PHPUnit/Extensions/SeleniumTestCase.php' );
 9+ }
 10+}
Property changes on: trunk/phase3/maintenance/tests/selenium/SeleniumLoader.php
___________________________________________________________________
Name: svn:eol-style
111 + native
Index: trunk/phase3/includes/User.php
@@ -167,6 +167,7 @@
168168 'reupload',
169169 'reupload-shared',
170170 'rollback',
 171+ 'selenium',
171172 'sendemail',
172173 'siteadmin',
173174 'suppressionlog',
Index: trunk/phase3/includes/AutoLoader.php
@@ -593,6 +593,7 @@
594594 'SpecialRecentChanges' => 'includes/specials/SpecialRecentchanges.php',
595595 'SpecialRecentchangeslinked' => 'includes/specials/SpecialRecentchangeslinked.php',
596596 'SpecialSearch' => 'includes/specials/SpecialSearch.php',
 597+ 'SpecialSelenium' => 'includes/specials/SpecialSelenium.php',
597598 'SpecialStatistics' => 'includes/specials/SpecialStatistics.php',
598599 'SpecialTags' => 'includes/specials/SpecialTags.php',
599600 'SpecialUnlockdb' => 'includes/specials/SpecialUnlockdb.php',
@@ -638,25 +639,40 @@
639640
640641 # maintenance
641642 'AnsiTermColorer' => 'maintenance/parserTests.inc',
642 - 'ApiTestSetup' => 'maintenance/tests/ApiSetup.php',
643643 'DbTestPreviewer' => 'maintenance/parserTests.inc',
644644 'DbTestRecorder' => 'maintenance/parserTests.inc',
645645 'DeleteArchivedFilesImplementation' => 'maintenance/deleteArchivedFiles.inc',
646646 'DeleteArchivedRevisionsImplementation' => 'maintenance/deleteArchivedRevisions.inc',
647647 'DummyTermColorer' => 'maintenance/parserTests.inc',
648 - 'MediaWikiTestSetup' => 'maintenance/tests/MediaWiki_Setup.php',
649 - 'PHPUnitTestRecorder' => 'maintenance/tests/ParserHelpers.php',
650648 'ParserTest' => 'maintenance/parserTests.inc',
651649 'ParserTestParserHook' => 'maintenance/parserTestsParserHook.php',
652650 'ParserTestStaticParserHook' => 'maintenance/parserTestsStaticParserHook.php',
653 - 'ParserTestSuiteBackend' => 'maintenance/tests/ParserHelpers.php',
654 - 'ParserUnitTest' => 'maintenance/tests/ParserHelpers.php',
655651 'RemoteTestRecorder' => 'maintenance/parserTests.inc',
656 - 'SearchEngineTest' => 'maintenance/tests/SearchEngineTest.php',
657652 'SevenZipStream' => 'maintenance/7zip.inc',
658653 'TestFileIterator' => 'maintenance/parserTests.inc',
659654 'TestRecorder' => 'maintenance/parserTests.inc',
 655+
 656+ # maintenance/tests
 657+ 'ApiTestSetup' => 'maintenance/tests/ApiSetup.php',
 658+ 'MediaWikiTestSetup' => 'maintenance/tests/MediaWiki_Setup.php',
 659+ 'PHPUnitTestRecorder' => 'maintenance/tests/ParserHelpers.php',
 660+ 'ParserTestSuiteBackend' => 'maintenance/tests/ParserHelpers.php',
 661+ 'ParserUnitTest' => 'maintenance/tests/ParserHelpers.php',
 662+ 'SearchEngineTest' => 'maintenance/tests/SearchEngineTest.php',
660663 'UploadFromUrlTest' => 'maintenance/tests/UploadFromUrlTest.php',
 664+
 665+ # maintenance/tests/selenium
 666+ 'SimpleSeleniumTest' => 'maintenance/tests/selenium/SimpleSeleniumTest.php',
 667+ 'Selenium' => 'maintenance/tests/selenium/Selenium.php',
 668+ 'SeleniumLoader' => 'maintenance/tests/selenium/SeleniumLoader.php',
 669+ 'SeleniumTestCase' => 'maintenance/tests/selenium/SeleniumTestCase.php',
 670+ 'SeleniumTestConsoleLogger' => 'maintenance/tests/selenium/SeleniumTestConsoleLogger.php',
 671+ 'SeleniumTestHTMLLogger' => 'maintenance/tests/selenium/SeleniumTestHTMLLogger.php',
 672+ 'SeleniumTestListener' => 'maintenance/tests/selenium/SeleniumTestListener.php',
 673+ 'SeleniumTestSuite' => 'maintenance/tests/selenium/SeleniumTestSuite.php',
 674+ 'SimpleSeleniumTest' => 'maintenance/tests/selenium/SimpleSeleniumTest.php',
 675+
 676+ # maintenance/language
661677 'csvStatsOutput' => 'maintenance/language/StatOutputs.php',
662678 'statsOutput' => 'maintenance/language/StatOutputs.php',
663679 'textStatsOutput' => 'maintenance/language/StatOutputs.php',
Index: trunk/phase3/includes/DefaultSettings.php
@@ -3701,6 +3701,50 @@
37023702 */
37033703 $wgParserTestRemote = false;
37043704
 3705+/**
 3706+ * Enable Selenium test framework.
 3707+ * This enables maintenance/tests/RunSeleniumTests.php and [[Special:Selenium]].
 3708+ */
 3709+$wgEnableSelenium = false;
 3710+
 3711+/** List of Selenium test classes. These must be registered with the autoloader. */
 3712+$wgSeleniumTests = array(
 3713+ 'SimpleSeleniumTest'
 3714+);
 3715+
 3716+
 3717+/** Hostname of selenium server */
 3718+$wgSeleniumTestsSeleniumHost = 'localhost';
 3719+
 3720+/** URL of the wiki to be tested. By default, the local wiki is used. */
 3721+$wgSeleniumTestsWikiUrl = false;
 3722+
 3723+/** Port used by selenium server. */
 3724+$wgSeleniumServerPort = 4444;
 3725+
 3726+/** Wiki login username. Used by Selenium to log onto the wiki. */
 3727+$wgSeleniumTestsWikiUser = 'Wikiuser';
 3728+
 3729+/** Wiki login password. Used by Selenium to log onto the wiki. */
 3730+$wgSeleniumTestsWikiPassword = '';
 3731+
 3732+/**
 3733+ * Common browsers on Windows platform. Modify for other platforms or
 3734+ * other Windows browsers.
 3735+ * Use the *chrome handler in order to be able to test file uploads.
 3736+ * Further solution suggestions: http://www.brokenbuild.com/blog/2007/06/07/testing-file-uploads-with-selenium-rc-and-firefoxor-reducing-javascript-security-in-firefox-for-fun-and-profit/
 3737+ */
 3738+$wgSeleniumTestsBrowsers = array(
 3739+ 'firefox' => '*firefox /usr/bin/firefox',
 3740+ 'iexplorer' => '*iexploreproxy',
 3741+ 'opera' => '*chrome /usr/bin/opera',
 3742+);
 3743+
 3744+/** Actually, use this browser */
 3745+$wgSeleniumTestsUseBrowser = 'firefox';
 3746+
 3747+
 3748+
37053749 /** @} */ # end of profiling, testing and debugging }
37063750
37073751 /************************************************************************//**
Index: trunk/phase3/includes/specials/SpecialSelenium.php
@@ -0,0 +1,62 @@
 2+<?php
 3+
 4+/**
 5+ * TODO: remove this feature
 6+ */
 7+
 8+class SpecialSelenium extends SpecialPage {
 9+ function __construct() {
 10+ parent::__construct( 'Selenium', 'selenium', false );
 11+ }
 12+
 13+ function getDescription() {
 14+ return 'Selenium';
 15+ }
 16+
 17+ function execute() {
 18+ global $wgUser, $wgOut, $wgEnableSelenium, $wgRequest;
 19+
 20+ if ( !$wgEnableSelenium ) {
 21+ throw new MWException(
 22+ 'Selenium special page invoked when it should not be registered!' );
 23+ }
 24+
 25+ $this->setHeaders();
 26+ if ( !$this->userCanExecute( $wgUser ) ) {
 27+ $this->displayRestrictionError();
 28+ return;
 29+ }
 30+
 31+ if ( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'token' ) ) ) {
 32+ $this->runTests();
 33+ }
 34+ $wgOut->addHTML(
 35+ Html::openElement( 'form', array(
 36+ 'method' => 'POST',
 37+ 'action' => $this->getTitle()->getLocalUrl(),
 38+ ) ) .
 39+ Html::input( 'submit', 'Run tests', 'submit' ) .
 40+ Html::hidden( 'token', $wgUser->editToken() ) .
 41+ '</form>'
 42+ );
 43+ }
 44+
 45+ function runTests() {
 46+ global $wgSeleniumTests, $wgOut;
 47+ SeleniumLoader::load();
 48+
 49+ $result = new PHPUnit_Framework_TestResult;
 50+ $logger = new SeleniumTestHTMLLogger;
 51+ $result->addListener( new SeleniumTestListener( $logger ) );
 52+
 53+ // run tests
 54+ $suite = new SeleniumTestSuite;
 55+ foreach ( $wgSeleniumTests as $testClass ) {
 56+ $suite->addTest( new $testClass );
 57+ }
 58+ $wgOut->addHTML( '<div class="selenium">' );
 59+ $suite->run( $result );
 60+ $wgOut->addHTML( '</div>' );
 61+ }
 62+}
 63+
Property changes on: trunk/phase3/includes/specials/SpecialSelenium.php
___________________________________________________________________
Name: svn:eol-style
164 + native
Index: trunk/phase3/includes/SpecialPage.php
@@ -207,6 +207,7 @@
208208 static function initList() {
209209 global $wgSpecialPages;
210210 global $wgDisableCounters, $wgDisableInternalSearch, $wgEmailAuthentication;
 211+ global $wgEnableSelenium;
211212
212213 if ( self::$mListInitialised ) {
213214 return;
@@ -229,6 +230,10 @@
230231 self::$mList['Invalidateemail'] = 'EmailInvalidation';
231232 }
232233
 234+ if ( $wgEnableSelenium ) {
 235+ self::$mList['Selenium'] = 'SpecialSelenium';
 236+ }
 237+
233238 # Add extension special pages
234239 self::$mList = array_merge( self::$mList, $wgSpecialPages );
235240
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -1936,6 +1936,7 @@
19371937 'right-override-export-depth' => 'Export pages including linked pages up to a depth of 5',
19381938 'right-sendemail' => 'Send e-mail to other users',
19391939 'right-revisionmove' => 'Move revisions',
 1940+'right-selenium' => 'Run Selenium tests',
19401941
19411942 # User rights log
19421943 'rightslog' => 'User rights log',

Follow-up revisions

RevisionCommit summaryAuthorDate
r68556Follow-up r68555: Add new message key to maintenance script...raymond06:34, 25 June 2010
r68557* Fixed the makefile to only run enabled tests, instead of every file in the ...tstarling09:01, 25 June 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r68544* Removed require/require_once from maintenance scripts where possible, repla...tstarling02:55, 25 June 2010

Status & tagging log