more follow-up to r65715: coding style tweaks, etc.
authorJack Phoenix <ashley@users.mediawiki.org>
Fri, 30 Apr 2010 22:21:36 +0000 (22:21 +0000)
committerJack Phoenix <ashley@users.mediawiki.org>
Fri, 30 Apr 2010 22:21:36 +0000 (22:21 +0000)
maintenance/tests/RunSeleniumTests.php
maintenance/tests/selenium/Selenium.php
maintenance/tests/selenium/SeleniumTestCase.php
maintenance/tests/selenium/SeleniumTestConsoleLogger.php
maintenance/tests/selenium/SeleniumTestHTMLLogger.php
maintenance/tests/selenium/SeleniumTestListener.php
maintenance/tests/selenium/SeleniumTestSuite.php

index bae7234..5c6478f 100644 (file)
@@ -1,49 +1,50 @@
 <?php
- /**
-  * Copyright (C) Wikimedia Deuschland, 2009
-  * Authors Hallo Welt! Medienwerkstatt GmbH
-  * Authors Markus Glaser
-  *
-  * This program is free software; you can redistribute it and/or modify
-  * it under the terms of the GNU General Public License as published by
-  * the Free Software Foundation; either version 2 of the License, or
-  * (at your option) any later version.
-  *
-  * This program is distributed in the hope that it will be useful,
-  * but WITHOUT ANY WARRANTY; without even the implied warranty of
-  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-  * GNU General Public License for more details.
-  *
-  * You should have received a copy of the GNU General Public License along
-  * with this program; if not, write to the Free Software Foundation, Inc.,
-  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-  * http://www.gnu.org/copyleft/gpl.html
-  *
-  */
-
-define( "MEDIAWIKI", true );
-define( "SELENIUMTEST", true);
-
-//command line only
+/**
+ * @file
+ * @ingroup Maintenance
+ * @copyright Copyright © Wikimedia Deuschland, 2009
+ * @author Hallo Welt! Medienwerkstatt GmbH
+ * @author Markus Glaser
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+define( 'MEDIAWIKI', true );
+define( 'SELENIUMTEST', true );
+
+// Command line only
 $wgSeleniumTestsRunMode = 'cli';
 if( $wgSeleniumTestsRunMode == 'cli' && php_sapi_name() != 'cli' ) {
        echo 'Must be run from the command line.';
        die( -1 );
 }
-//include path and installation instructions
+// include path and installation instructions
 
-//URL: http://localhost/tests/RunSeleniumTests.php
-//set_include_path(get_include_path() . PATH_SEPARATOR . './PEAR/');
+// URL: http://localhost/tests/RunSeleniumTests.php
+//set_include_path( get_include_path() . PATH_SEPARATOR . './PEAR/' );
 
 // Hostname of selenium server
-$wgSeleniumTestsSeleniumHost          = "http://localhost";
+$wgSeleniumTestsSeleniumHost = 'http://localhost';
 
 // URL of the wiki to be tested.
-$wgSeleniumTestsWikiUrl               = 'http://localhost';
+$wgSeleniumTestsWikiUrl = 'http://localhost';
 
 // Wiki login. Used by Selenium to log onto the wiki
-$wgSeleniumTestsWikiUser      = "WikiSysop";
-$wgSeleniumTestsWikiPassword  = "password";
+$wgSeleniumTestsWikiUser      = 'WikiSysop';
+$wgSeleniumTestsWikiPassword  = 'password';
 
 // Common browsers on Windows platform
 // Use the *chrome handler in order to be able to test file uploads
@@ -69,12 +70,16 @@ require_once 'selenium/SeleniumTestSuite.php';
 require_once 'selenium/SeleniumTestCase.php';
 
 $result = new PHPUnit_Framework_TestResult;
-switch ($wgSeleniumTestsRunMode) {
-    case 'html' : $logger = new SeleniumTestHTMLLogger; break;
-    case 'cli'  : $logger = new SeleniumTestConsoleLogger; break;
+switch ( $wgSeleniumTestsRunMode ) {
+       case 'html':
+               $logger = new SeleniumTestHTMLLogger;
+               break;
+       case 'cli':
+               $logger = new SeleniumTestConsoleLogger;
+               break;
 }
-$result->addListener(new SeleniumTestListener($logger));
 
+$result->addListener( new SeleniumTestListener( $logger ) );
 
 $wgSeleniumTestSuites = array();
 
@@ -82,12 +87,11 @@ $wgSeleniumTestSuites = array();
 #include_once '<your tests>';
 
 // Here, you can override standard setting
-if (file_exists('LocalSeleniumSettings.php'))
-{
+if ( file_exists( 'LocalSeleniumSettings.php' ) ) {
        include_once 'LocalSeleniumSettings.php';
 }
 
 // run tests
-foreach ($wgSeleniumTestSuites as $suite)
-    $suite->run($result);
-?>
+foreach ( $wgSeleniumTestSuites as $suite ) {
+       $suite->run( $result );
+}
\ No newline at end of file
index a1518ff..a040010 100644 (file)
@@ -4,53 +4,47 @@
  * This is implemented as a singleton.
  */
 
