Index: trunk/phase3/maintenance/tests/RunSeleniumTests.php |
— | — | @@ -0,0 +1,93 @@ |
| 2 | +<?php |
| 3 | + /** |
| 4 | + * Copyright (C) Wikimedia Deuschland, 2009 |
| 5 | + * Authors Hallo Welt! Medienwerkstatt GmbH |
| 6 | + * Authors Markus Glaser |
| 7 | + * |
| 8 | + * This program is free software; you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU General Public License as published by |
| 10 | + * the Free Software Foundation; either version 2 of the License, or |
| 11 | + * (at your option) any later version. |
| 12 | + * |
| 13 | + * This program is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + * GNU General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU General Public License along |
| 19 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 21 | + * http://www.gnu.org/copyleft/gpl.html |
| 22 | + * |
| 23 | + */ |
| 24 | + |
| 25 | +define( "MEDIAWIKI", true ); |
| 26 | +define( "SELENIUMTEST", true); |
| 27 | + |
| 28 | +//command line only |
| 29 | +$wgSeleniumTestsRunMode = 'cli'; |
| 30 | +if( $wgSeleniumTestsRunMode == 'cli' && php_sapi_name() != 'cli' ) { |
| 31 | + echo 'Must be run from the command line.'; |
| 32 | + die( -1 ); |
| 33 | +} |
| 34 | +//include path and installation instructions |
| 35 | + |
| 36 | +//URL: http://localhost/tests/RunSeleniumTests.php |
| 37 | +//set_include_path(get_include_path() . PATH_SEPARATOR . './PEAR/'); |
| 38 | + |
| 39 | +// Hostname of selenium server |
| 40 | +$wgSeleniumTestsSeleniumHost = "http://localhost"; |
| 41 | + |
| 42 | +// URL of the wiki to be tested. |
| 43 | +$wgSeleniumTestsWikiUrl = 'http://localhost'; |
| 44 | + |
| 45 | +// Wiki login. Used by Selenium to log onto the wiki |
| 46 | +$wgSeleniumTestsWikiUser = "WikiSysop"; |
| 47 | +$wgSeleniumTestsWikiPassword = "password"; |
| 48 | + |
| 49 | +// Common browsers on Windows platform |
| 50 | +// Use the *chrome handler in order to be able to test file uploads |
| 51 | +// 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/ |
| 52 | +//$wgSeleniumTestsBrowsers['firefox'] = '*firefox c:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe'; |
| 53 | +$wgSeleniumTestsBrowsers['firefox'] = '*chrome c:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe'; |
| 54 | +$wgSeleniumTestsBrowsers['iexplorer'] = '*iexploreproxy'; |
| 55 | + |
| 56 | +// Actually, use this browser |
| 57 | +$wgSeleniumTestsUseBrowser = 'firefox'; |
| 58 | + |
| 59 | +// requires PHPUnit 3.4 |
| 60 | +require_once 'Testing/Selenium.php'; |
| 61 | +require_once 'PHPUnit/Framework.php'; |
| 62 | +require_once 'PHPUnit/Extensions/SeleniumTestCase.php'; |
| 63 | + |
| 64 | +// include uiTestsuite |
| 65 | +require_once 'selenium/SeleniumTestHTMLLogger.php'; |
| 66 | +require_once 'selenium/SeleniumTestConsoleLogger.php'; |
| 67 | +require_once 'selenium/SeleniumTestListener.php'; |
| 68 | +require_once 'selenium/Selenium.php'; |
| 69 | +require_once 'selenium/SeleniumTestSuite.php'; |
| 70 | +require_once 'selenium/SeleniumTestCase.php'; |
| 71 | + |
| 72 | +$result = new PHPUnit_Framework_TestResult; |
| 73 | +switch ($wgSeleniumTestsRunMode) { |
| 74 | + case 'html' : $logger = new SeleniumTestHTMLLogger; break; |
| 75 | + case 'cli' : $logger = new SeleniumTestConsoleLogger; break; |
| 76 | +} |
| 77 | +$result->addListener(new SeleniumTestListener($logger)); |
| 78 | + |
| 79 | + |
| 80 | +$wgSeleniumTestSuites = array(); |
| 81 | + |
| 82 | +// Todo: include automatically |
| 83 | +#include_once '<your tests>'; |
| 84 | + |
| 85 | +// Here, you can override standard setting |
| 86 | +if (file_exists('LocalSeleniumSettings.php')) |
| 87 | +{ |
| 88 | + include_once 'LocalSeleniumSettings.php'; |
| 89 | +} |
| 90 | + |
| 91 | +// run tests |
| 92 | +foreach ($wgSeleniumTestSuites as $suite) |
| 93 | + $suite->run($result); |
| 94 | +?> |
Property changes on: trunk/phase3/maintenance/tests/RunSeleniumTests.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 95 | + native |
Index: trunk/phase3/maintenance/tests/selenium/SeleniumTestSuite.php |
— | — | @@ -0,0 +1,40 @@ |
| 2 | +<?php |
| 3 | +if (!defined('MEDIAWIKI') || !defined('SELENIUMTEST')) { |
| 4 | + echo "This script cannot be run standalone"; |
| 5 | + exit(1); |
| 6 | +} |
| 7 | + |
| 8 | +// Do not add line break after test output |
| 9 | +define('MW_TESTLOGGER_CONTINUE_LINE', 1); |
| 10 | +define('MW_TESTLOGGER_RESULT_OK', 2); |
| 11 | +define('MW_TESTLOGGER_RESULT_ERROR', 3); |
| 12 | + |
| 13 | +class SeleniumTestSuite extends PHPUnit_Framework_TestSuite |
| 14 | +{ |
| 15 | + private $selenium; |
| 16 | + |
| 17 | + public function setUp() |
| 18 | + { |
| 19 | + |
| 20 | + $this->selenium = Selenium::getInstance(); |
| 21 | + $this->selenium->start(); |
| 22 | + $this->login(); |
| 23 | + //$this->loadPage('Testpage', 'edit'); |
| 24 | + } |
| 25 | + |
| 26 | + public function tearDown() |
| 27 | + { |
| 28 | + $this->selenium->stop(); |
| 29 | + } |
| 30 | + |
| 31 | + public function login() |
| 32 | + { |
| 33 | + $this->selenium->login(); |
| 34 | + } |
| 35 | + |
| 36 | + public function loadPage($title, $action) |
| 37 | + { |
| 38 | + $this->selenium->loadPage($title, $action); |
| 39 | + } |
| 40 | +} |
| 41 | + |
Property changes on: trunk/phase3/maintenance/tests/selenium/SeleniumTestSuite.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 42 | + native |
Index: trunk/phase3/maintenance/tests/selenium/SeleniumTestCase.php |
— | — | @@ -0,0 +1,43 @@ |
| 2 | +<?php |
| 3 | +if (!defined('MEDIAWIKI') || !defined('SELENIUMTEST')) { |
| 4 | + echo "This script cannot be run standalone"; |
| 5 | + exit(1); |
| 6 | +} |
| 7 | + |
| 8 | +class SeleniumTestCase extends PHPUnit_Framework_TestCase //PHPUnit_Extensions_SeleniumTestCase |
| 9 | +{ |
| 10 | + protected $selenium; |
| 11 | + |
| 12 | + public function setUp() |
| 13 | + { |
| 14 | + set_time_limit(60); |
| 15 | + $this->selenium = Selenium::getInstance(); |
| 16 | + //print_r($this->suite); |
| 17 | + } |
| 18 | + |
| 19 | + public function tearDown() |
| 20 | + { |
| 21 | + |
| 22 | + } |
| 23 | + |
| 24 | + public function __call($method, $args) |
| 25 | + { |
| 26 | + return call_user_func_array (array($this->selenium, $method), $args); |
| 27 | + } |
| 28 | + |
| 29 | + public function assertSeleniumAttributeEquals($attribute, $value) |
| 30 | + { |
| 31 | + $attr = $this->getAttribute($attribute); |
| 32 | + $this->assertEquals($attr, $value); |
| 33 | + } |
| 34 | + |
| 35 | + public function assertSeleniumHTMLContains($element, $text) |
| 36 | + { |
| 37 | + $innerHTML = $this->getText($element); |
| 38 | + //or assertContains |
| 39 | + $this->assertRegExp("/$text/", $innerHTML ); |
| 40 | + } |
| 41 | + |
| 42 | +} |
| 43 | + |
| 44 | +?> |
Property changes on: trunk/phase3/maintenance/tests/selenium/SeleniumTestCase.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 45 | + native |
Index: trunk/phase3/maintenance/tests/selenium/Selenium.php |
— | — | @@ -0,0 +1,60 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Selenium connector |
| 5 | + * This is implemented as a singleton. |
| 6 | + */ |
| 7 | + |
| 8 | +if (!defined('MEDIAWIKI') || !defined('SELENIUMTEST')) { |
| 9 | + echo "This script cannot be run standalone"; |
| 10 | + exit(1); |
| 11 | +} |
| 12 | + |
| 13 | +class Selenium extends Testing_Selenium |
| 14 | +{ |
| 15 | + protected static $_instance = null; |
| 16 | + public $isStarted = false; |
| 17 | + public static function getInstance() |
| 18 | + { |
| 19 | + global $wgSeleniumTestsBrowsers, $wgSeleniumTestsSeleniumHost, $wgSeleniumTestsUseBrowser; |
| 20 | + if (null === self::$_instance) |
| 21 | + { |
| 22 | + self::$_instance = new self($wgSeleniumTestsBrowsers[$wgSeleniumTestsUseBrowser], $wgSeleniumTestsSeleniumHost); |
| 23 | + } |
| 24 | + return self::$_instance; |
| 25 | + } |
| 26 | + |
| 27 | + public function start() |
| 28 | + { |
| 29 | + global $wgSeleniumTestsBrowsers, $wgSeleniumTestsSeleniumHost; |
| 30 | + parent::start(); |
| 31 | + $this->isStarted = true; |
| 32 | + } |
| 33 | + |
| 34 | + public function stop() |
| 35 | + { |
| 36 | + parent::stop(); |
| 37 | + $this->isStarted = false; |
| 38 | + } |
| 39 | + |
| 40 | + public function login() |
| 41 | + { |
| 42 | + global $wgSeleniumTestsWikiUser, $wgSeleniumTestsWikiPassword, $wgSeleniumTestsWikiUrl; |
| 43 | + |
| 44 | + $this->open($wgSeleniumTestsWikiUrl.'/index.php?title=Special:Userlogin'); |
| 45 | + $this->type("wpName1", $wgSeleniumTestsWikiUser); |
| 46 | + $this->type("wpPassword1", $wgSeleniumTestsWikiPassword); |
| 47 | + $this->click("//input[@id='wpLoginAttempt']"); |
| 48 | + $value = $this->doCommand('assertTitle', array('Anmeldung erfolgreich*')); |
| 49 | + } |
| 50 | + |
| 51 | + public function loadPage($title, $action) |
| 52 | + { |
| 53 | + global $wgSeleniumTestsWikiUrl; |
| 54 | + $this->open($wgSeleniumTestsWikiUrl.'/index.php?title='.$title.'&action='.$action); |
| 55 | + } |
| 56 | + |
| 57 | + // Prevent external cloning |
| 58 | + protected function __clone() {} |
| 59 | + // Prevent external construction |
| 60 | + //protected function __construct() {} |
| 61 | +} |
Property changes on: trunk/phase3/maintenance/tests/selenium/Selenium.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 62 | + native |
Index: trunk/phase3/maintenance/tests/selenium/SeleniumTestConsoleLogger.php |
— | — | @@ -0,0 +1,29 @@ |
| 2 | +<?php |
| 3 | +if (!defined('MEDIAWIKI') || !defined('SELENIUMTEST')) { |
| 4 | + echo "This script cannot be run standalone"; |
| 5 | + exit(1); |
| 6 | +} |
| 7 | + |
| 8 | +class SeleniumTestConsoleLogger |
| 9 | +{ |
| 10 | + public function __construct() |
| 11 | + { |
| 12 | + // Prepare testsuite for immediate output |
| 13 | + @ini_set('zlib.output_compression', 0); |
| 14 | + @ini_set('implicit_flush', 1); |
| 15 | + for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); } |
| 16 | + ob_implicit_flush(1); |
| 17 | + |
| 18 | + } |
| 19 | + |
| 20 | + public function write($message, $mode = false) |
| 21 | + { |
| 22 | + $out .= ''; |
| 23 | + //if ($mode == MW_TESTLOGGER_RESULT_OK) $out .= '<font color="green">'; |
| 24 | + $out .= htmlentities($message); |
| 25 | + //if ($mode == MW_TESTLOGGER_RESULT_OK) $out .= '</font>'; |
| 26 | + if ($mode != MW_TESTLOGGER_CONTINUE_LINE) $out .= "\n"; |
| 27 | + |
| 28 | + echo $out; |
| 29 | + } |
| 30 | +} |
\ No newline at end of file |
Property changes on: trunk/phase3/maintenance/tests/selenium/SeleniumTestConsoleLogger.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 31 | + native |
Index: trunk/phase3/maintenance/tests/selenium/SeleniumTestHTMLLogger.php |
— | — | @@ -0,0 +1,43 @@ |
| 2 | +<?php |
| 3 | +if (!defined('MEDIAWIKI') || !defined('SELENIUMTEST')) { |
| 4 | + echo "This script cannot be run standalone"; |
| 5 | + exit(1); |
| 6 | +} |
| 7 | + |
| 8 | +class SeleniumTestHTMLLogger |
| 9 | +{ |
| 10 | + public function __construct() |
| 11 | + { |
| 12 | + // Prepare testsuite for immediate output |
| 13 | + @ini_set('zlib.output_compression', 0); |
| 14 | + @ini_set('implicit_flush', 1); |
| 15 | + for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); } |
| 16 | + ob_implicit_flush(1); |
| 17 | + |
| 18 | + // Output some style information |
| 19 | + echo '<style> |
| 20 | + pre { |
| 21 | + overflow-x: auto; /* Use horizontal scroller if needed; for Firefox 2, not needed in Firefox 3 */ |
| 22 | + white-space: pre-wrap; /* css-3 */ |
| 23 | + white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */ |
| 24 | + white-space: -pre-wrap; /* Opera 4-6 */ |
| 25 | + white-space: -o-pre-wrap; /* Opera 7 */ |
| 26 | + /* width: 99%; */ |
| 27 | + word-wrap: break-word; /* Internet Explorer 5.5+ */ |
| 28 | + } |
| 29 | + </style>'; |
| 30 | + |
| 31 | + |
| 32 | + } |
| 33 | + |
| 34 | + public function write($message, $mode = false) |
| 35 | + { |
| 36 | + $out .= ''; |
| 37 | + if ($mode == MW_TESTLOGGER_RESULT_OK) $out .= '<font color="green">'; |
| 38 | + $out .= htmlentities($message); |
| 39 | + if ($mode == MW_TESTLOGGER_RESULT_OK) $out .= '</font>'; |
| 40 | + if ($mode != MW_TESTLOGGER_CONTINUE_LINE) $out .= '<br/>'; |
| 41 | + |
| 42 | + echo $out; |
| 43 | + } |
| 44 | +} |
\ No newline at end of file |
Property changes on: trunk/phase3/maintenance/tests/selenium/SeleniumTestHTMLLogger.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 45 | + native |
Index: trunk/phase3/maintenance/tests/selenium/SeleniumTestListener.php |
— | — | @@ -0,0 +1,74 @@ |
| 2 | +<?php |
| 3 | +if (!defined('MEDIAWIKI') || !defined('SELENIUMTEST')) { |
| 4 | + echo "This script cannot be run standalone"; |
| 5 | + exit(1); |
| 6 | +} |
| 7 | + |
| 8 | +class SeleniumTestListener implements PHPUnit_Framework_TestListener |
| 9 | +{ |
| 10 | + private $logger; |
| 11 | + private $tests_ok = 0; |
| 12 | + private $tests_failed = 0; |
| 13 | + |
| 14 | + public function __construct($loggerInstance) |
| 15 | + { |
| 16 | + $this->logger = $loggerInstance; |
| 17 | + } |
| 18 | + |
| 19 | + public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) |
| 20 | + { |
| 21 | + $this->logger->write("Error: ".$e->getMessage()); |
| 22 | + $this->tests_failed++; |
| 23 | + } |
| 24 | + |
| 25 | + public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) |
| 26 | + { |
| 27 | + $this->logger->write("Failed: ".$e->getMessage()); |
| 28 | + $this->tests_failed++; |
| 29 | + |
| 30 | + } |
| 31 | + |
| 32 | + public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) |
| 33 | + { |
| 34 | + $this->logger->write("Incomplete."); |
| 35 | + $this->tests_failed++; |
| 36 | + } |
| 37 | + |
| 38 | + public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) |
| 39 | + { |
| 40 | + $this->logger->write("Skipped."); |
| 41 | + $this->tests_failed++; |
| 42 | + } |
| 43 | + |
| 44 | + public function startTest(PHPUnit_Framework_Test $test) |
| 45 | + { |
| 46 | + $this->logger->write("Testing ".$test->getName()." ... ", MW_TESTLOGGER_CONTINUE_LINE); |
| 47 | + } |
| 48 | + |
| 49 | + public function endTest(PHPUnit_Framework_Test $test, $time) |
| 50 | + { |
| 51 | + if (!$test->hasFailed()) |
| 52 | + { |
| 53 | + $this->logger->write("OK", MW_TESTLOGGER_RESULT_OK); |
| 54 | + $this->tests_ok++; |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + public function startTestSuite(PHPUnit_Framework_TestSuite $suite) |
| 59 | + { |
| 60 | + $this->logger->write("Testsuite ".$suite->getName()." started."); |
| 61 | + $this->tests_ok = 0; |
| 62 | + } |
| 63 | + |
| 64 | + public function endTestSuite(PHPUnit_Framework_TestSuite $suite) |
| 65 | + { |
| 66 | + $this->logger->write("Testsuite ".$suite->getName()." ended. OK: ".$this->tests_ok." Failed: ".$this->tests_failed); |
| 67 | + |
| 68 | + } |
| 69 | + |
| 70 | + public function statusMessage($message) |
| 71 | + { |
| 72 | + $this->logger->write($message); |
| 73 | + } |
| 74 | +} |
| 75 | + |
Property changes on: trunk/phase3/maintenance/tests/selenium/SeleniumTestListener.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 76 | + native |