r65718 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65717‎ | r65718 | r65719 >
Date:22:21, 30 April 2010
Author:ashley
Status:ok
Tags:
Comment:
more follow-up to r65715: coding style tweaks, etc.
Modified paths:
  • /trunk/phase3/maintenance/tests/RunSeleniumTests.php (modified) (history)
  • /trunk/phase3/maintenance/tests/selenium/Selenium.php (modified) (history)
  • /trunk/phase3/maintenance/tests/selenium/SeleniumTestCase.php (modified) (history)
  • /trunk/phase3/maintenance/tests/selenium/SeleniumTestConsoleLogger.php (modified) (history)
  • /trunk/phase3/maintenance/tests/selenium/SeleniumTestHTMLLogger.php (modified) (history)
  • /trunk/phase3/maintenance/tests/selenium/SeleniumTestListener.php (modified) (history)
  • /trunk/phase3/maintenance/tests/selenium/SeleniumTestSuite.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/tests/RunSeleniumTests.php
@@ -1,49 +1,50 @@
22 <?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 - */
 3+/**
 4+ * @file
 5+ * @ingroup Maintenance
 6+ * @copyright Copyright © Wikimedia Deuschland, 2009
 7+ * @author Hallo Welt! Medienwerkstatt GmbH
 8+ * @author Markus Glaser
 9+ *
 10+ * This program is free software; you can redistribute it and/or modify
 11+ * it under the terms of the GNU General Public License as published by
 12+ * the Free Software Foundation; either version 2 of the License, or
 13+ * (at your option) any later version.
 14+ *
 15+ * This program is distributed in the hope that it will be useful,
 16+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 18+ * GNU General Public License for more details.
 19+ *
 20+ * You should have received a copy of the GNU General Public License along
 21+ * with this program; if not, write to the Free Software Foundation, Inc.,
 22+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 23+ * http://www.gnu.org/copyleft/gpl.html
 24+ */
2425
25 -define( "MEDIAWIKI", true );
26 -define( "SELENIUMTEST", true);
 26+define( 'MEDIAWIKI', true );
 27+define( 'SELENIUMTEST', true );
2728
28 -//command line only
 29+// Command line only
2930 $wgSeleniumTestsRunMode = 'cli';
3031 if( $wgSeleniumTestsRunMode == 'cli' && php_sapi_name() != 'cli' ) {
3132 echo 'Must be run from the command line.';
3233 die( -1 );
3334 }
34 -//include path and installation instructions
 35+// include path and installation instructions
3536
36 -//URL: http://localhost/tests/RunSeleniumTests.php
37 -//set_include_path(get_include_path() . PATH_SEPARATOR . './PEAR/');
 37+// URL: http://localhost/tests/RunSeleniumTests.php
 38+//set_include_path( get_include_path() . PATH_SEPARATOR . './PEAR/' );
3839
3940 // Hostname of selenium server
40 -$wgSeleniumTestsSeleniumHost = "http://localhost";
 41+$wgSeleniumTestsSeleniumHost = 'http://localhost';
4142
4243 // URL of the wiki to be tested.
43 -$wgSeleniumTestsWikiUrl = 'http://localhost';
 44+$wgSeleniumTestsWikiUrl = 'http://localhost';
4445
4546 // Wiki login. Used by Selenium to log onto the wiki
46 -$wgSeleniumTestsWikiUser = "WikiSysop";
47 -$wgSeleniumTestsWikiPassword = "password";
 47+$wgSeleniumTestsWikiUser = 'WikiSysop';
 48+$wgSeleniumTestsWikiPassword = 'password';
