From: Mark A. Hershberger Date: Sat, 4 Sep 2010 00:58:57 +0000 (+0000) Subject: * Remove $wg*Selenium* globals as they are only used for testing. X-Git-Tag: 1.31.0-rc.0~35181 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/operations/recherche.php?a=commitdiff_plain;h=495f6344becb97c5b5c754acc347048903ce2b15;p=lhc%2Fweb%2Fwiklou.git * Remove $wg*Selenium* globals as they are only used for testing. * mglaser said the SpecialSelenium page wasn't needed so I'm removing it – I suggest its functionality be put in an extension if needed. * Add verbose option (requires patch to Testing_Selenium) to RunSeleniumTests. * TODO: add .ini file to hold local configuration * TODO: add ability to sniff available browsers from Grid server instead of hard-coding. --- diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index aa38e90cda..b1055302f6 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -3719,50 +3719,6 @@ $wgParserTestFiles = array( */ $wgParserTestRemote = false; -/** - * Enable Selenium test framework. - * This enables maintenance/tests/RunSeleniumTests.php and [[Special:Selenium]]. - */ -$wgEnableSelenium = false; - -/** List of Selenium test suites. These must be registered with the autoloader. */ -$wgSeleniumTestSuites = array( - 'SimpleSeleniumTestSuite' -); - - -/** Hostname of selenium server */ -$wgSeleniumTestsSeleniumHost = 'localhost'; - -/** URL of the wiki to be tested. By default, the local wiki is used. */ -$wgSeleniumTestsWikiUrl = false; - -/** Port used by selenium server. */ -$wgSeleniumServerPort = 4444; - -/** Wiki login username. Used by Selenium to log onto the wiki. */ -$wgSeleniumTestsWikiUser = 'Wikiuser'; - -/** Wiki login password. Used by Selenium to log onto the wiki. */ -$wgSeleniumTestsWikiPassword = ''; - -/** - * Common browsers on Windows platform. Modify for other platforms or - * other Windows browsers. - * Use the *chrome handler in order to be able to test file uploads. - * 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/ - */ -$wgSeleniumTestsBrowsers = array( - 'firefox' => '*firefox /usr/bin/firefox', - 'iexplorer' => '*iexploreproxy', - 'opera' => '*chrome /usr/bin/opera', -); - -/** Actually, use this browser */ -$wgSeleniumTestsUseBrowser = 'firefox'; - - - /** @} */ # end of profiling, testing and debugging } /************************************************************************//** diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index e3174db86e..fbbf7a277f 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -207,7 +207,6 @@ class SpecialPage { static function initList() { global $wgSpecialPages; global $wgDisableCounters, $wgDisableInternalSearch, $wgEmailAuthentication; - global $wgEnableSelenium; if ( self::$mListInitialised ) { return; @@ -230,10 +229,6 @@ class SpecialPage { self::$mList['Invalidateemail'] = 'EmailInvalidation'; } - if ( $wgEnableSelenium ) { - self::$mList['Selenium'] = 'SpecialSelenium'; - } - # Add extension special pages self::$mList = array_merge( self::$mList, $wgSpecialPages ); diff --git a/includes/specials/SpecialSelenium.php b/includes/specials/SpecialSelenium.php deleted file mode 100644 index 4a7a0d1510..0000000000 --- a/includes/specials/SpecialSelenium.php +++ /dev/null @@ -1,72 +0,0 @@ -setHeaders(); - if ( !$this->userCanExecute( $wgUser ) ) { - $this->displayRestrictionError(); - return; - } - - if ( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'token' ) ) ) { - $this->runTests(); - } - $wgOut->addHTML( - Html::openElement( 'form', array( - 'method' => 'POST', - 'action' => $this->getTitle()->getLocalUrl(), - ) ) . - Html::input( 'submit', 'Run tests', 'submit' ) . - Html::hidden( 'token', $wgUser->editToken() ) . - '' - ); - } - - function runTests() { - global $wgSeleniumTestSuites, $wgOut, $wgSeleniumLogger; - SeleniumLoader::load(); - - $result = new PHPUnit_Framework_TestResult; - $wgSeleniumLogger = new SeleniumTestHTMLLogger; - $result->addListener( new SeleniumTestListener( $wgSeleniumLogger ) ); - //$wgSeleniumLogger->setHeaders(); - - // run tests - $wgOut->addHTML( '
' ); - - // for some really strange reason, foreach doesn't work here. It produces an infinite loop, - // executing only the first test suite. - for ( $i = 0; $i < count( $wgSeleniumTestSuites ); $i++ ) { - $suite = new $wgSeleniumTestSuites[$i]; - $suite->addTests(); - $suite->run( $result ); - } - $wgOut->addHTML( '
' ); - } -} - diff --git a/maintenance/tests/RunSeleniumTests.php b/maintenance/tests/RunSeleniumTests.php index 935d9a4ac7..58fbfcd027 100644 --- a/maintenance/tests/RunSeleniumTests.php +++ b/maintenance/tests/RunSeleniumTests.php @@ -26,8 +26,13 @@ define( 'SELENIUMTEST', true ); require_once( dirname( dirname( __FILE__ ) )."/Maintenance.php" ); +require_once( 'PHPUnit/Framework.php' ); +require_once( 'PHPUnit/Extensions/SeleniumTestCase.php' ); + class SeleniumTester extends Maintenance { + protected $selenium; + public function __construct() { parent::__construct(); @@ -45,27 +50,25 @@ class SeleniumTester extends Maintenance { } public function listBrowsers() { - global $wgSeleniumTestsBrowsers; - $desc = "Available browsers:\n"; - foreach ($wgSeleniumTestsBrowsers as $k => $v) { + + $sel = new Selenium; + foreach ($sel->setupBrowsers() as $k => $v) { $desc .= " $k => $v\n"; } echo $desc; } - protected function runTests( $verbose = false ) { - global $wgSeleniumLogger, $wgSeleniumTestSuites; + protected function getTestSuites() { + return array( 'SimpleSeleniumTestSuite' ); + } - require_once( 'Testing/Selenium.php' ); - require_once( 'PHPUnit/Framework.php' ); - require_once( 'PHPUnit/Extensions/SeleniumTestCase.php' ); + protected function runTests( ) { $result = new PHPUnit_Framework_TestResult; - $wgSeleniumLogger = new SeleniumTestConsoleLogger; - $result->addListener( new SeleniumTestListener( $wgSeleniumLogger ) ); + $result->addListener( new SeleniumTestListener( $this->selenium->getLogger() ) ); - foreach ( $wgSeleniumTestSuites as $testSuiteName ) { + foreach ( $this->getTestSuites() as $testSuiteName ) { $suite = new $testSuiteName; $suite->addTests(); try { @@ -77,20 +80,29 @@ class SeleniumTester extends Maintenance { } public function execute() { - global $wgSeleniumServerPort, $wgSeleniumTestsSeleniumHost, - $wgSeleniumTestsWikiUrl, $wgServer, $wgScriptPath; + global $wgServer, $wgScriptPath; + + /** + * @todo Add an alternative where settings are read from an INI file. + */ + $this->selenium = new Selenium( ); + $this->selenium->setUrl( $this->getOption( 'url', $wgServer . $wgScriptPath ) ); + $this->selenium->setBrowser( $this->getOption( 'browser', 'firefox' ) ); + $this->selenium->setPort( $this->getOption( 'port', 4444 ) ); + $this->selenium->setHost( $this->getOption( 'host', 'localhost' ) ); + $this->selenium->setUser( $this->getOption( 'user', 'WikiSysop' ) ); + $this->selenium->setPass( $this->getOption( 'pass', 'Password' ) ); + $this->selenium->setVerbose( $this->hasOption( 'verbose' ) ); if( $this->hasOption( 'list-browsers' ) ) { $this->listBrowsers(); exit(0); } - $wgSeleniumServerPort = $this->getOption( 'port', 4444 ); - $wgSeleniumTestsSeleniumHost = $this->getOption( 'host', 'localhost' ); - $wgSeleniumTestsWikiUrl = $this->getOption( 'url', $wgServer . $wgScriptPath ); - $wgSeleniumTestsUseBrowser = $this->getOption( 'browser', 'firefox' ); + $logger = new SeleniumTestConsoleLogger; + $this->selenium->setLogger( $logger ); - $this->runTests( $this->hasOption( 'verbose' ) ); + $this->runTests( ); } } diff --git a/maintenance/tests/selenium/Selenium.php b/maintenance/tests/selenium/Selenium.php index 4bd54ba974..de7d9e0347 100644 --- a/maintenance/tests/selenium/Selenium.php +++ b/maintenance/tests/selenium/Selenium.php @@ -4,49 +4,76 @@ * This is implemented as a singleton. */ -class Selenium extends Testing_Selenium { +require( 'Testing/Selenium.php' ); +class Selenium { protected static $_instance = null; public $isStarted = false; + public $tester; - public static function getInstance() { - global $wgSeleniumTestsBrowsers, $wgSeleniumTestsSeleniumHost, $wgSeleniumTestsUseBrowser; - global $wgSeleniumServerPort, $wgSeleniumLogger; + protected $port; + protected $host; + protected $browser; + protected $browsers; + protected $logger; + protected $user; + protected $pass; + protected $timeout = 30000; + protected $verbose; + + /** + * @todo this shouldn't have to be static + */ + static protected $url; + /** + * Override parent + */ + public function __construct() { + /** + * @todo this is an ugly hack to make information available to + * other tests. It should be fixed. + */ if ( null === self::$_instance ) { - $wgSeleniumLogger->write( "Browser: " . $wgSeleniumTestsBrowsers[$wgSeleniumTestsUseBrowser] ); - self::$_instance = new self( $wgSeleniumTestsBrowsers[$wgSeleniumTestsUseBrowser], - self::getBaseUrl(), - $wgSeleniumTestsSeleniumHost, - $wgSeleniumServerPort ); + self::$_instance = $this; + } else { + throw new MWException("Already have one Selenium instance."); } - return self::$_instance; } public function start() { - parent::start(); + $this->tester = new Testing_Selenium( $this->browser, self::$url, $this->host, + $this->port, $this->timeout ); + if ( method_exists( $this->tester, "setVerbose" ) ) $this->tester->setVerbose( $this->verbose ); + + $this->tester->start(); $this->isStarted = true; } public function stop() { - parent::stop(); + $this->tester->stop(); + $this->tester = null; $this->isStarted = false; } - static function getBaseUrl() { - global $wgSeleniumTestsWikiUrl, $wgServer, $wgScriptPath; - if ( $wgSeleniumTestsWikiUrl ) { - return $wgSeleniumTestsWikiUrl; - } else { - return $wgServer . $wgScriptPath; + protected function setupBrowsers() { + /** + * @todo This needs to be replaced with something not hard + * coded. This would be entries in a .ini file or + * screen-scraping + * http://grid.tesla.usability.wikimedia.org:4444/console for + * example. + */ + return array( + 'firefox' => 'Firefox 3.5 on Linux', + 'iexplorer' => '*iexploreproxy', + 'chrome' => '*googlechrome', + ); } - } public function login() { - global $wgSeleniumTestsWikiUser, $wgSeleniumTestsWikiPassword; - - $this->open( self::getBaseUrl() . '/index.php?title=Special:Userlogin' ); - $this->type( 'wpName1', $wgSeleniumTestsWikiUser ); - $this->type( 'wpPassword1', $wgSeleniumTestsWikiPassword ); + $this->open( self::$url . '/index.php?title=Special:Userlogin' ); + $this->type( 'wpName1', $this->user ); + $this->type( 'wpPassword1', $this->pass ); $this->click( "//input[@id='wpLoginAttempt']" ); $this->waitForPageToLoad(5000); //after login we redirect to the main page. So check whether the "Prefernces" top menu item exists @@ -57,18 +84,71 @@ class Selenium extends Testing_Selenium { } + public static function getInstance() { + if ( null === self::$_instance ) { + throw new MWException( "No instance set yet" ); + } + + return self::$_instance; + } + public function loadPage( $title, $action ) { - $this->open( self::getBaseUrl() . '/index.php?title=' . $title . '&action=' . $action ); + $this->open( self::$url . '/index.php?title=' . $title . '&action=' . $action ); } - /* - * Log to console or html depending on the value of $wgSeleniumTestsRunMode - */ + public function setLogger( $logger ) { + $this->logger = $logger; + } + + public function getLogger( ) { + return $this->logger; + } + public function log( $message ) { - global $wgSeleniumLogger; - $wgSeleniumLogger->write( $message ); + $this->logger->write( $message ); } + public function setUrl( $url ) { + self::$url = $url; + } + + static public function getUrl() { + return self::$url; + } + + public function setPort( $port ) { + $this->port = $port; + } + + public function setUser( $user ) { + $this->user = $user; + } + + public function setPass( $pass ) { + $this->pass = $pass; + } + + public function setHost( $host ) { + $this->host = $host; + } + + public function setVerbose( $verbose ) { + $this->verbose = $verbose; + } + + public function setBrowser( $b ) { + $browsers = $this->setupBrowsers(); + if ( !isset( $browsers[$b] ) ) { + throw new MWException( "Invalid Browser: $b.\n" ); + } + $this->browser = $browsers[$b]; + } + + public function __call( $name, $args ) { + $t = call_user_func_array( array( $this->tester, $name), $args ); + return $t; + } + // Prevent external cloning protected function __clone() { } // Prevent external construction