From cb57d56d8bbbc1f48d2038d54aa826c4bc3797d5 Mon Sep 17 00:00:00 2001 From: Priyanka Dhanda Date: Thu, 14 Oct 2010 16:38:40 +0000 Subject: [PATCH] * WebStart.php and SeleniumWebSettings.php allow include files and global config variables to be set based on the testsuite being run. See discussion in http://www.mediawiki.org/wiki/SeleniumFramework#Test_Wiki_configuration * Let test suites run without logging in. --- includes/SeleniumWebSettings.php | 69 +++++++++++++++++++ includes/WebStart.php | 6 ++ maintenance/tests/RunSeleniumTests.php | 1 + .../tests/selenium/SeleniumTestSuite.php | 13 +++- .../tests/selenium/SimpleSeleniumTestCase.php | 22 +++--- .../selenium/SimpleSeleniumTestSuite.php | 16 ++++- 6 files changed, 109 insertions(+), 18 deletions(-) create mode 100644 includes/SeleniumWebSettings.php diff --git a/includes/SeleniumWebSettings.php b/includes/SeleniumWebSettings.php new file mode 100644 index 0000000000..e9be250eeb --- /dev/null +++ b/includes/SeleniumWebSettings.php @@ -0,0 +1,69 @@ + 0 ) { + $expire = time() + 600; + setcookie( $name, + $setupTestSuiteName, + $expire, + $wgCookiePath, + $wgCookieDomain, + $wgCookieSecure, + true ); + } +} +//clear the cookie based on a request param +if ( array_key_exists( 'clearTestSuite', $_GET) ) { + $expire = time() - 600; + setcookie( $name, + '', + $expire, + $wgCookiePath, + $wgCookieDomain, + $wgCookieSecure, + true ); +} + +//if a cookie is found, run the appropriate callback to get the config params. +if ( array_key_exists( $name, $_COOKIE) ) { + $testSuiteName = $_COOKIE[$name]; + $testIncludes = array(); //array containing all the includes needed for this test + $testGlobalConfigs = array(); //an array containg all the global configs needed for this test + if ( isset( $wgSeleniumTestConfigs ) && array_key_exists($testSuiteName, $wgSeleniumTestConfigs) ) { + $callback = $wgSeleniumTestConfigs[$testSuiteName]; + call_user_func_array( $callback, array( &$testIncludes, &$testGlobalConfigs)); + } + + foreach ( $testIncludes as $includeFile ) { + $file = $IP . '/' . $includeFile; + require_once( $file ); + } + foreach ( $testGlobalConfigs as $key => $value ) { + if ( is_array( $value ) ) { + + $configArray = array(); + if ( isset( $GLOBALS[$key] ) ) { + $configArray = $GLOBALS[$key]; + } + foreach ( $value as $configKey => $configValue ) { + $configArray[$configKey] = $configValue; + } + $GLOBALS[$key] = $configArray; + } else { + $GLOBALS[$key] = $value; + } + } +} \ No newline at end of file diff --git a/includes/WebStart.php b/includes/WebStart.php index 557fa741f5..dee5d4b90c 100644 --- a/includes/WebStart.php +++ b/includes/WebStart.php @@ -114,6 +114,11 @@ if ( defined( 'MW_CONFIG_CALLBACK' ) ) { # Include site settings. $IP may be changed (hopefully before the AutoLoader is invoked) require_once( "$IP/LocalSettings.php" ); } + +if ( $wgEnableSelenium ) { + require_once( "$IP/includes/SeleniumWebSettings.php" ); +} + wfProfileOut( 'WebStart.php-conf' ); wfProfileIn( 'WebStart.php-ob_start' ); @@ -135,3 +140,4 @@ wfProfileOut( 'WebStart.php-ob_start' ); if ( !defined( 'MW_NO_SETUP' ) ) { require_once( "$IP/includes/Setup.php" ); } + diff --git a/maintenance/tests/RunSeleniumTests.php b/maintenance/tests/RunSeleniumTests.php index 0197c1df61..e705e61eaa 100644 --- a/maintenance/tests/RunSeleniumTests.php +++ b/maintenance/tests/RunSeleniumTests.php @@ -120,6 +120,7 @@ class SeleniumTester extends Maintenance { foreach ( $seleniumTestSuites as $testSuiteName => $testSuiteFile ) { require( $testSuiteFile ); $suite = new $testSuiteName(); + $suite->setName( $testSuiteName ); $suite->addTests(); try { diff --git a/maintenance/tests/selenium/SeleniumTestSuite.php b/maintenance/tests/selenium/SeleniumTestSuite.php index 88bd9b1fc5..b5f69e2091 100644 --- a/maintenance/tests/selenium/SeleniumTestSuite.php +++ b/maintenance/tests/selenium/SeleniumTestSuite.php @@ -3,6 +3,7 @@ abstract class SeleniumTestSuite extends PHPUnit_Framework_TestSuite { private $selenium; private $isSetUp = false; + private $loginBeforeTests = true; // Do not add line break after test output const CONTINUE_LINE = 1; @@ -20,12 +21,14 @@ abstract class SeleniumTestSuite extends PHPUnit_Framework_TestSuite { $this->isSetUp = true; $this->selenium = Selenium::getInstance(); $this->selenium->start(); - //$this->selenium->open( $this->selenium->getUrl() . '/index.php?setupTestSuite=' . $this->getName() ); - $this->login(); + $this->selenium->open( $this->selenium->getUrl() . '/index.php?setupTestSuite=' . $this->getName() ); + if ( $this->loginBeforeTests ) { + $this->login(); + } } public function tearDown() { - //$this->selenium->open( $this->selenium->getUrl() . '/index.php?clearTestSuite=' . $this->getName() ); + $this->selenium->open( $this->selenium->getUrl() . '/index.php?clearTestSuite=' . $this->getName() ); $this->selenium->stop(); } @@ -36,4 +39,8 @@ abstract class SeleniumTestSuite extends PHPUnit_Framework_TestSuite { public function loadPage( $title, $action ) { $this->selenium->loadPage( $title, $action ); } + + protected function setLoginBeforeTests( $loginBeforeTests = true ) { + $this->loginBeforeTests = $loginBeforeTests; + } } diff --git a/maintenance/tests/selenium/SimpleSeleniumTestCase.php b/maintenance/tests/selenium/SimpleSeleniumTestCase.php index ea44e7357b..8f27dcd360 100644 --- a/maintenance/tests/selenium/SimpleSeleniumTestCase.php +++ b/maintenance/tests/selenium/SimpleSeleniumTestCase.php @@ -1,9 +1,10 @@ open( $this->getUrl() . '/index.php?title=Selenium&action=edit' ); $this->type( "wpTextbox1", "This is a basic test" ); @@ -14,19 +15,12 @@ class SimpleSeleniumTestCase extends SeleniumTestCase $source = $this->getText( "//div[@id='wikiPreview']/p" ); $correct = strstr( $source, "This is a basic test" ); $this->assertEquals( $correct, true ); - } - /* - * Needs the following in your LocalConfig or an alternative method of configuration (coming soon) - * require_once( "$IP/extensions/UsabilityInitiative/Vector/Vector.php" ); - * $wgDefaultSkin='vector'; - */ - public function testGlobalVariable1() - { + public function testGlobalVariableForDefaultSkin() { $this->open( $this->getUrl() . '/index.php?&action=purge' ); $bodyClass = $this->getAttribute( "//body/@class" ); - $this-> assertContains('skin-vector', $bodyClass, 'Vector skin not set'); + $this-> assertContains('skin-chick', $bodyClass, 'Chick skin not set'); } } diff --git a/maintenance/tests/selenium/SimpleSeleniumTestSuite.php b/maintenance/tests/selenium/SimpleSeleniumTestSuite.php index bad4ca376a..cf3293766e 100644 --- a/maintenance/tests/selenium/SimpleSeleniumTestSuite.php +++ b/maintenance/tests/selenium/SimpleSeleniumTestSuite.php @@ -1,7 +1,21 @@ setLoginBeforeTests( false ); + parent::setUp(); + } public function addTests() { $testFiles = array( 'maintenance/tests/selenium/SimpleSeleniumTestCase.php' -- 2.20.1