* Let test suites run without logging in.
--- /dev/null
+<?php
+/*
+ * Dynamically change configuration variables based on the test suite name and a cookie value.
+ * For details on how to configure a wiki for a Selenium test, see:
+ * http://www.mediawiki.org/wiki/SeleniumFramework#Test_Wiki_configuration
+ */
+if ( !$wgEnableSelenium ) {
+ return;
+}
+$cookiePrefix = $wgSitename . "-";
+$name = $cookiePrefix . "Selenium";
+
+//if we find a request parameter containing the test name, set a cookie with the test name
+if ( array_key_exists( 'setupTestSuite', $_GET) ) {
+ //TODO: do a check for valid testsuite names
+ $setupTestSuiteName = $_GET['setupTestSuite'];
+ if ( strlen( $setupTestSuiteName) > 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
# 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' );
if ( !defined( 'MW_NO_SETUP' ) ) {
require_once( "$IP/includes/Setup.php" );
}
+
foreach ( $seleniumTestSuites as $testSuiteName => $testSuiteFile ) {
require( $testSuiteFile );
$suite = new $testSuiteName();
+ $suite->setName( $testSuiteName );
$suite->addTests();
try {
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;
$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();
}
public function loadPage( $title, $action ) {
$this->selenium->loadPage( $title, $action );
}
+
+ protected function setLoginBeforeTests( $loginBeforeTests = true ) {
+ $this->loginBeforeTests = $loginBeforeTests;
+ }
}
<?php
-
-class SimpleSeleniumTestCase extends SeleniumTestCase
-{
- public function testBasic()
- {
+/*
+ * This test case is part of the SimpleSeleniumTestSuite.
+ * Configuration for these tests are dosumented as part of SimpleSeleniumTestSuite.php
+ */
+class SimpleSeleniumTestCase extends SeleniumTestCase {
+ public function testBasic() {
$this->open( $this->getUrl() .
'/index.php?title=Selenium&action=edit' );
$this->type( "wpTextbox1", "This is a basic test" );
$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');
}
}
<?php
-
+/*
+ * Sample test suite.
+ * Two ways to configure MW for these tests
+ * 1) If you are running multiple test suites, add the following in LocalSettings.php
+ * require_once("maintenance/tests/selenium/SimpleSeleniumConfig.php");
+ * $wgSeleniumTestConfigs['SimpleSeleniumTestSuite'] = 'SimpleSeleniumConfig::getSettings';
+ * OR
+ * 2) Add the following to your Localsettings.php
+ * require_once( "$IP/skins/Chick.php" );
+ * $wgDefaultSkin = 'chick';
+ */
class SimpleSeleniumTestSuite extends SeleniumTestSuite
{
+ public function setUp() {
+ $this->setLoginBeforeTests( false );
+ parent::setUp();
+ }
public function addTests() {
$testFiles = array(
'maintenance/tests/selenium/SimpleSeleniumTestCase.php'