Index: trunk/phase3/maintenance/tests/RunSeleniumTests.php |
— | — | @@ -120,6 +120,7 @@ |
121 | 121 | foreach ( $seleniumTestSuites as $testSuiteName => $testSuiteFile ) { |
122 | 122 | require( $testSuiteFile ); |
123 | 123 | $suite = new $testSuiteName(); |
| 124 | + $suite->setName( $testSuiteName ); |
124 | 125 | $suite->addTests(); |
125 | 126 | |
126 | 127 | try { |
Index: trunk/phase3/maintenance/tests/selenium/SeleniumTestSuite.php |
— | — | @@ -3,6 +3,7 @@ |
4 | 4 | abstract class SeleniumTestSuite extends PHPUnit_Framework_TestSuite { |
5 | 5 | private $selenium; |
6 | 6 | private $isSetUp = false; |
| 7 | + private $loginBeforeTests = true; |
7 | 8 | |
8 | 9 | // Do not add line break after test output |
9 | 10 | const CONTINUE_LINE = 1; |
— | — | @@ -20,12 +21,14 @@ |
21 | 22 | $this->isSetUp = true; |
22 | 23 | $this->selenium = Selenium::getInstance(); |
23 | 24 | $this->selenium->start(); |
24 | | - //$this->selenium->open( $this->selenium->getUrl() . '/index.php?setupTestSuite=' . $this->getName() ); |
25 | | - $this->login(); |
| 25 | + $this->selenium->open( $this->selenium->getUrl() . '/index.php?setupTestSuite=' . $this->getName() ); |
| 26 | + if ( $this->loginBeforeTests ) { |
| 27 | + $this->login(); |
| 28 | + } |
26 | 29 | } |
27 | 30 | |
28 | 31 | public function tearDown() { |
29 | | - //$this->selenium->open( $this->selenium->getUrl() . '/index.php?clearTestSuite=' . $this->getName() ); |
| 32 | + $this->selenium->open( $this->selenium->getUrl() . '/index.php?clearTestSuite=' . $this->getName() ); |
30 | 33 | $this->selenium->stop(); |
31 | 34 | } |
32 | 35 | |
— | — | @@ -36,4 +39,8 @@ |
37 | 40 | public function loadPage( $title, $action ) { |
38 | 41 | $this->selenium->loadPage( $title, $action ); |
39 | 42 | } |
| 43 | + |
| 44 | + protected function setLoginBeforeTests( $loginBeforeTests = true ) { |
| 45 | + $this->loginBeforeTests = $loginBeforeTests; |
| 46 | + } |
40 | 47 | } |
Index: trunk/phase3/maintenance/tests/selenium/SimpleSeleniumTestSuite.php |
— | — | @@ -1,7 +1,21 @@ |
2 | 2 | <?php |
3 | | - |
| 3 | +/* |
| 4 | + * Sample test suite. |
| 5 | + * Two ways to configure MW for these tests |
| 6 | + * 1) If you are running multiple test suites, add the following in LocalSettings.php |
| 7 | + * require_once("maintenance/tests/selenium/SimpleSeleniumConfig.php"); |
| 8 | + * $wgSeleniumTestConfigs['SimpleSeleniumTestSuite'] = 'SimpleSeleniumConfig::getSettings'; |
| 9 | + * OR |
| 10 | + * 2) Add the following to your Localsettings.php |
| 11 | + * require_once( "$IP/skins/Chick.php" ); |
| 12 | + * $wgDefaultSkin = 'chick'; |
| 13 | + */ |
4 | 14 | class SimpleSeleniumTestSuite extends SeleniumTestSuite |
5 | 15 | { |
| 16 | + public function setUp() { |
| 17 | + $this->setLoginBeforeTests( false ); |
| 18 | + parent::setUp(); |
| 19 | + } |
6 | 20 | public function addTests() { |
7 | 21 | $testFiles = array( |
8 | 22 | 'maintenance/tests/selenium/SimpleSeleniumTestCase.php' |
Index: trunk/phase3/maintenance/tests/selenium/SimpleSeleniumTestCase.php |
— | — | @@ -1,9 +1,10 @@ |
2 | 2 | <?php |
3 | | - |
4 | | -class SimpleSeleniumTestCase extends SeleniumTestCase |
5 | | -{ |
6 | | - public function testBasic() |
7 | | - { |
| 3 | +/* |
| 4 | + * This test case is part of the SimpleSeleniumTestSuite. |
| 5 | + * Configuration for these tests are dosumented as part of SimpleSeleniumTestSuite.php |
| 6 | + */ |
| 7 | +class SimpleSeleniumTestCase extends SeleniumTestCase { |
| 8 | + public function testBasic() { |
8 | 9 | $this->open( $this->getUrl() . |
9 | 10 | '/index.php?title=Selenium&action=edit' ); |
10 | 11 | $this->type( "wpTextbox1", "This is a basic test" ); |
— | — | @@ -14,19 +15,12 @@ |
15 | 16 | $source = $this->getText( "//div[@id='wikiPreview']/p" ); |
16 | 17 | $correct = strstr( $source, "This is a basic test" ); |
17 | 18 | $this->assertEquals( $correct, true ); |
18 | | - |
19 | 19 | } |
20 | 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 | | - { |
| 21 | + public function testGlobalVariableForDefaultSkin() { |
28 | 22 | $this->open( $this->getUrl() . '/index.php?&action=purge' ); |
29 | 23 | $bodyClass = $this->getAttribute( "//body/@class" ); |
30 | | - $this-> assertContains('skin-vector', $bodyClass, 'Vector skin not set'); |
| 24 | + $this-> assertContains('skin-chick', $bodyClass, 'Chick skin not set'); |
31 | 25 | } |
32 | 26 | |
33 | 27 | } |
Index: trunk/phase3/includes/SeleniumWebSettings.php |
— | — | @@ -0,0 +1,69 @@ |
| 2 | +<?php |
| 3 | +/* |
| 4 | + * Dynamically change configuration variables based on the test suite name and a cookie value. |
| 5 | + * For details on how to configure a wiki for a Selenium test, see: |
| 6 | + * http://www.mediawiki.org/wiki/SeleniumFramework#Test_Wiki_configuration |
| 7 | + */ |
| 8 | +if ( !$wgEnableSelenium ) { |
| 9 | + return; |
| 10 | +} |
| 11 | +$cookiePrefix = $wgSitename . "-"; |
| 12 | +$name = $cookiePrefix . "Selenium"; |
| 13 | + |
| 14 | +//if we find a request parameter containing the test name, set a cookie with the test name |
| 15 | +if ( array_key_exists( 'setupTestSuite', $_GET) ) { |
| 16 | + //TODO: do a check for valid testsuite names |
| 17 | + $setupTestSuiteName = $_GET['setupTestSuite']; |
| 18 | + if ( strlen( $setupTestSuiteName) > 0 ) { |
| 19 | + $expire = time() + 600; |
| 20 | + setcookie( $name, |
| 21 | + $setupTestSuiteName, |
| 22 | + $expire, |
| 23 | + $wgCookiePath, |
| 24 | + $wgCookieDomain, |
| 25 | + $wgCookieSecure, |
| 26 | + true ); |
| 27 | + } |
| 28 | +} |
| 29 | +//clear the cookie based on a request param |
| 30 | +if ( array_key_exists( 'clearTestSuite', $_GET) ) { |
| 31 | + $expire = time() - 600; |
| 32 | + setcookie( $name, |
| 33 | + '', |
| 34 | + $expire, |
| 35 | + $wgCookiePath, |
| 36 | + $wgCookieDomain, |
| 37 | + $wgCookieSecure, |
| 38 | + true ); |
| 39 | +} |
| 40 | + |
| 41 | +//if a cookie is found, run the appropriate callback to get the config params. |
| 42 | +if ( array_key_exists( $name, $_COOKIE) ) { |
| 43 | + $testSuiteName = $_COOKIE[$name]; |
| 44 | + $testIncludes = array(); //array containing all the includes needed for this test |
| 45 | + $testGlobalConfigs = array(); //an array containg all the global configs needed for this test |
| 46 | + if ( isset( $wgSeleniumTestConfigs ) && array_key_exists($testSuiteName, $wgSeleniumTestConfigs) ) { |
| 47 | + $callback = $wgSeleniumTestConfigs[$testSuiteName]; |
| 48 | + call_user_func_array( $callback, array( &$testIncludes, &$testGlobalConfigs)); |
| 49 | + } |
| 50 | + |
| 51 | + foreach ( $testIncludes as $includeFile ) { |
| 52 | + $file = $IP . '/' . $includeFile; |
| 53 | + require_once( $file ); |
| 54 | + } |
| 55 | + foreach ( $testGlobalConfigs as $key => $value ) { |
| 56 | + if ( is_array( $value ) ) { |
| 57 | + |
| 58 | + $configArray = array(); |
| 59 | + if ( isset( $GLOBALS[$key] ) ) { |
| 60 | + $configArray = $GLOBALS[$key]; |
| 61 | + } |
| 62 | + foreach ( $value as $configKey => $configValue ) { |
| 63 | + $configArray[$configKey] = $configValue; |
| 64 | + } |
| 65 | + $GLOBALS[$key] = $configArray; |
| 66 | + } else { |
| 67 | + $GLOBALS[$key] = $value; |
| 68 | + } |
| 69 | + } |
| 70 | +} |
\ No newline at end of file |
Index: trunk/phase3/includes/WebStart.php |
— | — | @@ -114,6 +114,11 @@ |
115 | 115 | # Include site settings. $IP may be changed (hopefully before the AutoLoader is invoked) |
116 | 116 | require_once( "$IP/LocalSettings.php" ); |
117 | 117 | } |
| 118 | + |
| 119 | +if ( $wgEnableSelenium ) { |
| 120 | + require_once( "$IP/includes/SeleniumWebSettings.php" ); |
| 121 | +} |
| 122 | + |
118 | 123 | wfProfileOut( 'WebStart.php-conf' ); |
119 | 124 | |
120 | 125 | wfProfileIn( 'WebStart.php-ob_start' ); |
— | — | @@ -135,3 +140,4 @@ |
136 | 141 | if ( !defined( 'MW_NO_SETUP' ) ) { |
137 | 142 | require_once( "$IP/includes/Setup.php" ); |
138 | 143 | } |
| 144 | + |