4849
4950 // Common browsers on Windows platform
5051 // Use the *chrome handler in order to be able to test file uploads
@@ -69,12 +70,16 @@
7071 require_once 'selenium/SeleniumTestCase.php';
7172
7273 $result = new PHPUnit_Framework_TestResult;
73 -switch ($wgSeleniumTestsRunMode) {
74 - case 'html' : $logger = new SeleniumTestHTMLLogger; break;
75 - case 'cli' : $logger = new SeleniumTestConsoleLogger; break;
 74+switch ( $wgSeleniumTestsRunMode ) {
 75+ case 'html':
 76+ $logger = new SeleniumTestHTMLLogger;
 77+ break;
 78+ case 'cli':
 79+ $logger = new SeleniumTestConsoleLogger;
 80+ break;
7681 }
77 -$result->addListener(new SeleniumTestListener($logger));
7882
 83+$result->addListener( new SeleniumTestListener( $logger ) );
7984
8085 $wgSeleniumTestSuites = array();
8186
@@ -82,12 +87,11 @@
8388 #include_once '<your tests>';
8489
8590 // Here, you can override standard setting
86 -if (file_exists('LocalSeleniumSettings.php'))
87 -{
 91+if ( file_exists( 'LocalSeleniumSettings.php' ) ) {
8892 include_once 'LocalSeleniumSettings.php';
8993 }
9094
9195 // run tests
92 -foreach ($wgSeleniumTestSuites as $suite)
93 - $suite->run($result);
94 -?>
 96+foreach ( $wgSeleniumTestSuites as $suite ) {
 97+ $suite->run( $result );
 98+}
\ No newline at end of file
Index: trunk/phase3/maintenance/tests/selenium/SeleniumTestSuite.php
@@ -1,40 +1,34 @@
22 <?php
3 -if (!defined('MEDIAWIKI') || !defined('SELENIUMTEST')) {
 3+if ( !defined( 'MEDIAWIKI' ) || !defined( 'SELENIUMTEST' ) ) {
44 echo "This script cannot be run standalone";
5 - exit(1);
 5+ exit( 1 );
66 }
77
88 // 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);
 9+define( 'MW_TESTLOGGER_CONTINUE_LINE', 1 );
 10+define( 'MW_TESTLOGGER_RESULT_OK', 2 );
 11+define( 'MW_TESTLOGGER_RESULT_ERROR', 3 );
1212
13 -class SeleniumTestSuite extends PHPUnit_Framework_TestSuite
14 -{
 13+class SeleniumTestSuite extends PHPUnit_Framework_TestSuite {
1514 private $selenium;
1615
17 - public function setUp()
18 - {
19 -
 16+ public function setUp() {
2017 $this->selenium = Selenium::getInstance();
2118 $this->selenium->start();
2219 $this->login();
23 - //$this->loadPage('Testpage', 'edit');
 20+ //$this->loadPage( 'Testpage', 'edit' );
2421 }
2522
26 - public function tearDown()
27 - {
 23+ public function tearDown() {
2824 $this->selenium->stop();
2925 }
3026
31 - public function login()
32 - {
 27+ public function login() {
3328 $this->selenium->login();
3429 }
3530
36 - public function loadPage($title, $action)
37 - {
38 - $this->selenium->loadPage($title, $action);
 31+ public function loadPage( $title, $action ) {
 32+ $this->selenium->loadPage( $title, $action );
3933 }
4034 }
4135
Index: trunk/phase3/maintenance/tests/selenium/SeleniumTestCase.php
@@ -1,43 +1,34 @@
22 <?php
3 -if (!defined('MEDIAWIKI') || !defined('SELENIUMTEST')) {
 3+if ( !defined( 'MEDIAWIKI' ) || !defined( 'SELENIUMTEST' ) ) {
44 echo "This script cannot be run standalone";
5 - exit(1);
 5+ exit( 1 );
66 }
77
8 -class SeleniumTestCase extends PHPUnit_Framework_TestCase //PHPUnit_Extensions_SeleniumTestCase
9 -{
 8+class SeleniumTestCase extends PHPUnit_Framework_TestCase { //PHPUnit_Extensions_SeleniumTestCase
109 protected $selenium;
1110
12 - public function setUp()
13 - {
14 - set_time_limit(60);
 11+ public function setUp() {
 12+ set_time_limit( 60 );
1513 $this->selenium = Selenium::getInstance();
16 - //print_r($this->suite);
1714 }
1815
19 - public function tearDown()
20 - {
 16+ public function tearDown() {
2117
2218 }
2319
24 - public function __call($method, $args)
25 - {
26 - return call_user_func_array (array($this->selenium, $method), $args);
 20+ public function __call( $method, $args ) {
 21+ return call_user_func_array( array( $this->selenium, $method ), $args );
2722 }
2823
29 - public function assertSeleniumAttributeEquals($attribute, $value)
30 - {
31 - $attr = $this->getAttribute($attribute);
32 - $this->assertEquals($attr, $value);
 24+ public function assertSeleniumAttributeEquals( $attribute, $value ) {
 25+ $attr = $this->getAttribute( $attribute );
 26+ $this->assertEquals( $attr, $value );
3327 }
3428
35 - public function assertSeleniumHTMLContains($element, $text)
36 - {
37 - $innerHTML = $this->getText($element);
38 - //or assertContains
39 - $this->assertRegExp("/$text/", $innerHTML );
 29+ public function assertSeleniumHTMLContains( $element, $text ) {
 30+ $innerHTML = $this->getText( $element );
 31+ // or assertContains
 32+ $this->assertRegExp( "/$text/", $innerHTML );
4033 }
4134
42 -}
43 -
44 -?>
 35+}
\ No newline at end of file
Index: trunk/phase3/maintenance/tests/selenium/Selenium.php
@@ -4,53 +4,47 @@
55 * This is implemented as a singleton.
66 */
77
8 -if (!defined('MEDIAWIKI') || !defined('SELENIUMTEST')) {
 8+if ( !defined( 'MEDIAWIKI' ) || !defined( 'SELENIUMTEST' ) ) {
99 echo "This script cannot be run standalone";
10 - exit(1);
 10+ exit( 1 );
1111 }
1212
13 -class Selenium extends Testing_Selenium
14 -{
 13+class Selenium extends Testing_Selenium {
1514 protected static $_instance = null;
1615 public $isStarted = false;
17 - public static function getInstance()
18 - {
 16+
 17+ public static function getInstance() {
1918 global $wgSeleniumTestsBrowsers, $wgSeleniumTestsSeleniumHost, $wgSeleniumTestsUseBrowser;
20 - if (null === self::$_instance)
21 - {
22 - self::$_instance = new self($wgSeleniumTestsBrowsers[$wgSeleniumTestsUseBrowser], $wgSeleniumTestsSeleniumHost);
 19+ if ( null === self::$_instance ) {
 20+ self::$_instance = new self( $wgSeleniumTestsBrowsers[$wgSeleniumTestsUseBrowser], $wgSeleniumTestsSeleniumHost );
2321 }
2422 return self::$_instance;
2523 }
2624
27 - public function start()
28 - {
 25+ public function start() {
2926 global $wgSeleniumTestsBrowsers, $wgSeleniumTestsSeleniumHost;
3027 parent::start();
3128 $this->isStarted = true;
3229 }
3330
34 - public function stop()
35 - {
 31+ public function stop() {
3632 parent::stop();
3733 $this->isStarted = false;
3834 }
3935
40 - public function login()
41 - {
 36+ public function login() {
4237 global $wgSeleniumTestsWikiUser, $wgSeleniumTestsWikiPassword, $wgSeleniumTestsWikiUrl;
4338
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*'));
 39+ $this->open( $wgSeleniumTestsWikiUrl . '/index.php?title=Special:Userlogin' );
 40+ $this->type( 'wpName1', $wgSeleniumTestsWikiUser );
 41+ $this->type( 'wpPassword1', $wgSeleniumTestsWikiPassword );
 42+ $this->click( "//input[@id='wpLoginAttempt']" );
 43+ $value = $this->doCommand( 'assertTitle', array( 'Anmeldung erfolgreich*' ) );
4944 }
5045
51 - public function loadPage($title, $action)
52 - {
 46+ public function loadPage( $title, $action ) {
5347 global $wgSeleniumTestsWikiUrl;
54 - $this->open($wgSeleniumTestsWikiUrl.'/index.php?title='.$title.'&action='.$action);
 48+ $this->open( $wgSeleniumTestsWikiUrl . '/index.php?title=' . $title . '&action=' . $action );
5549 }
5650
5751 // Prevent external cloning
Index: trunk/phase3/maintenance/tests/selenium/SeleniumTestConsoleLogger.php
@@ -1,28 +1,28 @@
22 <?php
3 -if (!defined('MEDIAWIKI') || !defined('SELENIUMTEST')) {
 3+if ( !defined( 'MEDIAWIKI' ) || !defined( 'SELENIUMTEST' ) ) {
44 echo "This script cannot be run standalone";
5 - exit(1);
 5+ exit( 1 );
66 }
77
8 -class SeleniumTestConsoleLogger
9 -{
10 - public function __construct()
11 - {
 8+class SeleniumTestConsoleLogger {
 9+ public function __construct() {
1210 // 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 -
 11+ @ini_set( 'zlib.output_compression', 0 );
 12+ @ini_set( 'implicit_flush', 1 );
 13+ for ( $i = 0; $i < ob_get_level(); $i++ ) {
 14+ ob_end_flush();
 15+ }
 16+ ob_implicit_flush( 1 );
1817 }
1918
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";
 19+ public function write( $message, $mode = false ) {
 20+ $out = '';
 21+ //if ( $mode == MW_TESTLOGGER_RESULT_OK ) $out .= '<font color="green">';
 22+ $out .= htmlentities( $message );
 23+ //if ( $mode == MW_TESTLOGGER_RESULT_OK ) $out .= '</font>';
 24+ if ( $mode != MW_TESTLOGGER_CONTINUE_LINE ) {
 25+ $out .= "\n";
 26+ }
2727
2828 echo $out;
2929 }
Index: trunk/phase3/maintenance/tests/selenium/SeleniumTestHTMLLogger.php
@@ -1,42 +1,45 @@
22 <?php
3 -if (!defined('MEDIAWIKI') || !defined('SELENIUMTEST')) {
 3+if ( !defined( 'MEDIAWIKI' ) || !defined( 'SELENIUMTEST' ) ) {
44 echo "This script cannot be run standalone";
5 - exit(1);
 5+ exit( 1 );
66 }
77
8 -class SeleniumTestHTMLLogger
9 -{
10 - public function __construct()
11 - {
 8+class SeleniumTestHTMLLogger {
 9+ public function __construct() {
1210 // 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 -
 11+ @ini_set( 'zlib.output_compression', 0 );
 12+ @ini_set( 'implicit_flush', 1 );
 13+ for ( $i = 0; $i < ob_get_level(); $i++ ) {
 14+ ob_end_flush();
 15+ }
 16+ ob_implicit_flush( 1 );
 17+
1818 // Output some style information
1919 echo '<style>
2020 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+ */
 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+ */
2828 }
2929 </style>';
30 -
31 -
3230 }
3331
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/>';
 32+ public function write( $message, $mode = false ) {
 33+ $out = '';
 34+ if ( $mode == MW_TESTLOGGER_RESULT_OK ) {
 35+ $out .= '<font color="green">';
 36+ }
 37+ $out .= htmlentities( $message );
 38+ if ( $mode == MW_TESTLOGGER_RESULT_OK ) {
 39+ $out .= '</font>';
 40+ }
 41+ if ( $mode != MW_TESTLOGGER_CONTINUE_LINE ) {
 42+ $out .= '<br />';
 43+ }
4144
4245 echo $out;
4346 }
Index: trunk/phase3/maintenance/tests/selenium/SeleniumTestListener.php
@@ -1,74 +1,69 @@
22 <?php
3 -if (!defined('MEDIAWIKI') || !defined('SELENIUMTEST')) {
 3+if ( !defined( 'MEDIAWIKI' ) || !defined( 'SELENIUMTEST' ) ) {
44 echo "This script cannot be run standalone";
5 - exit(1);
 5+ exit( 1 );
66 }
77
8 -class SeleniumTestListener implements PHPUnit_Framework_TestListener
9 -{
 8+class SeleniumTestListener implements PHPUnit_Framework_TestListener {
109 private $logger;
1110 private $tests_ok = 0;
1211 private $tests_failed = 0;
1312
14 - public function __construct($loggerInstance)
15 - {
 13+ public function __construct( $loggerInstance ) {
1614 $this->logger = $loggerInstance;
1715 }
1816
19 - public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
20 - {
21 - $this->logger->write("Error: ".$e->getMessage());
 17+ public function addError( PHPUnit_Framework_Test $test, Exception $e, $time ) {
 18+ $this->logger->write( 'Error: ' . $e->getMessage() );
2219 $this->tests_failed++;
2320 }
2421
25 - public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
 22+ public function addFailure( PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time )
2623 {
27 - $this->logger->write("Failed: ".$e->getMessage());
 24+ $this->logger->write( 'Failed: ' . $e->getMessage() );
2825 $this->tests_failed++;
29 -
3026 }
3127
32 - public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
 28+ public function addIncompleteTest( PHPUnit_Framework_Test $test, Exception $e, $time )
3329 {
34 - $this->logger->write("Incomplete.");
 30+ $this->logger->write( 'Incomplete.' );
3531 $this->tests_failed++;
3632 }
3733
38 - public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
 34+ public function addSkippedTest( PHPUnit_Framework_Test $test, Exception $e, $time )
3935 {
40 - $this->logger->write("Skipped.");
 36+ $this->logger->write( 'Skipped.' );
4137 $this->tests_failed++;
4238 }
4339
44 - public function startTest(PHPUnit_Framework_Test $test)
45 - {
46 - $this->logger->write("Testing ".$test->getName()." ... ", MW_TESTLOGGER_CONTINUE_LINE);
 40+ public function startTest( PHPUnit_Framework_Test $test ) {
 41+ $this->logger->write(
 42+ 'Testing ' . $test->getName() . ' ... ',
 43+ MW_TESTLOGGER_CONTINUE_LINE
 44+ );
4745 }
4846
49 - public function endTest(PHPUnit_Framework_Test $test, $time)
50 - {
51 - if (!$test->hasFailed())
52 - {
53 - $this->logger->write("OK", MW_TESTLOGGER_RESULT_OK);
 47+ public function endTest( PHPUnit_Framework_Test $test, $time ) {
 48+ if ( !$test->hasFailed() ) {
 49+ $this->logger->write( 'OK', MW_TESTLOGGER_RESULT_OK );
5450 $this->tests_ok++;
5551 }
5652 }
5753
58 - public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
59 - {
60 - $this->logger->write("Testsuite ".$suite->getName()." started.");
 54+ public function startTestSuite( PHPUnit_Framework_TestSuite $suite ) {
 55+ $this->logger->write( 'Testsuite ' . $suite->getName() . ' started.' );
6156 $this->tests_ok = 0;
6257 }
6358
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 -
 59+ public function endTestSuite( PHPUnit_Framework_TestSuite $suite ) {
 60+ $this->logger->write(
 61+ 'Testsuite ' . $suite->getName() . ' ended. OK: ' .
 62+ $this->tests_ok . ' Failed: ' . $this->tests_failed
 63+ );
6864 }
6965
70 - public function statusMessage($message)
71 - {
72 - $this->logger->write($message);
 66+ public function statusMessage( $message ) {
 67+ $this->logger->write( $message );
7368 }
7469 }
7570

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r65715Initial commit of the Selenium frameworklaner20:45, 30 April 2010

Status & tagging log