-if (!defined('MEDIAWIKI') || !defined('SELENIUMTEST')) {
+if ( !defined( 'MEDIAWIKI' ) || !defined( 'SELENIUMTEST' ) ) {
        echo "This script cannot be run standalone";
-       exit(1);
+       exit( 1 );
 }
 
-class Selenium extends Testing_Selenium
-{
+class Selenium extends Testing_Selenium {
        protected static $_instance = null;
        public $isStarted = false;
-       public static function getInstance()
-       {
+
+       public static function getInstance() {
                global $wgSeleniumTestsBrowsers, $wgSeleniumTestsSeleniumHost, $wgSeleniumTestsUseBrowser;
-               if (null === self::$_instance)
-               {
-                       self::$_instance = new self($wgSeleniumTestsBrowsers[$wgSeleniumTestsUseBrowser], $wgSeleniumTestsSeleniumHost);
+               if ( null === self::$_instance ) {
+                       self::$_instance = new self( $wgSeleniumTestsBrowsers[$wgSeleniumTestsUseBrowser], $wgSeleniumTestsSeleniumHost );
                }
                return self::$_instance;
        }
 
-       public function start()
-       {
+       public function start() {
                global $wgSeleniumTestsBrowsers, $wgSeleniumTestsSeleniumHost;
                parent::start();
                $this->isStarted = true;
        }
 
-       public function stop()
-       {
+       public function stop() {
                parent::stop();
                $this->isStarted = false;
        }
 
-       public function login()
-       {
+       public function login() {
                global $wgSeleniumTestsWikiUser, $wgSeleniumTestsWikiPassword, $wgSeleniumTestsWikiUrl;
 
-               $this->open($wgSeleniumTestsWikiUrl.'/index.php?title=Special:Userlogin');
-               $this->type("wpName1", $wgSeleniumTestsWikiUser);
-               $this->type("wpPassword1", $wgSeleniumTestsWikiPassword);
-               $this->click("//input[@id='wpLoginAttempt']");
-               $value = $this->doCommand('assertTitle', array('Anmeldung erfolgreich*'));
+               $this->open( $wgSeleniumTestsWikiUrl . '/index.php?title=Special:Userlogin' );
+               $this->type( 'wpName1', $wgSeleniumTestsWikiUser );
+               $this->type( 'wpPassword1', $wgSeleniumTestsWikiPassword );
+               $this->click( "//input[@id='wpLoginAttempt']" );
+               $value = $this->doCommand( 'assertTitle', array( 'Anmeldung erfolgreich*' ) );
        }
 
-       public function loadPage($title, $action)
-       {
+       public function loadPage( $title, $action ) {
                global $wgSeleniumTestsWikiUrl;
-               $this->open($wgSeleniumTestsWikiUrl.'/index.php?title='.$title.'&action='.$action);
+               $this->open( $wgSeleniumTestsWikiUrl . '/index.php?title=' . $title . '&action=' . $action );
        }
 
        // Prevent external cloning
index 86c2f0d..6f0a4a0 100644 (file)
@@ -1,43 +1,34 @@
 <?php
-if (!defined('MEDIAWIKI') || !defined('SELENIUMTEST')) {
+if ( !defined( 'MEDIAWIKI' ) || !defined( 'SELENIUMTEST' ) ) {
        echo "This script cannot be run standalone";
-       exit(1);
+       exit( 1 );
 }
 
-class SeleniumTestCase extends PHPUnit_Framework_TestCase //PHPUnit_Extensions_SeleniumTestCase
-{
+class SeleniumTestCase extends PHPUnit_Framework_TestCase { //PHPUnit_Extensions_SeleniumTestCase
        protected $selenium;
 
-       public function setUp()
-       {
-               set_time_limit(60);
+       public function setUp() {
+               set_time_limit( 60 );
                $this->selenium = Selenium::getInstance();
-               //print_r($this->suite);
        }
 
-       public function tearDown()
-       {
+       public function tearDown() {
 
        }
 
-       public function __call($method, $args)
-       {
-          return call_user_func_array (array($this->selenium, $method), $args);
+       public function __call( $method, $args ) {
+               return call_user_func_array( array( $this->selenium, $method ), $args );
        }
 
-       public function assertSeleniumAttributeEquals($attribute, $value)
-       {
-               $attr = $this->getAttribute($attribute);
-               $this->assertEquals($attr, $value);
+       public function assertSeleniumAttributeEquals( $attribute, $value ) {
+               $attr = $this->getAttribute( $attribute );
+               $this->assertEquals( $attr, $value );
        }
 
-       public function assertSeleniumHTMLContains($element, $text)
-       {
-               $innerHTML = $this->getText($element);
-               //or assertContains
-               $this->assertRegExp("/$text/", $innerHTML );
+       public function assertSeleniumHTMLContains( $element, $text ) {
+               $innerHTML = $this->getText( $element );
+               // or assertContains
+               $this->assertRegExp( "/$text/", $innerHTML );
        }
 
-}
-
-?>
+}
\ No newline at end of file
index b554796..8c14210 100644 (file)
@@ -1,28 +1,28 @@
 <?php
-if (!defined('MEDIAWIKI') || !defined('SELENIUMTEST')) {
+if ( !defined( 'MEDIAWIKI' ) || !defined( 'SELENIUMTEST' ) ) {
        echo "This script cannot be run standalone";
-       exit(1);
+       exit( 1 );
 }
 
-class SeleniumTestConsoleLogger
-{
-       public function __construct()
-       {
+class SeleniumTestConsoleLogger {
+       public function __construct() {
                // Prepare testsuite for immediate output
-               @ini_set('zlib.output_compression', 0);
-               @ini_set('implicit_flush', 1);
-               for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
-               ob_implicit_flush(1);
-               
+               @ini_set( 'zlib.output_compression', 0 );
+               @ini_set( 'implicit_flush', 1 );
+               for ( $i = 0; $i < ob_get_level(); $i++ ) {
+                       ob_end_flush();
+               }
+               ob_implicit_flush( 1 );
        }
 
-       public function write($message, $mode = false)
-       {
-               $out .= '';
-               //if ($mode == MW_TESTLOGGER_RESULT_OK) $out .= '<font color="green">';
-               $out .=  htmlentities($message);
-               //if ($mode == MW_TESTLOGGER_RESULT_OK) $out .= '</font>';
-               if ($mode != MW_TESTLOGGER_CONTINUE_LINE) $out .= "\n";
+       public function write( $message, $mode = false ) {
+               $out = '';
+               //if ( $mode == MW_TESTLOGGER_RESULT_OK ) $out .= '<font color="green">';
+               $out .= htmlentities( $message );
+               //if ( $mode == MW_TESTLOGGER_RESULT_OK ) $out .= '</font>';
+               if ( $mode != MW_TESTLOGGER_CONTINUE_LINE ) {
+                       $out .= "\n";
+               }
 
                echo $out;
        }
index 354e586..084a04b 100644 (file)
@@ -1,42 +1,45 @@
 <?php
-if (!defined('MEDIAWIKI') || !defined('SELENIUMTEST')) {
+if ( !defined( 'MEDIAWIKI' ) || !defined( 'SELENIUMTEST' ) ) {
        echo "This script cannot be run standalone";
-       exit(1);
+       exit( 1 );
 }
 
-class SeleniumTestHTMLLogger
-{
-       public function __construct()
-       {
+class SeleniumTestHTMLLogger {
+       public function __construct() {
                // Prepare testsuite for immediate output
-               @ini_set('zlib.output_compression', 0);
-               @ini_set('implicit_flush', 1);
-               for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
-               ob_implicit_flush(1);
-               
+               @ini_set( 'zlib.output_compression', 0 );
+               @ini_set( 'implicit_flush', 1 );
+               for ( $i = 0; $i < ob_get_level(); $i++ ) {
+                       ob_end_flush();
+               }
+               ob_implicit_flush( 1 );
+
                // Output some style information
                echo '<style>
                pre {
-                overflow-x: auto; /* Use horizontal scroller if needed; for Firefox 2, not needed in Firefox 3 */
-                white-space: pre-wrap; /* css-3 */
-                white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */
-                white-space: -pre-wrap; /* Opera 4-6 */
-                white-space: -o-pre-wrap; /* Opera 7 */
-                /* width: 99%; */
-                word-wrap: break-word; /* Internet Explorer 5.5+ */
+                       overflow-x: auto; /* Use horizontal scroller if needed; for Firefox 2, not needed in Firefox 3 */
+                       white-space: pre-wrap; /* css-3 */
+                       white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */
+                       white-space: -pre-wrap; /* Opera 4-6 */
+                       white-space: -o-pre-wrap; /* Opera 7 */
+                       /* width: 99%; */
+                       word-wrap: break-word; /* Internet Explorer 5.5+ */
                }
                </style>';
-               
-               
        }
 
-       public function write($message, $mode = false)
-       {
-               $out .= '';
-               if ($mode == MW_TESTLOGGER_RESULT_OK) $out .= '<font color="green">';
-               $out .=  htmlentities($message);
-               if ($mode == MW_TESTLOGGER_RESULT_OK) $out .= '</font>';
-               if ($mode != MW_TESTLOGGER_CONTINUE_LINE) $out .= '<br/>';
+       public function write( $message, $mode = false ) {
+               $out = '';
+               if ( $mode == MW_TESTLOGGER_RESULT_OK ) {
+                       $out .= '<font color="green">';
+               }
+               $out .= htmlentities( $message );
+               if ( $mode == MW_TESTLOGGER_RESULT_OK ) {
+                       $out .= '</font>';
+               }
+               if ( $mode != MW_TESTLOGGER_CONTINUE_LINE ) {
+                       $out .= '<br />';
+               }
 
                echo $out;
        }
index 266eb3b..2dfb564 100644 (file)
@@ -1,74 +1,69 @@
 <?php
-if (!defined('MEDIAWIKI') || !defined('SELENIUMTEST')) {
+if ( !defined( 'MEDIAWIKI' ) || !defined( 'SELENIUMTEST' ) ) {
        echo "This script cannot be run standalone";
-       exit(1);
+       exit( 1 );
 }
 
-class SeleniumTestListener implements PHPUnit_Framework_TestListener
-{
+class SeleniumTestListener implements PHPUnit_Framework_TestListener {
        private $logger;
        private $tests_ok = 0;
        private $tests_failed = 0;
 
-       public function __construct($loggerInstance)
-       {
+       public function __construct( $loggerInstance ) {
                $this->logger = $loggerInstance;
        }
 
-       public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
-       {
-               $this->logger->write("Error: ".$e->getMessage());
+       public function addError( PHPUnit_Framework_Test $test, Exception $e, $time ) {
+               $this->logger->write( 'Error: ' . $e->getMessage() );
                $this->tests_failed++;
        }
 
-       public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
+       public function addFailure( PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time )
        {
-               $this->logger->write("Failed: ".$e->getMessage());
+               $this->logger->write( 'Failed: ' . $e->getMessage() );
                $this->tests_failed++;
-
        }
 
-       public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
+       public function addIncompleteTest( PHPUnit_Framework_Test $test, Exception $e, $time )
        {
-               $this->logger->write("Incomplete.");
+               $this->logger->write( 'Incomplete.' );
                $this->tests_failed++;
        }
 
-       public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
+       public function addSkippedTest( PHPUnit_Framework_Test $test, Exception $e, $time )
        {
-               $this->logger->write("Skipped.");
+               $this->logger->write( 'Skipped.' );
                $this->tests_failed++;
        }
 
-       public function startTest(PHPUnit_Framework_Test $test)
-       {
-               $this->logger->write("Testing ".$test->getName()." ... ", MW_TESTLOGGER_CONTINUE_LINE);
+       public function startTest( PHPUnit_Framework_Test $test ) {
+               $this->logger->write(
+                       'Testing ' . $test->getName() . ' ... ',
+                       MW_TESTLOGGER_CONTINUE_LINE
+               );
        }
 
-       public function endTest(PHPUnit_Framework_Test $test, $time)
-       {
-               if (!$test->hasFailed())
-               {
-                       $this->logger->write("OK", MW_TESTLOGGER_RESULT_OK);
+       public function endTest( PHPUnit_Framework_Test $test, $time ) {
+               if ( !$test->hasFailed() ) {
+                       $this->logger->write( 'OK', MW_TESTLOGGER_RESULT_OK );
                        $this->tests_ok++;
                }
        }
 
-       public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
-       {
-               $this->logger->write("Testsuite ".$suite->getName()." started.");
+       public function startTestSuite( PHPUnit_Framework_TestSuite $suite ) {
+               $this->logger->write( 'Testsuite ' . $suite->getName() . ' started.' );
                $this->tests_ok = 0;
        }
 
-       public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
-       {
-               $this->logger->write("Testsuite ".$suite->getName()." ended. OK: ".$this->tests_ok." Failed: ".$this->tests_failed);
-
+       public function endTestSuite( PHPUnit_Framework_TestSuite $suite ) {
+               $this->logger->write(
+                       'Testsuite ' . $suite->getName() . ' ended. OK: ' .
+                       $this->tests_ok . ' Failed: ' . $this->tests_failed
+               );
        }
 
-       public function statusMessage($message)
-       {
-               $this->logger->write($message);
+       public function statusMessage( $message ) {
+               $this->logger->write( $message );
        }
 }
 
index 112db74..a248ad6 100644 (file)
@@ -1,40 +1,34 @@
 <?php
-if (!defined('MEDIAWIKI') || !defined('SELENIUMTEST')) {
+if ( !defined( 'MEDIAWIKI' ) || !defined( 'SELENIUMTEST' ) ) {
        echo "This script cannot be run standalone";
-       exit(1);
+       exit( 1 );
 }
 
 // Do not add line break after test output
-define('MW_TESTLOGGER_CONTINUE_LINE', 1);
-define('MW_TESTLOGGER_RESULT_OK', 2);
-define('MW_TESTLOGGER_RESULT_ERROR', 3);
+define( 'MW_TESTLOGGER_CONTINUE_LINE', 1 );
+define( 'MW_TESTLOGGER_RESULT_OK', 2 );
+define( 'MW_TESTLOGGER_RESULT_ERROR', 3 );
 
-class SeleniumTestSuite extends PHPUnit_Framework_TestSuite
-{
+class SeleniumTestSuite extends PHPUnit_Framework_TestSuite {
        private $selenium;
 
-       public function setUp()
-       {
-
+       public function setUp() {
                $this->selenium = Selenium::getInstance();
                $this->selenium->start();
                $this->login();
-               //$this->loadPage('Testpage', 'edit');
+               //$this->loadPage( 'Testpage', 'edit' );
        }
 
-       public function tearDown()
-       {
+       public function tearDown() {
                $this->selenium->stop();
        }
 
-       public function login()
-       {
+       public function login() {
                $this->selenium->login();
        }
 
-       public function loadPage($title, $action)
-       {
-               $this->selenium->loadPage($title, $action);
+       public function loadPage( $title, $action ) {
+               $this->selenium->loadPage( $title, $action );
        }
 }