Index: trunk/phase3/maintenance/tests/RunSeleniumTests.php |
— | — | @@ -35,11 +35,14 @@ |
36 | 36 | |
37 | 37 | public function __construct() { |
38 | 38 | parent::__construct(); |
39 | | - |
40 | | - $this->addOption( 'port', 'Port used by selenium server' ); |
41 | | - $this->addOption( 'host', 'Host selenium server' ); |
42 | | - $this->addOption( 'browser', 'The browser he used during testing' ); |
43 | | - $this->addOption( 'url', 'The Mediawiki installation to point to.' ); |
| 39 | + $this->mDescription = "Selenium Test Runner. For documentation, visit http://www.mediawiki.org/wiki/SeleniumFramework"; |
| 40 | + $this->addOption( 'port', 'Port used by selenium server. Default: 4444' ); |
| 41 | + $this->addOption( 'host', 'Host selenium server. Default: $wgServer . $wgScriptPath' ); |
| 42 | + $this->addOption( 'testBrowser', 'The browser he used during testing. Default: firefox' ); |
| 43 | + $this->addOption( 'wikiUrl', 'The Mediawiki installation to point to. Default: http://localhost' ); |
| 44 | + $this->addOption( 'username', 'The login username for sunning tests. Default: empty' ); |
| 45 | + $this->addOption( 'userPassword', 'The login password for running tests. Default: empty' ); |
| 46 | + $this->addOption( 'seleniumConfig', 'Location of the selenium config file. Default: empty' ); |
44 | 47 | $this->addOption( 'list-browsers', 'List the available browsers.' ); |
45 | 48 | $this->addOption( 'verbose', 'Be noisier.' ); |
46 | 49 | |
— | — | @@ -52,46 +55,76 @@ |
53 | 56 | public function listBrowsers() { |
54 | 57 | $desc = "Available browsers:\n"; |
55 | 58 | |
56 | | - $sel = new Selenium; |
57 | | - foreach ($sel->setupBrowsers() as $k => $v) { |
| 59 | + foreach ($this->selenium->getAvailableBrowsers() as $k => $v) { |
58 | 60 | $desc .= " $k => $v\n"; |
59 | 61 | } |
60 | 62 | |
61 | 63 | echo $desc; |
62 | 64 | } |
63 | 65 | |
64 | | - protected function getTestSuites() { |
65 | | - return array( 'SimpleSeleniumTestSuite' ); |
66 | | - } |
67 | | - |
68 | | - protected function runTests( ) { |
| 66 | + protected function runTests( $seleniumTestSuites = array() ) { |
69 | 67 | $result = new PHPUnit_Framework_TestResult; |
70 | 68 | $result->addListener( new SeleniumTestListener( $this->selenium->getLogger() ) ); |
71 | | - |
72 | | - foreach ( $this->getTestSuites() as $testSuiteName ) { |
73 | | - $suite = new $testSuiteName; |
| 69 | + |
| 70 | + foreach ( $seleniumTestSuites as $testSuiteName => $testSuiteFile ) { |
| 71 | + require( $testSuiteFile ); |
| 72 | + $suite = new $testSuiteName(); |
74 | 73 | $suite->addTests(); |
| 74 | + |
75 | 75 | try { |
76 | 76 | $suite->run( $result ); |
77 | 77 | } catch ( Testing_Selenium_Exception $e ) { |
| 78 | + $suite->tearDown(); |
78 | 79 | throw new MWException( $e->getMessage() ); |
79 | 80 | } |
80 | 81 | } |
81 | 82 | } |
82 | 83 | |
83 | 84 | public function execute() { |
84 | | - global $wgServer, $wgScriptPath; |
| 85 | + global $wgServer, $wgScriptPath, $wgHooks; |
| 86 | + |
| 87 | + $seleniumSettings; |
| 88 | + $seleniumBrowsers; |
| 89 | + $seleniumTestSuites; |
85 | 90 | |
86 | | - /** |
87 | | - * @todo Add an alternative where settings are read from an INI file. |
88 | | - */ |
| 91 | + $configFile = $this->getOption( 'seleniumConfig', '' ); |
| 92 | + if ( strlen( $configFile ) > 0 ) { |
| 93 | + $this->output("Using Selenium Configuration file: " . $configFile . "\n"); |
| 94 | + SeleniumTestConfig::getSeleniumSettings( &$seleniumSettings, |
| 95 | + &$seleniumBrowsers, |
| 96 | + &$seleniumTestSuites, |
| 97 | + $configFile ); |
| 98 | + } else if ( !isset( $wgHooks['SeleniumSettings'] ) ) { |
| 99 | + $this->output("Using default Selenium Configuration file: selenium_settings.ini in the root directory.\n"); |
| 100 | + SeleniumTestConfig::getSeleniumSettings( &$seleniumSettings, |
| 101 | + &$seleniumBrowsers, |
| 102 | + &$seleniumTestSuites |
| 103 | + ); |
| 104 | + } else { |
| 105 | + $this->output("Using 'SeleniumSettings' hook for configuration.\n"); |
| 106 | + wfRunHooks('SeleniumSettings', array( &$seleniumSettings, |
| 107 | + &$seleniumBrowsers, |
| 108 | + &$seleniumTestSuites ) ); |
| 109 | + } |
| 110 | + |
| 111 | + |
| 112 | + //set reasonable defaults if we did not find the settings |
| 113 | + if ( !isset( $seleniumBrowsers ) ) $seleniumBrowsers = array ('firefox' => '*firefox'); |
| 114 | + if ( !isset( $seleniumSettings['host'] ) ) $seleniumSettings['host'] = $wgServer . $wgScriptPath; |
| 115 | + if ( !isset( $seleniumSettings['port'] ) ) $seleniumSettings['port'] = '4444'; |
| 116 | + if ( !isset( $seleniumSettings['wikiUrl'] ) ) $seleniumSettings['wikiUrl'] = 'http://localhost'; |
| 117 | + if ( !isset( $seleniumSettings['username'] ) ) $seleniumSettings['username'] = ''; |
| 118 | + if ( !isset( $seleniumSettings['userPassword'] ) ) $seleniumSettings['userPassword'] = ''; |
| 119 | + if ( !isset( $seleniumSettings['testBrowser'] ) ) $seleniumSettings['testBrowser'] = 'firefox'; |
| 120 | + |
89 | 121 | $this->selenium = new Selenium( ); |
90 | | - $this->selenium->setUrl( $this->getOption( 'url', $wgServer . $wgScriptPath ) ); |
91 | | - $this->selenium->setBrowser( $this->getOption( 'browser', 'firefox' ) ); |
92 | | - $this->selenium->setPort( $this->getOption( 'port', 4444 ) ); |
93 | | - $this->selenium->setHost( $this->getOption( 'host', 'localhost' ) ); |
94 | | - $this->selenium->setUser( $this->getOption( 'user', 'WikiSysop' ) ); |
95 | | - $this->selenium->setPass( $this->getOption( 'pass', 'Password' ) ); |
| 122 | + $this->selenium->setAvailableBrowsers( $seleniumBrowsers ); |
| 123 | + $this->selenium->setUrl( $this->getOption( 'wikiUrl', $seleniumSettings['wikiUrl'] ) ); |
| 124 | + $this->selenium->setBrowser( $this->getOption( 'testBrowser', $seleniumSettings['testBrowser'] ) ); |
| 125 | + $this->selenium->setPort( $this->getOption( 'port', $seleniumSettings['port'] ) ); |
| 126 | + $this->selenium->setHost( $this->getOption( 'host', $seleniumSettings['host'] ) ); |
| 127 | + $this->selenium->setUser( $this->getOption( 'username', $seleniumSettings['username'] ) ); |
| 128 | + $this->selenium->setPass( $this->getOption( 'userPassword', $seleniumSettings['userPassword'] ) ); |
96 | 129 | $this->selenium->setVerbose( $this->hasOption( 'verbose' ) ); |
97 | 130 | |
98 | 131 | if( $this->hasOption( 'list-browsers' ) ) { |
— | — | @@ -102,7 +135,7 @@ |
103 | 136 | $logger = new SeleniumTestConsoleLogger; |
104 | 137 | $this->selenium->setLogger( $logger ); |
105 | 138 | |
106 | | - $this->runTests( ); |
| 139 | + $this->runTests( $seleniumTestSuites ); |
107 | 140 | } |
108 | 141 | } |
109 | 142 | |
Index: trunk/phase3/maintenance/tests/selenium/selenium_settings.ini.sample |
— | — | @@ -0,0 +1,17 @@ |
| 2 | +[SeleniumSettings] |
| 3 | + |
| 4 | +browsers[firefox] = "*firefox" |
| 5 | +browsers[iexplorer] = "*iexploreproxy" |
| 6 | +browsers[chrome] = "*chrome" |
| 7 | +host = "localhost" |
| 8 | +port = "4444" |
| 9 | +wikiUrl = "http://localhost/deployment" |
| 10 | +username = "wikiuser" |
| 11 | +userPassword = "wikipass" |
| 12 | +testBrowser = "firefox" |
| 13 | + |
| 14 | +[SeleniumTests] |
| 15 | + |
| 16 | +testSuite[SimpleSeleniumTestSuite] = "maintenance/tests/selenium/SimpleSeleniumTestSuite.php" |
| 17 | +testSuite[PagedTiffHandlerSeleniumTestSuite] = "extensions/PagedTiffHandler/selenium/PagedTiffHandlerTestSuite.php" |
| 18 | + |
Index: trunk/phase3/maintenance/tests/selenium/SeleniumTestSuite.php |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -class SeleniumTestSuite extends PHPUnit_Framework_TestSuite { |
| 4 | +abstract class SeleniumTestSuite extends PHPUnit_Framework_TestSuite { |
5 | 5 | private $selenium; |
6 | 6 | private $isSetUp = false; |
7 | 7 | |
— | — | @@ -9,6 +9,8 @@ |
10 | 10 | const RESULT_OK = 2; |
11 | 11 | const RESULT_ERROR = 3; |
12 | 12 | |
| 13 | + public abstract function addTests(); |
| 14 | + |
13 | 15 | public function setUp() { |
14 | 16 | // Hack because because PHPUnit version 3.0.6 which is on prototype does not |
15 | 17 | // run setUp as part of TestSuite::run |
— | — | @@ -18,11 +20,12 @@ |
19 | 21 | $this->isSetUp = true; |
20 | 22 | $this->selenium = Selenium::getInstance(); |
21 | 23 | $this->selenium->start(); |
| 24 | + //$this->selenium->open( $this->selenium->getUrl() . '/index.php?setupTestSuite=' . $this->getName() ); |
22 | 25 | $this->login(); |
23 | | - // $this->loadPage( 'Testpage', 'edit' ); |
24 | 26 | } |
25 | 27 | |
26 | 28 | public function tearDown() { |
| 29 | + //$this->selenium->open( $this->selenium->getUrl() . '/index.php?clearTestSuite=' . $this->getName() ); |
27 | 30 | $this->selenium->stop(); |
28 | 31 | } |
29 | 32 | |
Index: trunk/phase3/maintenance/tests/selenium/Selenium.php |
— | — | @@ -8,6 +8,7 @@ |
9 | 9 | |
10 | 10 | class Selenium { |
11 | 11 | protected static $_instance = null; |
| 12 | + |
12 | 13 | public $isStarted = false; |
13 | 14 | public $tester; |
14 | 15 | |
— | — | @@ -56,27 +57,15 @@ |
57 | 58 | $this->isStarted = false; |
58 | 59 | } |
59 | 60 | |
60 | | - protected function setupBrowsers() { |
61 | | - /** |
62 | | - * @todo This needs to be replaced with something not hard |
63 | | - * coded. This would be entries in a .ini file or |
64 | | - * screen-scraping |
65 | | - * http://grid.tesla.usability.wikimedia.org:4444/console for |
66 | | - * example. |
67 | | - */ |
68 | | - return array( |
69 | | - 'firefox' => 'Firefox 3.5 on Linux', |
70 | | - 'iexplorer' => '*iexploreproxy', |
71 | | - 'chrome' => '*googlechrome', |
72 | | - ); |
73 | | - } |
74 | | - |
75 | 61 | public function login() { |
| 62 | + if ( strlen( $this->user ) == 0 ) { |
| 63 | + return; |
| 64 | + } |
76 | 65 | $this->open( self::$url . '/index.php?title=Special:Userlogin' ); |
77 | 66 | $this->type( 'wpName1', $this->user ); |
78 | 67 | $this->type( 'wpPassword1', $this->pass ); |
79 | 68 | $this->click( "//input[@id='wpLoginAttempt']" ); |
80 | | - $this->waitForPageToLoad( 5000 ); |
| 69 | + $this->waitForPageToLoad( 10000 ); |
81 | 70 | |
82 | 71 | // after login we redirect to the main page. So check whether the "Prefernces" top menu item exists |
83 | 72 | $value = $this->isElementPresent( "//li[@id='pt-preferences']" ); |
— | — | @@ -138,17 +127,22 @@ |
139 | 128 | public function setVerbose( $verbose ) { |
140 | 129 | $this->verbose = $verbose; |
141 | 130 | } |
| 131 | + |
| 132 | + public function setAvailableBrowsers( $availableBrowsers ) { |
| 133 | + $this->browsers = $availableBrowsers; |
| 134 | + } |
142 | 135 | |
143 | 136 | public function setBrowser( $b ) { |
144 | | - $browsers = $this->setupBrowsers(); |
145 | | - |
146 | | - |
147 | | - if ( !isset( $browsers[$b] ) ) { |
| 137 | + if ( !isset( $this->browsers[$b] ) ) { |
148 | 138 | throw new MWException( "Invalid Browser: $b.\n" ); |
149 | 139 | } |
150 | 140 | |
151 | | - $this->browser = $browsers[$b]; |
| 141 | + $this->browser = $this->browsers[$b]; |
152 | 142 | } |
| 143 | + |
| 144 | + public function getAvailableBrowsers() { |
| 145 | + return $this->browsers; |
| 146 | + } |
153 | 147 | |
154 | 148 | public function __call( $name, $args ) { |
155 | 149 | $t = call_user_func_array( array( $this->tester, $name ), $args ); |
Index: trunk/phase3/maintenance/tests/selenium/SimpleSeleniumTestSuite.php |
— | — | @@ -1,15 +1,13 @@ |
2 | 2 | <?php |
3 | | - |
4 | | -require_once(dirname( __FILE__ ) . '/SimpleSeleniumTestCase.php'); |
5 | 3 | |
6 | 4 | class SimpleSeleniumTestSuite extends SeleniumTestSuite |
7 | 5 | { |
8 | | - public function __construct( $name = 'Basic selenium test suite') { |
9 | | - parent::__construct( $name ); |
10 | | - } |
11 | | - |
12 | 6 | public function addTests() { |
13 | | - $test = new SimpleSeleniumTestCase(); |
14 | | - parent::addTest( $test ); |
| 7 | + $testFiles = array( |
| 8 | + 'maintenance/tests/selenium/SimpleSeleniumTestCase.php' |
| 9 | + ); |
| 10 | + parent::addTestFiles( $testFiles ); |
15 | 11 | } |
| 12 | + |
| 13 | + |
16 | 14 | } |
Index: trunk/phase3/maintenance/tests/selenium/SeleniumTestConfig.php |
— | — | @@ -0,0 +1,46 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class SeleniumTestConfig { |
| 5 | + |
| 6 | + /* |
| 7 | + * Retreives the Selenium configuration values from an ini file. |
| 8 | + * See sample config file in selenium_settings.ini.sample |
| 9 | + * |
| 10 | + */ |
| 11 | + public static function getSeleniumSettings ( &$seleniumSettings, |
| 12 | + &$seleniumBrowsers, |
| 13 | + &$seleniumTestSuites, |
| 14 | + $seleniumConfigFile = null ) { |
| 15 | + if ( $seleniumConfigFile == null ) { |
| 16 | + global $wgSeleniumConfigFile; |
| 17 | + $seleniumConfigFile = ( isset( $wgSeleniumConfigFile ) ) ? |
| 18 | + $wgSeleniumConfigFile : dirname( __FILE__ ) . "/../../../selenium_settings.ini"; |
| 19 | + } |
| 20 | + |
| 21 | + if ( !file_exists( $seleniumConfigFile ) ) { |
| 22 | + throw new MWException( "Unable to read local Selenium Settings from " . $seleniumConfigFile . "\n" ); |
| 23 | + } |
| 24 | + |
| 25 | + $configArray = parse_ini_file($seleniumConfigFile, true); |
| 26 | + if ( array_key_exists( 'SeleniumSettings', $configArray) ) { |
| 27 | + wfSuppressWarnings(); |
| 28 | + //we may need to change how this is set. But for now leave it in the ini file |
| 29 | + $seleniumBrowsers = $configArray['SeleniumSettings']['browsers']; |
| 30 | + |
| 31 | + $seleniumSettings['host'] = $configArray['SeleniumSettings']['host']; |
| 32 | + $seleniumSettings['port'] = $configArray['SeleniumSettings']['port']; |
| 33 | + $seleniumSettings['wikiUrl'] = $configArray['SeleniumSettings']['wikiUrl']; |
| 34 | + $seleniumSettings['username'] = $configArray['SeleniumSettings']['username']; |
| 35 | + $seleniumSettings['userPassword'] = $configArray['SeleniumSettings']['userPassword']; |
| 36 | + $seleniumSettings['testBrowser'] = $configArray['SeleniumSettings']['testBrowser']; |
| 37 | + wfRestoreWarnings(); |
| 38 | + } |
| 39 | + if ( array_key_exists( 'SeleniumTests', $configArray) ) { |
| 40 | + wfSuppressWarnings(); |
| 41 | + $seleniumTestSuites = $configArray['SeleniumTests']['testSuite']; |
| 42 | + wfRestoreWarnings(); |
| 43 | + } |
| 44 | + return true; |
| 45 | + } |
| 46 | + |
| 47 | +} |
Index: trunk/phase3/maintenance/tests/selenium/SeleniumTestListener.php |
— | — | @@ -49,13 +49,16 @@ |
50 | 50 | public function startTestSuite( PHPUnit_Framework_TestSuite $suite ) { |
51 | 51 | $this->logger->write( 'Testsuite ' . $suite->getName() . ' started.' ); |
52 | 52 | $this->tests_ok = 0; |
| 53 | + $this->tests_failed = 0; |
53 | 54 | } |
54 | 55 | |
55 | 56 | public function endTestSuite( PHPUnit_Framework_TestSuite $suite ) { |
56 | | - $this->logger->write( |
57 | | - 'Testsuite ' . $suite->getName() . ' ended. OK: ' . |
58 | | - $this->tests_ok . ' Failed: ' . $this->tests_failed |
59 | | - ); |
| 57 | + $this->logger->write('Testsuite ' . $suite->getName() . ' ended.' ); |
| 58 | + if ( $this->tests_ok > 0 || $this->tests_failed > 0 ) { |
| 59 | + $this->logger->write( ' OK: ' . $this->tests_ok . ' Failed: ' . $this->tests_failed ); |
| 60 | + } |
| 61 | + $this->tests_ok = 0; |
| 62 | + $this->tests_failed = 0; |
60 | 63 | } |
61 | 64 | |
62 | 65 | public function statusMessage( $message ) { |
Index: trunk/phase3/maintenance/tests/selenium/SimpleSeleniumTestCase.php |
— | — | @@ -2,13 +2,9 @@ |
3 | 3 | |
4 | 4 | class SimpleSeleniumTestCase extends SeleniumTestCase |
5 | 5 | { |
6 | | - public function __construct( $name = 'Basic selenium test') { |
7 | | - parent::__construct( $name ); |
8 | | - } |
9 | | - |
10 | | - public function runTest() |
| 6 | + public function testBasic() |
11 | 7 | { |
12 | | - $this->open( Selenium::getBaseUrl() . |
| 8 | + $this->open( $this->getUrl() . |
13 | 9 | '/index.php?title=Selenium&action=edit' ); |
14 | 10 | $this->type( "wpTextbox1", "This is a basic test" ); |
15 | 11 | $this->click( "wpPreview" ); |
— | — | @@ -20,5 +16,17 @@ |
21 | 17 | $this->assertEquals( $correct, true ); |
22 | 18 | |
23 | 19 | } |
| 20 | + |
| 21 | + /* |
| 22 | + * Needs the following in your LocalConfig or an alternative method of configuration (coming soon) |
| 23 | + * require_once( "$IP/extensions/UsabilityInitiative/Vector/Vector.php" ); |
| 24 | + * $wgDefaultSkin='vector'; |
| 25 | + */ |
| 26 | + public function testGlobalVariable1() |
| 27 | + { |
| 28 | + $this->open( $this->getUrl() . '/index.php?&action=purge' ); |
| 29 | + $bodyClass = $this->getAttribute( "//body/@class" ); |
| 30 | + $this-> assertContains('skin-vector', $bodyClass, 'Vector skin not set'); |
| 31 | + } |
24 | 32 | |
25 | 33 | } |
Index: trunk/phase3/maintenance/tests/phpunit/includes/SeleniumConfigurationTest.php |
— | — | @@ -0,0 +1,174 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class SeleniumConfigurationTest extends PHPUnit_Framework_TestCase { |
| 5 | + |
| 6 | + /* |
| 7 | + * The file where the test temporarity stores the selenium config. |
| 8 | + * This should be cleaned up as part of teardown. |
| 9 | + */ |
| 10 | + private $tempFileName; |
| 11 | + |
| 12 | + /* |
| 13 | + * String containing the a sample selenium settings |
| 14 | + */ |
| 15 | + private $testConfig0 = |
| 16 | +' |
| 17 | +[SeleniumSettings] |
| 18 | +browsers[firefox] = "*firefox" |
| 19 | +browsers[iexplorer] = "*iexploreproxy" |
| 20 | +browsers[chrome] = "*chrome" |
| 21 | +host = "localhost" |
| 22 | +port = "foobarr" |
| 23 | +wikiUrl = "http://localhost/deployment" |
| 24 | +username = "xxxxxxx" |
| 25 | +userPassword = "" |
| 26 | +testBrowser = "chrome" |
| 27 | + |
| 28 | +[SeleniumTests] |
| 29 | +testSuite[SimpleSeleniumTestSuite] = "maintenance/tests/selenium/SimpleSeleniumTestSuite.php" |
| 30 | +testSuite[TestSuiteName] = "testSuitePath" |
| 31 | +'; |
| 32 | + /* |
| 33 | + * Array of expected browsers from $testConfig0 |
| 34 | + */ |
| 35 | + private $testBrowsers0 = array( 'firefox' => '*firefox', |
| 36 | + 'iexplorer' => '*iexploreproxy', |
| 37 | + 'chrome' => '*chrome' |
| 38 | + ); |
| 39 | + /* |
| 40 | + * Array of expected selenium settings from $testConfig0 |
| 41 | + */ |
| 42 | + private $testSettings0 = array( |
| 43 | + 'host' => 'localhost', |
| 44 | + 'port' => 'foobarr', |
| 45 | + 'wikiUrl' => 'http://localhost/deployment', |
| 46 | + 'username' => 'xxxxxxx', |
| 47 | + 'userPassword' => '', |
| 48 | + 'testBrowser' => 'chrome' |
| 49 | + ); |
| 50 | + /* |
| 51 | + * Array of expected testSuites from $testConfig0 |
| 52 | + */ |
| 53 | + private $testSuites0 = array( |
| 54 | + 'SimpleSeleniumTestSuite' => 'maintenance/tests/selenium/SimpleSeleniumTestSuite.php', |
| 55 | + 'TestSuiteName' => 'testSuitePath' |
| 56 | + ); |
| 57 | + |
| 58 | + |
| 59 | + /* |
| 60 | + * Another sample selenium settings file contents |
| 61 | + */ |
| 62 | + private $testConfig1 = |
| 63 | +' |
| 64 | +[SeleniumSettings] |
| 65 | +host = "localhost" |
| 66 | +testBrowser = "firefox" |
| 67 | +'; |
| 68 | + /* |
| 69 | + * Expected browsers from $testConfig1 |
| 70 | + */ |
| 71 | + private $testBrowsers1 = null; |
| 72 | + /* |
| 73 | + * Expected selenium settings from $testConfig1 |
| 74 | + */ |
| 75 | + private $testSettings1 = array( |
| 76 | + 'host' => 'localhost', |
| 77 | + 'port' => null, |
| 78 | + 'wikiUrl' => null, |
| 79 | + 'username' => null, |
| 80 | + 'userPassword' => null, |
| 81 | + 'testBrowser' => 'firefox' |
| 82 | + ); |
| 83 | + /* |
| 84 | + * Expected test suites from $testConfig1 |
| 85 | + */ |
| 86 | + private $testSuites1 = null; |
| 87 | + |
| 88 | + |
| 89 | + /* |
| 90 | + * Clean up the temporary file used to sore the selenium settings. |
| 91 | + */ |
| 92 | + public function tearDown() { |
| 93 | + if ( strlen( $this->tempFileName ) > 0 ) { |
| 94 | + unlink( $this->tempFileName ); |
| 95 | + unset( $this->tempFileName ); |
| 96 | + } |
| 97 | + parent::tearDown(); |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * @expectedException MWException |
| 102 | + * @group SeleniumFramework |
| 103 | + * This test will throw warnings unless you have the following setting in your php.ini |
| 104 | + * allow_call_time_pass_reference = On |
| 105 | + */ |
| 106 | + public function testErrorOnMissingConfigFile() { |
| 107 | + $seleniumSettings; |
| 108 | + $seleniumBrowsers; |
| 109 | + $seleniumTestSuites; |
| 110 | + |
| 111 | + SeleniumTestConfig::getSeleniumSettings(&$seleniumSettings, |
| 112 | + &$seleniumBrowsers, |
| 113 | + &$seleniumTestSuites, |
| 114 | + "Some_fake_settings_file.ini" ); |
| 115 | + } |
| 116 | + |
| 117 | + /** |
| 118 | + * @group SeleniumFramework |
| 119 | + * @dataProvider sampleConfigs |
| 120 | + * This test will throw warnings unless you have the following setting in your php.ini |
| 121 | + * allow_call_time_pass_reference = On |
| 122 | + */ |
| 123 | + public function testgetSeleniumSettings($sampleConfig, $expectedSettings, $expectedBrowsers, $expectedSuites ) { |
| 124 | + //print "SAMPLE_CONFIG " . $sampleConfig . "\n\n"; |
| 125 | + $this->writeToTempFile( $sampleConfig ); |
| 126 | + $seleniumSettings; |
| 127 | + $seleniumBrowsers; |
| 128 | + $seleniumTestSuites; |
| 129 | + |
| 130 | + SeleniumTestConfig::getSeleniumSettings(&$seleniumSettings, |
| 131 | + &$seleniumBrowsers, |
| 132 | + &$seleniumTestSuites, |
| 133 | + $this->tempFileName ); |
| 134 | + |
| 135 | + |
| 136 | + $this->assertEquals($seleniumSettings, $expectedSettings, |
| 137 | + "The selenium settings for the following test configuration was not retrieved correctly" . $sampleConfig |
| 138 | + ); |
| 139 | + $this->assertEquals($seleniumBrowsers, $expectedBrowsers, |
| 140 | + "The available browsers for the following test configuration was not retrieved correctly" . $sampleConfig |
| 141 | + ); |
| 142 | + $this->assertEquals($seleniumTestSuites, $expectedSuites, |
| 143 | + "The test suites for the following test configuration was not retrieved correctly" . $sampleConfig |
| 144 | + ); |
| 145 | + |
| 146 | + |
| 147 | + } |
| 148 | + |
| 149 | + /* |
| 150 | + * create a temp file and write text to it. |
| 151 | + * @param $testToWrite the text to write to the temp file |
| 152 | + */ |
| 153 | + private function writeToTempFile($textToWrite) { |
| 154 | + $this->tempFileName = tempnam(sys_get_temp_dir(), 'test_settings.'); |
| 155 | + $tempFile = fopen( $this->tempFileName, "w" ); |
| 156 | + fwrite($tempFile , $textToWrite); |
| 157 | + fclose($tempFile); |
| 158 | + } |
| 159 | + |
| 160 | + /* |
| 161 | + * Returns an array containing: |
| 162 | + * The contents of the selenium cingiguration ini file |
| 163 | + * The expected selenium configuration array that getSeleniumSettings should return |
| 164 | + * The expected available browsers array that getSeleniumSettings should return |
| 165 | + * The expected test suites arrya that getSeleniumSettings should return |
| 166 | + */ |
| 167 | + public function sampleConfigs() { |
| 168 | + return array( |
| 169 | + array($this->testConfig0, $this->testSettings0, $this->testBrowsers0, $this->testSuites0 ), |
| 170 | + array($this->testConfig1, $this->testSettings1, $this->testBrowsers1, $this->testSuites1 ) |
| 171 | + ); |
| 172 | + } |
| 173 | + |
| 174 | + |
| 175 | +} |
\ No newline at end of file |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -633,7 +633,6 @@ |
634 | 634 | 'SpecialRecentChanges' => 'includes/specials/SpecialRecentchanges.php', |
635 | 635 | 'SpecialRecentchangeslinked' => 'includes/specials/SpecialRecentchangeslinked.php', |
636 | 636 | 'SpecialSearch' => 'includes/specials/SpecialSearch.php', |
637 | | - 'SpecialSelenium' => 'includes/specials/SpecialSelenium.php', |
638 | 637 | 'SpecialSpecialpages' => 'includes/specials/SpecialSpecialpages.php', |
639 | 638 | 'SpecialStatistics' => 'includes/specials/SpecialStatistics.php', |
640 | 639 | 'SpecialTags' => 'includes/specials/SpecialTags.php', |
— | — | @@ -705,7 +704,6 @@ |
706 | 705 | 'UserDupes' => 'maintenance/userDupes.inc', |
707 | 706 | |
708 | 707 | # maintenance/tests/selenium |
709 | | - 'SimpleSeleniumTestSuite' => 'maintenance/tests/selenium/SimpleSeleniumTestSuite.php', |
710 | 708 | 'Selenium' => 'maintenance/tests/selenium/Selenium.php', |
711 | 709 | 'SeleniumLoader' => 'maintenance/tests/selenium/SeleniumLoader.php', |
712 | 710 | 'SeleniumTestCase' => 'maintenance/tests/selenium/SeleniumTestCase.php', |
— | — | @@ -713,6 +711,7 @@ |
714 | 712 | 'SeleniumTestHTMLLogger' => 'maintenance/tests/selenium/SeleniumTestHTMLLogger.php', |
715 | 713 | 'SeleniumTestListener' => 'maintenance/tests/selenium/SeleniumTestListener.php', |
716 | 714 | 'SeleniumTestSuite' => 'maintenance/tests/selenium/SeleniumTestSuite.php', |
| 715 | + 'SeleniumTestConfig' => 'maintenance/tests/selenium/SeleniumTestConfig.php', |
717 | 716 | |
718 | 717 | # maintenance/language |
719 | 718 | 'csvStatsOutput' => 'maintenance/language/StatOutputs.php', |
Index: trunk/phase3/includes/DefaultSettings.php |
— | — | @@ -5117,6 +5117,13 @@ |
5118 | 5118 | ); |
5119 | 5119 | |
5120 | 5120 | /** |
| 5121 | + * Allows running of selenium tests via maintenance/tests/RunSeleniumTests.php |
| 5122 | + */ |
| 5123 | +$wgEnableSelenium = false; |
| 5124 | + |
| 5125 | + |
| 5126 | + |
| 5127 | +/** |
5121 | 5128 | * For really cool vim folding this needs to be at the end: |
5122 | 5129 | * vim: foldmarker=@{,@} foldmethod=marker |
5123 | 5130 | * @} |