From: Mark A. Hershberger Date: Tue, 5 Oct 2010 03:51:49 +0000 (+0000) Subject: (second commit to get all files.) X-Git-Tag: 1.31.0-rc.0~34617 X-Git-Url: http://git.cyclocoop.org/%40spipnet%40?a=commitdiff_plain;h=a828027890ada986f83b420c41a659100d472331;p=lhc%2Fweb%2Fwiklou.git (second commit to get all files.) = BacklinkCache.php = * BacklinkCache class ** Set a few otherwise unset varables ($wgContLang & $wgMemc in BacklinkCache) = testHelpers.inc = * TectRecorder class ** TestRecorder::record() accept and use a recorder object ** change TestFileIterator::setParser use a MediaWikiParserTest instead of ParserTest = parserTest.inc = * ParserTest class ** Make $ParserTest->regex and $ParsaerTest->savedGlobals member variables available to stop warnings. ** Force ParserTest::$showProgress and $showFailure to false ** Set ParserTest::$uploadDir on time ** Move ParserTest::chomp() and addArticle() to bootstrap for MediaWikiTestSetup. ** Update ParserTest::runTest so that Success and Failure are reported via reporter->showsTestResult() or ParserTestSuiteBackend::show*() as needed. ** Set $ParserTest->uploadDir with setupUploadDir() ** Change ParserTest->setupGlobals() so that $wgDBprefix doesn't get to set to the “parsertest_” bits. ** Sprinkle $this->teardownGlobals() at exit points in ParserTest->teardownDatabase() = bootstrap.php = * MediaWikiTestSetup class ** Make member variables MediaWikiTestSetup::$suite, MediaW* Make member variables MediaWikiTestSetup::$suite, MediaWikiTestSetup::$regex, MediaWikiTestSetup::$runDisabled available. * Setup a constructor MediaWikiTestSetup that accepts an optional PHPUnit_Framework_TestSuite so they can use PHPUnit. * Change MediaWikiParserTest so that it is derived from MediaWikiTestSetup instead of PHPUnit_Framework_TestSuite * Make MediaWikiParserTest create a PHPUnit_Framework_TestSuite for the parser tests and pass it to the new parent (MediaWikiTestSetup) as the PHPUnit testsuite. * Replace MediaWikiParserTest->run() with MediaWikiParserTest::suite() so that the tests can be loaded into a suite and then run with PHPUnit's test runner. = ParserHelpers.php = * ParserUnitTest class ** Force run() $backend to use ParserTestSuiteBackend instead of trying to get the backend from the suite member. ** Use ParserTest::runTest() instead of ParserikiTestSetup::$regex, MediaWikiTestSetup::$runDisabled available. ** Setup a constructor MediaWikiTestSetup that accepts an optional PHPUnit_Framework_TestSuite so they can use PHPUnit. ** Change MediaWikiParserTest so that it is derived from MediaWikiTestSetup instead of PHPUnit_Framework_TestSuite ** Make MediaWikiParserTest create a PHPUnit_Framework_TestSuite for the parser tests and pass it to the new parent (MediaWikiTestSetup) as the PHPUnit testsuite. ** Replace MediaWikiParserTest->run() with MediaWikiParserTest::suite() so that the tests can be loaded into a suite and then run with PHPUnit's test runner. = ParserHelpers.php = * ParserUnitTest class ** Force run() $backend to use ParserTestSuiteBackend instead of trying to get the backend from the suite member. ** Use ParserTest::runTest() instead of ParserTestSuiteBackend::runTest() * ParserTestSuiteBackend class ** extends PHPUnit_FrameWork_TestSuite instead of ParserTest ** Add member variables $recorder, $term, and $usePHPUnit ** Add a constructor that determines if PHPUnit is usewd. ** Add a method showTestResult() that can be used to show success or failure ** Change showSucess and showFailure() to be static and use identical arguments and only use PHPUnit_Framework_Assert::assertEquals when PHPUnit is in use. = SearchEngineTest.php = ** Fix path in require to bootstrap.php --- diff --git a/includes/BacklinkCache.php b/includes/BacklinkCache.php index b23fd56bd5..cdf82f9022 100644 --- a/includes/BacklinkCache.php +++ b/includes/BacklinkCache.php @@ -208,6 +208,7 @@ class BacklinkCache { // Try memcached global $wgMemc; + global $wgContLang; $memcKey = wfMemcKey( 'backlinks', @@ -216,6 +217,9 @@ class BacklinkCache { $batchSize ); + if ( $wgContLang === null ) $wgContLang = new Language; + if ( $wgMemc === null ) $wgMemc =& wfGetMainCache(); + $memcValue = $wgMemc->get( $memcKey ); if ( is_array( $memcValue ) ) { diff --git a/includes/db/Database.php b/includes/db/Database.php index e249ccb2a0..b009906e21 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -167,7 +167,7 @@ interface DatabaseType { /** * Returns a wikitext link to the DB's website, e.g., - * return "[http://www.mysql.com/ MySQL]"; + * return "[http://www.mysql.com/ MySQL]"; * Should at least contain plain text, if for some reason * your database has no website. * @@ -419,13 +419,13 @@ abstract class DatabaseBase implements DatabaseType { * Set a flag for this connection * * @param $flag Integer: DBO_* constants from Defines.php: - * - DBO_DEBUG: output some debug info (same as debug()) - * - DBO_NOBUFFER: don't buffer results (inverse of bufferResults()) - * - DBO_IGNORE: ignore errors (same as ignoreErrors()) - * - DBO_TRX: automatically start transactions - * - DBO_DEFAULT: automatically sets DBO_TRX if not in command line mode - * and removes it in command line mode - * - DBO_PERSISTENT: use persistant database connection + * - DBO_DEBUG: output some debug info (same as debug()) + * - DBO_NOBUFFER: don't buffer results (inverse of bufferResults()) + * - DBO_IGNORE: ignore errors (same as ignoreErrors()) + * - DBO_TRX: automatically start transactions + * - DBO_DEFAULT: automatically sets DBO_TRX if not in command line mode + * and removes it in command line mode + * - DBO_PERSISTENT: use persistant database connection */ function setFlag( $flag ) { $this->mFlags |= $flag; @@ -565,7 +565,7 @@ abstract class DatabaseBase implements DatabaseType { } } - protected function connectionErrorHandler( $errno, $errstr ) { + protected function connectionErrorHandler( $errno, $errstr ) { $this->mPHPError = $errstr; } @@ -612,13 +612,13 @@ abstract class DatabaseBase implements DatabaseType { /** * Usually aborts on failure. If errors are explicitly ignored, returns success. * - * @param $sql String: SQL query - * @param $fname String: Name of the calling function, for profiling/SHOW PROCESSLIST - * comment (you can use __METHOD__ or add some extra info) - * @param $tempIgnore Boolean: Whether to avoid throwing an exception on errors... - * maybe best to catch the exception instead? + * @param $sql String: SQL query + * @param $fname String: Name of the calling function, for profiling/SHOW PROCESSLIST + * comment (you can use __METHOD__ or add some extra info) + * @param $tempIgnore Boolean: Whether to avoid throwing an exception on errors... + * maybe best to catch the exception instead? * @return true for a successful write query, ResultWrapper object for a successful read query, - * or false on failure if $tempIgnore set + * or false on failure if $tempIgnore set * @throws DBQueryError Thrown when the database returns an error of any kind */ public function query( $sql, $fname = '', $tempIgnore = false ) { @@ -684,7 +684,7 @@ abstract class DatabaseBase implements DatabaseType { $cnt++; $sqlx = substr( $commentedSql, 0, 500 ); - $sqlx = strtr( $sqlx, "\t\n", ' ' ); + $sqlx = strtr( $sqlx, "\t\n", ' ' ); if ( $isMaster ) { wfDebug( "Query $cnt (master): $sqlx\n" ); @@ -709,7 +709,7 @@ abstract class DatabaseBase implements DatabaseType { if ( $this->ping() ) { wfDebug( "Reconnected\n" ); $sqlx = substr( $commentedSql, 0, 500 ); - $sqlx = strtr( $sqlx, "\t\n", ' ' ); + $sqlx = strtr( $sqlx, "\t\n", ' ' ); global $wgRequestTime; $elapsed = round( microtime( true ) - $wgRequestTime, 3 ); wfLogDBError( "Connection lost and reconnected after {$elapsed}s, query: $sqlx\n" ); @@ -762,7 +762,7 @@ abstract class DatabaseBase implements DatabaseType { * ? = scalar value, quoted as necessary * ! = raw SQL bit (a function for instance) * & = filename; reads the file and inserts as a blob - * (we don't use this though...) + * (we don't use this though...) */ function prepare( $sql, $func = 'DatabaseBase::prepare' ) { /* MySQL doesn't support prepared statements (yet), so just @@ -862,7 +862,7 @@ abstract class DatabaseBase implements DatabaseType { * @param $res Mixed: A SQL result */ function freeResult( $res ) { - # Stub. Might not really need to be overridden, since results should + # Stub. Might not really need to be overridden, since results should # be freed by PHP when the variable goes out of scope anyway. } @@ -916,7 +916,7 @@ abstract class DatabaseBase implements DatabaseType { * @private * * @param $options Array: associative array of options to be turned into - * an SQL query, valid keys are listed in the function. + * an SQL query, valid keys are listed in the function. * @return Array */ function makeSelectOptions( $options ) { @@ -1007,13 +1007,13 @@ abstract class DatabaseBase implements DatabaseType { * SELECT wrapper * * @param $table Mixed: Array or string, table name(s) (prefix auto-added) - * @param $vars Mixed: Array or string, field name(s) to be retrieved + * @param $vars Mixed: Array or string, field name(s) to be retrieved * @param $conds Mixed: Array or string, condition(s) for WHERE * @param $fname String: Calling function name (use __METHOD__) for logs/profiling * @param $options Array: Associative array of options (e.g. array('GROUP BY' => 'page_title')), - * see DatabaseBase::makeSelectOptions code for list of supported stuff + * see DatabaseBase::makeSelectOptions code for list of supported stuff * @param $join_conds Array: Associative array of table join conditions (optional) - * (e.g. array( 'page' => array('LEFT JOIN','page_latest=rev_id') ) + * (e.g. array( 'page' => array('LEFT JOIN','page_latest=rev_id') ) * @return mixed Database result resource (feed to DatabaseBase::fetchObject or whatever), or false on failure */ function select( $table, $vars, $conds = '', $fname = 'DatabaseBase::select', $options = array(), $join_conds = array() ) { @@ -1026,13 +1026,13 @@ abstract class DatabaseBase implements DatabaseType { * SELECT wrapper * * @param $table Mixed: Array or string, table name(s) (prefix auto-added) - * @param $vars Mixed: Array or string, field name(s) to be retrieved + * @param $vars Mixed: Array or string, field name(s) to be retrieved * @param $conds Mixed: Array or string, condition(s) for WHERE * @param $fname String: Calling function name (use __METHOD__) for logs/profiling * @param $options Array: Associative array of options (e.g. array('GROUP BY' => 'page_title')), - * see DatabaseBase::makeSelectOptions code for list of supported stuff + * see DatabaseBase::makeSelectOptions code for list of supported stuff * @param $join_conds Array: Associative array of table join conditions (optional) - * (e.g. array( 'page' => array('LEFT JOIN','page_latest=rev_id') ) + * (e.g. array( 'page' => array('LEFT JOIN','page_latest=rev_id') ) * @return string, the SQL text */ function selectSQLText( $table, $vars, $conds = '', $fname = 'DatabaseBase::select', $options = array(), $join_conds = array() ) { @@ -1090,10 +1090,10 @@ abstract class DatabaseBase implements DatabaseType { * @param $table String: table name * @param $vars String: the selected variables * @param $conds Array: a condition map, terms are ANDed together. - * Items with numeric keys are taken to be literal conditions + * Items with numeric keys are taken to be literal conditions * Takes an array of selected variables, and a condition map, which is ANDed * e.g: selectRow( "page", array( "page_id" ), array( "page_namespace" => - * NS_MAIN, "page_title" => "Astronomy" ) ) would return an object where + * NS_MAIN, "page_title" => "Astronomy" ) ) would return an object where * $obj- >page_id is the ID of the Astronomy article * @param $fname String: Calling function name * @param $options Array @@ -1350,9 +1350,9 @@ abstract class DatabaseBase implements DatabaseType { * @param $values Array: An array of values to SET * @param $conds Array: An array of conditions (WHERE). Use '*' to update all rows. * @param $fname String: The Class::Function calling this function - * (for the log) + * (for the log) * @param $options Array: An array of UPDATE options, can be one or - * more of IGNORE, LOW_PRIORITY + * more of IGNORE, LOW_PRIORITY * @return Boolean */ function update( $table, $values, $conds, $fname = 'DatabaseBase::update', $options = array() ) { @@ -1370,11 +1370,11 @@ abstract class DatabaseBase implements DatabaseType { /** * Makes an encoded list of strings from an array * $mode: - * LIST_COMMA - comma separated, no field names - * LIST_AND - ANDed WHERE clause (without the WHERE) - * LIST_OR - ORed WHERE clause (without the WHERE) - * LIST_SET - comma separated with field names, like a SET clause - * LIST_NAMES - comma separated field names + * LIST_COMMA - comma separated, no field names + * LIST_AND - ANDed WHERE clause (without the WHERE) + * LIST_OR - ORed WHERE clause (without the WHERE) + * LIST_SET - comma separated with field names, like a SET clause + * LIST_NAMES - comma separated field names */ function makeList( $a, $mode = LIST_COMMA ) { if ( !is_array( $a ) ) { @@ -1482,7 +1482,7 @@ abstract class DatabaseBase implements DatabaseType { * @return bool Success or failure */ function selectDB( $db ) { - # Stub. Shouldn't cause serious problems if it's not overridden, but + # Stub. Shouldn't cause serious problems if it's not overridden, but # if your database engine supports a concept similar to MySQL's # databases you may as well. return true; @@ -1562,7 +1562,7 @@ abstract class DatabaseBase implements DatabaseType { && is_array( $wgSharedTables ) && in_array( $table, $wgSharedTables ) ) { # A shared table is selected $database = $wgSharedDB; - $prefix = isset( $wgSharedPrefix ) ? $wgSharedPrefix : $prefix; + $prefix = isset( $wgSharedPrefix ) ? $wgSharedPrefix : $prefix; } # Quote the $database and $table and apply the prefix if not quoted. @@ -1584,7 +1584,7 @@ abstract class DatabaseBase implements DatabaseType { * Example: * extract($dbr->tableNames('user','watchlist')); * $sql = "SELECT wl_namespace,wl_title FROM $watchlist,$user - * WHERE wl_user=user_id AND wl_user=$nameWithQuotes"; + * WHERE wl_user=user_id AND wl_user=$nameWithQuotes"; */ public function tableNames() { $inArray = func_get_args(); @@ -1604,7 +1604,7 @@ abstract class DatabaseBase implements DatabaseType { * Example: * list( $user, $watchlist ) = $dbr->tableNamesN('user','watchlist'); * $sql = "SELECT wl_namespace,wl_title FROM $watchlist,$user - * WHERE wl_user=user_id AND wl_user=$nameWithQuotes"; + * WHERE wl_user=user_id AND wl_user=$nameWithQuotes"; */ public function tableNamesN() { $inArray = func_get_args(); @@ -1776,10 +1776,10 @@ abstract class DatabaseBase implements DatabaseType { } /** - * USE INDEX clause. Unlikely to be useful for anything but MySQL. This + * USE INDEX clause. Unlikely to be useful for anything but MySQL. This * is only needed because a) MySQL must be as efficient as possible due to * its use on Wikipedia, and b) MySQL 4.0 is kind of dumb sometimes about - * which index to pick. Anyway, other databases might have different + * which index to pick. Anyway, other databases might have different * indexes on a given table. So don't bother overriding this unless you're * MySQL. */ @@ -1933,7 +1933,7 @@ abstract class DatabaseBase implements DatabaseType { list( $startOpts, $useIndex, $tailOpts ) = $this->makeSelectOptions( $selectOptions ); if ( is_array( $srcTable ) ) { - $srcTable = implode( ',', array_map( array( &$this, 'tableName' ), $srcTable ) ); + $srcTable = implode( ',', array_map( array( &$this, 'tableName' ), $srcTable ) ); } else { $srcTable = $this->tableName( $srcTable ); } @@ -1959,7 +1959,7 @@ abstract class DatabaseBase implements DatabaseType { * If the result of the query is not ordered, then the rows to be returned * are theoretically arbitrary. * - * $sql is expected to be a SELECT, if that makes a difference. For + * $sql is expected to be a SELECT, if that makes a difference. For * UPDATE, limitResultForUpdate should be used. * * The version provided by default works in MySQL and SQLite. It will very @@ -2006,7 +2006,7 @@ abstract class DatabaseBase implements DatabaseType { } /** - * Returns an SQL expression for a simple conditional. This doesn't need + * Returns an SQL expression for a simple conditional. This doesn't need * to be overridden unless CASE isn't supported in your DBMS. * * @param $cond String: SQL expression which will result in a boolean value @@ -2063,7 +2063,7 @@ abstract class DatabaseBase implements DatabaseType { * will be rolled back and the callback function will be called again. * * Usage: - * $dbw->deadlockLoop( callback, ... ); + * $dbw->deadlockLoop( callback, ... ); * * Extra arguments are passed through to the specified callback function. * @@ -2312,7 +2312,7 @@ abstract class DatabaseBase implements DatabaseType { * @return bool Success or failure */ function ping() { - # Stub. Not essential to override. + # Stub. Not essential to override. return true; } @@ -2355,9 +2355,9 @@ abstract class DatabaseBase implements DatabaseType { } /** - * Override database's default connection timeout. May be useful for very + * Override database's default connection timeout. May be useful for very * long batch queries such as full-wiki dumps, where a single query reads - * out over hours or days. May or may not be necessary for non-MySQL + * out over hours or days. May or may not be necessary for non-MySQL * databases. For most purposes, leaving it as a no-op should be fine. * * @param $timeout Integer in seconds @@ -2371,7 +2371,7 @@ abstract class DatabaseBase implements DatabaseType { * @param $lineCallback Callback: Optional function called before reading each line * @param $resultCallback Callback: Optional function called for each MySQL result * @param $fname String: Calling function name or false if name should be generated dynamically - * using $filename + * using $filename */ function sourceFile( $filename, $lineCallback = false, $resultCallback = false, $fname = false ) { $fp = fopen( $filename, 'r' ); @@ -2906,7 +2906,7 @@ EOT; $mainpage = 'Main Page'; if ( $wgLang instanceof Language ) { - $mainpage = htmlspecialchars( $wgLang->getMessage( 'mainpage' ) ); + $mainpage = htmlspecialchars( $wgLang->getMessage( 'mainpage' ) ); } if ( $wgTitle ) { @@ -2937,7 +2937,7 @@ class DBQueryError extends DBError { public $error, $errno, $sql, $fname; function __construct( DatabaseBase &$db, $error, $errno, $sql, $fname ) { - $message = "A database error has occurred. Did you forget to run maintenance/update.php after upgrading? See: http://www.mediawiki.org/wiki/Manual:Upgrading#Run_the_update_script\n" . + $message = "A database error has occurred. Did you forget to run maintenance/update.php after upgrading? See: http://www.mediawiki.org/wiki/Manual:Upgrading#Run_the_update_script\n" . "Query: $sql\n" . "Function: $fname\n" . "Error: $errno $error\n"; @@ -3118,9 +3118,9 @@ class ResultWrapper implements Iterator { * doesn't go anywhere near an actual database. */ class FakeResultWrapper extends ResultWrapper { - var $result = array(); - var $db = null; // And it's going to stay that way :D - var $pos = 0; + var $result = array(); + var $db = null; // And it's going to stay that way :D + var $pos = 0; var $currentRow = null; function __construct( $array ) { diff --git a/includes/db/LoadBalancer.php b/includes/db/LoadBalancer.php index 0040fe9e15..44f860458f 100644 --- a/includes/db/LoadBalancer.php +++ b/includes/db/LoadBalancer.php @@ -23,10 +23,10 @@ class LoadBalancer { /** * @param $params Array with keys: - * servers Required. Array of server info structures. - * failFunction Deprecated, use exceptions instead. - * masterWaitTimeout Replication lag wait timeout - * loadMonitor Name of a class used to fetch server lag and load. + * servers Required. Array of server info structures. + * failFunction Deprecated, use exceptions instead. + * masterWaitTimeout Replication lag wait timeout + * loadMonitor Name of a class used to fetch server lag and load. */ function __construct( $params ) { @@ -57,7 +57,7 @@ class LoadBalancer { $this->mLaggedSlaveMode = false; $this->mErrorConnection = false; $this->mAllowLag = false; - $this->mLoadMonitorClass = isset( $params['loadMonitor'] ) + $this->mLoadMonitorClass = isset( $params['loadMonitor'] ) ? $params['loadMonitor'] : 'LoadMonitor_MySQL'; foreach( $params['servers'] as $i => $server ) { @@ -230,7 +230,7 @@ class LoadBalancer { $i = $this->pickRandom( $currentLoads ); } else { $i = $this->getRandomNonLagged( $currentLoads, $wiki ); - if ( $i === false && count( $currentLoads ) != 0 ) { + if ( $i === false && count( $currentLoads ) != 0 ) { # All slaves lagged. Switch to read-only mode $wgReadOnly = wfMsgNoDBForContent( 'readonly_lag' ); $i = $this->pickRandom( $currentLoads ); @@ -240,7 +240,7 @@ class LoadBalancer { if ( $i === false ) { # pickRandom() returned false - # This is permanent and means the configuration or the load monitor + # This is permanent and means the configuration or the load monitor # wants us to return false. wfDebugLog( 'connect', __METHOD__.": pickRandom() returned false\n" ); wfProfileOut( __METHOD__ ); @@ -258,7 +258,7 @@ class LoadBalancer { } // Perform post-connection backoff - $threshold = isset( $this->mServers[$i]['max threads'] ) + $threshold = isset( $this->mServers[$i]['max threads'] ) ? $this->mServers[$i]['max threads'] : false; $backoff = $this->getLoadMonitor()->postConnectionBackoff( $conn, $threshold ); @@ -267,7 +267,7 @@ class LoadBalancer { if ( $wiki !== false ) { $this->reuseConnection( $conn ); } - + if ( $backoff ) { # Post-connection overload, don't use this server for now $totalThreadsConnected += $backoff; @@ -399,11 +399,11 @@ class LoadBalancer { /** * Get a connection by index * This is the main entry point for this class. - * + * * @param $i Integer: server index * @param $groups Array: query groups * @param $wiki String: wiki ID - * + * * @return DatabaseBase */ public function &getConnection( $i, $groups = array(), $wiki = false ) { @@ -481,11 +481,11 @@ class LoadBalancer { wfDebug( __METHOD__.": this connection was not opened as a foreign connection\n" ); /** * This can happen in code like: - * foreach ( $dbs as $db ) { - * $conn = $lb->getConnection( DB_SLAVE, array(), $db ); - * ... - * $lb->reuseConnection( $conn ); - * } + * foreach ( $dbs as $db ) { + * $conn = $lb->getConnection( DB_SLAVE, array(), $db ); + * ... + * $lb->reuseConnection( $conn ); + * } * When a connection to the local DB is opened in this way, reuseConnection() * should be ignored */ @@ -770,7 +770,7 @@ class LoadBalancer { */ function closeAll() { foreach ( $this->mConns as $conns2 ) { - foreach ( $conns2 as $conns3 ) { + foreach ( $conns2 as $conns3 ) { foreach ( $conns3 as $conn ) { $conn->close(); } diff --git a/maintenance/tests/parserTests.php b/maintenance/tests/parserTests.php index a0aabd175f..2b63fbb3fd 100644 --- a/maintenance/tests/parserTests.php +++ b/maintenance/tests/parserTests.php @@ -28,31 +28,31 @@ $optionsWithArgs = array( 'regex', 'seed', 'setversion' ); require_once( dirname( __FILE__ ) . '/../commandLine.inc' ); if ( isset( $options['help'] ) ) { - echo << Run test cases from a custom file instead of parserTests.txt - --record Record tests in database - --compare Compare with recorded results, without updating the database. - --setversion When using --record, set the version string to use (useful - with git-svn so that you can get the exact revision) + --record Record tests in database + --compare Compare with recorded results, without updating the database. + --setversion When using --record, set the version string to use (useful + with git-svn so that you can get the exact revision) --keep-uploads Re-use the same upload directory for each test, don't delete it - --fuzz Do a fuzz test instead of a normal test - --seed Start the fuzz test from the specified seed - --help Show this help message + --fuzz Do a fuzz test instead of a normal test + --seed Start the fuzz test from the specified seed + --help Show this help message --run-disabled run disabled tests - --upload Upload test results to remote wiki (per \$wgParserTestRemote) + --upload Upload test results to remote wiki (per \$wgParserTestRemote) ENDS; - exit( 0 ); + exit( 0 ); } # Cases of weird db corruption were encountered when running tests on earlyish diff --git a/maintenance/tests/phpunit/bootstrap.php b/maintenance/tests/phpunit/bootstrap.php index c278af130f..d593e1af92 100644 --- a/maintenance/tests/phpunit/bootstrap.php +++ b/maintenance/tests/phpunit/bootstrap.php @@ -1,7 +1,7 @@ -suite = $suite; + } + } + + function __call( $func, $args ) { + if ( method_exists( $this->suite, $func ) ) { + return call_user_func_array( array( $tohis->suite, $func ), $args); + } else { + throw new MWException( "Called non-existant $func method on " + . get_class( $this ) ); + } + return false; + } + + /** + * @group utility + */ + function getSuite() { + return $this->suite; + } + + /** + * Remove last character if it is a newline + * @group utility + */ + public function chomp( $s ) { + if ( substr( $s, -1 ) === "\n" ) { + return substr( $s, 0, -1 ); + } + else { + return $s; + } + } + + public function addArticle( $name, $text, $line ) { + global $wgCapitalLinks; + $oldCapitalLinks = $wgCapitalLinks; + $wgCapitalLinks = true; // We only need this from SetupGlobals() See r70917#c8637 + + $title = Title::newFromText( $name ); + + if ( is_null( $title ) ) { + wfDie( "invalid title at line $line\n" ); + } + + $aid = $title->getArticleID( Title::GAID_FOR_UPDATE ); + + if ( $aid != 0 ) { + wfDie( "duplicate article '$name' at line $line\n" ); + } + + $art = new Article( $title ); + $art->insertNewArticle( $text, '', false, false ); + + $wgCapitalLinks = $oldCapitalLinks; + } + + /** + * @group utility + */ + function buildTestDatabase( $tables ) { global $wgDBprefix; $db = wfGetDB( DB_MASTER ); $oldTableNames = array(); foreach ( $tables as $table ) $oldTableNames[$table] = $db->tableName( $table ); - if ( $db->getType() == 'oracle' ) { - $wgDBprefix = 'pt_'; - } else { - $wgDBprefix = 'parsertest_'; - } - - $db->tablePrefix( $wgDBprefix ); if ( $db->isOpen() ) { foreach ( $tables as $tbl ) { diff --git a/maintenance/tests/phpunit/includes/SeleniumConfigurationTest.php b/maintenance/tests/phpunit/includes/SeleniumConfigurationTest.php index 3bb4b7482a..e4daebda2f 100644 --- a/maintenance/tests/phpunit/includes/SeleniumConfigurationTest.php +++ b/maintenance/tests/phpunit/includes/SeleniumConfigurationTest.php @@ -4,29 +4,29 @@ class SeleniumConfigurationTest extends PHPUnit_Framework_TestCase { /* * The file where the test temporarity stores the selenium config. - * This should be cleaned up as part of teardown. + * This should be cleaned up as part of teardown. */ private $tempFileName; - + /* * String containing the a sample selenium settings */ - private $testConfig0 = + private $testConfig0 = ' [SeleniumSettings] -browsers[firefox] = "*firefox" +browsers[firefox] = "*firefox" browsers[iexplorer] = "*iexploreproxy" -browsers[chrome] = "*chrome" -host = "localhost" -port = "foobarr" -wikiUrl = "http://localhost/deployment" -username = "xxxxxxx" -userPassword = "" -testBrowser = "chrome" +browsers[chrome] = "*chrome" +host = "localhost" +port = "foobarr" +wikiUrl = "http://localhost/deployment" +username = "xxxxxxx" +userPassword = "" +testBrowser = "chrome" [SeleniumTests] testSuite[SimpleSeleniumTestSuite] = "maintenance/tests/selenium/SimpleSeleniumTestSuite.php" -testSuite[TestSuiteName] = "testSuitePath" +testSuite[TestSuiteName] = "testSuitePath" '; /* * Array of expected browsers from $testConfig0 @@ -41,28 +41,28 @@ testSuite[TestSuiteName] = "testSuitePath" private $testSettings0 = array( 'host' => 'localhost', 'port' => 'foobarr', - 'wikiUrl' => 'http://localhost/deployment', - 'username' => 'xxxxxxx', - 'userPassword' => '', - 'testBrowser' => 'chrome' + 'wikiUrl' => 'http://localhost/deployment', + 'username' => 'xxxxxxx', + 'userPassword' => '', + 'testBrowser' => 'chrome' ); /* * Array of expected testSuites from $testConfig0 */ private $testSuites0 = array( - 'SimpleSeleniumTestSuite' => 'maintenance/tests/selenium/SimpleSeleniumTestSuite.php', - 'TestSuiteName' => 'testSuitePath' + 'SimpleSeleniumTestSuite' => 'maintenance/tests/selenium/SimpleSeleniumTestSuite.php', + 'TestSuiteName' => 'testSuitePath' ); - - + + /* * Another sample selenium settings file contents */ - private $testConfig1 = + private $testConfig1 = ' [SeleniumSettings] -host = "localhost" -testBrowser = "firefox" +host = "localhost" +testBrowser = "firefox" '; /* * Expected browsers from $testConfig1 @@ -74,23 +74,23 @@ testBrowser = "firefox" private $testSettings1 = array( 'host' => 'localhost', 'port' => null, - 'wikiUrl' => null, - 'username' => null, - 'userPassword' => null, - 'testBrowser' => 'firefox' + 'wikiUrl' => null, + 'username' => null, + 'userPassword' => null, + 'testBrowser' => 'firefox' ); /* * Expected test suites from $testConfig1 */ - private $testSuites1 = null; - - + private $testSuites1 = null; + + public function setUp() { if ( !defined( 'SELENIUMTEST' ) ) { define( 'SELENIUMTEST', true ); } } - + /* * Clean up the temporary file used to store the selenium settings. */ @@ -101,90 +101,90 @@ testBrowser = "firefox" } parent::tearDown(); } - + /** - * @expectedException MWException - * @group SeleniumFramework - */ - public function testErrorOnIncorrectConfigFile() { + * @expectedException MWException + * @group SeleniumFramework + */ + public function testErrorOnIncorrectConfigFile() { $seleniumSettings; $seleniumBrowsers; $seleniumTestSuites; - SeleniumConfig::getSeleniumSettings($seleniumSettings, - $seleniumBrowsers, + SeleniumConfig::getSeleniumSettings($seleniumSettings, + $seleniumBrowsers, $seleniumTestSuites, "Some_fake_settings_file.ini" ); } - + /** - * @expectedException MWException - * @group SeleniumFramework - */ - public function testErrorOnMissingConfigFile() { + * @expectedException MWException + * @group SeleniumFramework + */ + public function testErrorOnMissingConfigFile() { $seleniumSettings; $seleniumBrowsers; $seleniumTestSuites; global $wgSeleniumConfigFile; $wgSeleniumConfigFile = ''; - SeleniumConfig::getSeleniumSettings($seleniumSettings, - $seleniumBrowsers, + SeleniumConfig::getSeleniumSettings($seleniumSettings, + $seleniumBrowsers, $seleniumTestSuites); } - + /** - * @group SeleniumFramework - */ - public function testUsesGlobalVarForConfigFile() { + * @group SeleniumFramework + */ + public function testUsesGlobalVarForConfigFile() { $seleniumSettings; $seleniumBrowsers; $seleniumTestSuites; global $wgSeleniumConfigFile; $this->writeToTempFile( $this->testConfig0 ); $wgSeleniumConfigFile = $this->tempFileName; - SeleniumConfig::getSeleniumSettings($seleniumSettings, - $seleniumBrowsers, + SeleniumConfig::getSeleniumSettings($seleniumSettings, + $seleniumBrowsers, $seleniumTestSuites); $this->assertEquals($seleniumSettings, $this->testSettings0 , 'The selenium settings should have been read from the file defined in $wgSeleniumConfigFile' ); - $this->assertEquals($seleniumBrowsers, $this->testBrowsers0, + $this->assertEquals($seleniumBrowsers, $this->testBrowsers0, 'The available browsers should have been read from the file defined in $wgSeleniumConfigFile' ); - $this->assertEquals($seleniumTestSuites, $this->testSuites0, + $this->assertEquals($seleniumTestSuites, $this->testSuites0, 'The test suites should have been read from the file defined in $wgSeleniumConfigFile' - ); + ); } /** - * @group SeleniumFramework - * @dataProvider sampleConfigs - */ - public function testgetSeleniumSettings($sampleConfig, $expectedSettings, $expectedBrowsers, $expectedSuites ) { + * @group SeleniumFramework + * @dataProvider sampleConfigs + */ + public function testgetSeleniumSettings($sampleConfig, $expectedSettings, $expectedBrowsers, $expectedSuites ) { $this->writeToTempFile( $sampleConfig ); $seleniumSettings; $seleniumBrowsers; $seleniumTestSuites; - SeleniumConfig::getSeleniumSettings($seleniumSettings, - $seleniumBrowsers, + SeleniumConfig::getSeleniumSettings($seleniumSettings, + $seleniumBrowsers, $seleniumTestSuites, $this->tempFileName ); - - $this->assertEquals($seleniumSettings, $expectedSettings, + + $this->assertEquals($seleniumSettings, $expectedSettings, "The selenium settings for the following test configuration was not retrieved correctly" . $sampleConfig ); - $this->assertEquals($seleniumBrowsers, $expectedBrowsers, + $this->assertEquals($seleniumBrowsers, $expectedBrowsers, "The available browsers for the following test configuration was not retrieved correctly" . $sampleConfig ); - $this->assertEquals($seleniumTestSuites, $expectedSuites, + $this->assertEquals($seleniumTestSuites, $expectedSuites, "The test suites for the following test configuration was not retrieved correctly" . $sampleConfig ); - - + + } - + /* * create a temp file and write text to it. * @param $testToWrite the text to write to the temp file @@ -195,13 +195,13 @@ testBrowser = "firefox" fwrite($tempFile , $textToWrite); fclose($tempFile); } - + /* * Returns an array containing: - * The contents of the selenium cingiguration ini file - * The expected selenium configuration array that getSeleniumSettings should return - * The expected available browsers array that getSeleniumSettings should return - * The expected test suites arrya that getSeleniumSettings should return + * The contents of the selenium cingiguration ini file + * The expected selenium configuration array that getSeleniumSettings should return + * The expected available browsers array that getSeleniumSettings should return + * The expected test suites arrya that getSeleniumSettings should return */ public function sampleConfigs() { return array( @@ -209,6 +209,6 @@ testBrowser = "firefox" array($this->testConfig1, $this->testSettings1, $this->testBrowsers1, $this->testSuites1 ) ); } - + } diff --git a/maintenance/tests/phpunit/includes/api/ApiSetup.php b/maintenance/tests/phpunit/includes/api/ApiSetup.php index 54f2fa5953..10f3c37818 100644 --- a/maintenance/tests/phpunit/includes/api/ApiSetup.php +++ b/maintenance/tests/phpunit/includes/api/ApiSetup.php @@ -36,8 +36,9 @@ abstract class ApiTestSetup extends PHPUnit_Framework_TestCase { self::$user = new UserWrapper( 'Useruser', 'Passpass' ); self::$sysopUser = new UserWrapper( 'Useruser1', 'Passpass1', 'sysop' ); } - + $GLOBALS['wgUser'] = self::$sysopUser->user; + } function tearDown() { @@ -51,9 +52,10 @@ class UserWrapper { public function __construct( $userName, $password, $group = '' ) { $this->userName = $userName; - $this->password = $password; + $this->password = $password; + + $this->user = User::newFromName( $this->userName ); - $this->user = User::newFromName( $this->userName ); if ( !$this->user->getID() ) { $this->user = User::createNew( $this->userName, array( "email" => "test@example.com", @@ -64,6 +66,7 @@ class UserWrapper { if ( $group !== '' ) { $this->user->addGroup( $group ); } + $this->user->saveSettings(); } } diff --git a/maintenance/tests/phpunit/includes/api/ApiTest.php b/maintenance/tests/phpunit/includes/api/ApiTest.php index 47b9005711..fa8f612c9e 100644 --- a/maintenance/tests/phpunit/includes/api/ApiTest.php +++ b/maintenance/tests/phpunit/includes/api/ApiTest.php @@ -32,8 +32,8 @@ class ApiTest extends ApiTestSetup { } /** - * @expectedException UsageException - */ + * @expectedException UsageException + */ function testRequireOnlyOneParameterZero() { $mock = new MockApi(); @@ -43,8 +43,8 @@ class ApiTest extends ApiTestSetup { } /** - * @expectedException UsageException - */ + * @expectedException UsageException + */ function testRequireOnlyOneParameterTrue() { $mock = new MockApi(); @@ -98,7 +98,7 @@ class ApiTest extends ApiTestSetup { "lgpassword" => "bad", ) ); - + $result = $ret[0]; $this->assertNotType( "bool", $result ); @@ -180,6 +180,7 @@ class ApiTest extends ApiTestSetup { libxml_use_internal_errors( true ); $sxe = simplexml_load_string( $req->getContent() ); + $this->assertNotType( "bool", $sxe ); $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) ); $this->assertNotType( "null", $sxe->login[0] ); @@ -200,7 +201,6 @@ class ApiTest extends ApiTestSetup { $serializedCookie = $cj->serializeToHttpRequest( $wgScriptPath, $serverName ); $this->assertNotEquals( '', $serializedCookie ); $this->assertRegexp( '/_session=[^;]*; .*UserID=[0-9]*; .*UserName=' . self::$user->userName . '; .*Token=/', $serializedCookie ); - return $cj; } diff --git a/maintenance/tests/phpunit/includes/api/ApiWatchTest.php b/maintenance/tests/phpunit/includes/api/ApiWatchTest.php index 4a87e89a25..69a1001d66 100644 --- a/maintenance/tests/phpunit/includes/api/ApiWatchTest.php +++ b/maintenance/tests/phpunit/includes/api/ApiWatchTest.php @@ -217,7 +217,7 @@ class ApiWatchTest extends ApiTestSetup { 'action' => 'query', 'list' => 'watchlist' ), $data ); - $this->markTestIncomplete( 'This test needs to verify the deleted article was added to the users watchlist' ); + $this->markTestIncomplete( 'This test needs to verify the deleted article was added to the users watchlist' ); } } diff --git a/maintenance/tests/phpunit/includes/parser/MediaWikiParserTest.php b/maintenance/tests/phpunit/includes/parser/MediaWikiParserTest.php index 4b0c259e8a..05bed16575 100644 --- a/maintenance/tests/phpunit/includes/parser/MediaWikiParserTest.php +++ b/maintenance/tests/phpunit/includes/parser/MediaWikiParserTest.php @@ -1,41 +1,33 @@ backend = new ParserTestSuiteBackend; - parent::__construct(); $this->setName( 'Parser tests' ); } - public function run( PHPUnit_Framework_TestResult $result = null, $filter = false, - array $groups = array(), array $excludeGroups = array(), $processIsolation = false - ) { - global $IP, $wgContLang, $wgMemc; - $wgContLang = Language::factory( 'en' ); - $wgMemc = new FakeMemCachedClient; - $this->backend->setupDatabase(); + public static function suite() { + global $IP; + $tester = new self; $iter = new TestFileIterator( "$IP/maintenance/tests/parser/parserTests.txt" ); - $iter->setParser( $this->backend ); - $this->count = 0; + $iter->setParser( $tester ); + $tester->count = 0; foreach ( $iter as $test ) { - $this->addTest( new ParserUnitTest( $this, $test ) ); - $this->count++; + $tester->suite->addTest( new ParserUnitTest( $tester, $test ) ); + $tester->count++; } - parent::run( $result, $filter, $groups, $excludeGroups, $processIsolation ); - - $this->backend->teardownDatabase(); + return $tester->suite; } public function count() { diff --git a/maintenance/tests/phpunit/includes/parser/ParserHelpers.php b/maintenance/tests/phpunit/includes/parser/ParserHelpers.php index 165b93d9b2..b4c964b93e 100644 --- a/maintenance/tests/phpunit/includes/parser/ParserHelpers.php +++ b/maintenance/tests/phpunit/includes/parser/ParserHelpers.php @@ -17,9 +17,9 @@ class ParserUnitTest extends PHPUnit_Framework_TestCase { $result = new PHPUnit_Framework_TestResult; } - $backend = $this->suite->getBackend(); + $backend = new ParserTestSuiteBackend; $result->startTest( $this ); - + // Support the transition to PHPUnit 3.5 where PHPUnit_Util_Timer is replaced with PHP_Timer if ( class_exists( 'PHP_Timer' ) ) { PHP_Timer::start(); @@ -32,12 +32,9 @@ class ParserUnitTest extends PHPUnit_Framework_TestCase { # Run the test. # On failure, the subclassed backend will throw an exception with # the details. - $r = $backend->runTest( - $this->test['test'], - $this->test['input'], - $this->test['result'], - $this->test['options'], - $this->test['config'] + $pt = new ParserTest; + $r = $pt->runTest( $this->test['test'], $this->test['input'], + $this->test['result'], $this->test['options'], $this->test['config'] ); } catch ( PHPUnit_Framework_AssertionFailedError $e ) { @@ -77,20 +74,43 @@ class ParserUnitTest extends PHPUnit_Framework_TestCase { } -class ParserTestSuiteBackend extends ParserTest { +class ParserTestSuiteBackend extends PHPUnit_FrameWork_TestSuite { + public $recorder; + public $term; + static $usePHPUnit = false; + + function __construct() { + parent::__construct(); + $this->setupRecorder(null); + self::$usePHPUnit = method_exists('PHPUnit_Framework_Assert', 'assertEquals'); + } + function showTesting( $desc ) { } function showRunFile( $path ) { } - function showSuccess( $desc ) { - PHPUnit_Framework_Assert::assertTrue( true, $desc ); + function showTestResult( $desc, $result, $out ) { + if ( $result === $out ) { + return self::showSuccess( $desc, $result, $out ); + } else { + return self::showFailure( $desc, $result, $out ); + } + } + + public static function showSuccess( $desc, $expected, $got ) { + if ( self::$usePHPUnit ) { + PHPUnit_Framework_Assert::assertEquals( $expected, $got, $desc ); + } return true; } - function showFailure( $desc, $expected, $got ) { - PHPUnit_Framework_Assert::assertEquals( $expected, $got, $desc ); + public static function showFailure( $desc, $expected, $got ) { + if ( self::$usePHPUnit ) { + PHPUnit_Framework_Assert::assertEquals( $expected, $got, $desc ); + } + return false; } public function setupRecorder( $options ) { diff --git a/maintenance/tests/phpunit/includes/search/SearchEngineTest.php b/maintenance/tests/phpunit/includes/search/SearchEngineTest.php index 58eaecfed2..9469de0298 100644 --- a/maintenance/tests/phpunit/includes/search/SearchEngineTest.php +++ b/maintenance/tests/phpunit/includes/search/SearchEngineTest.php @@ -1,6 +1,6 @@ pageExists( 'Not_Main_Page' ) ) { + if ( $this->pageExists( 'Not_Main_Page' ) ) { return; - } - $this->insertPage( "Not_Main_Page", "This is not a main page", 0 ); - $this->insertPage( 'Talk:Not_Main_Page', 'This is not a talk page to the main page, see [[smithee]]', 1 ); - $this->insertPage( 'Smithee', 'A smithee is one who smiths. See also [[Alan Smithee]]', 0 ); - $this->insertPage( 'Talk:Smithee', 'This article sucks.', 1 ); - $this->insertPage( 'Unrelated_page', 'Nothing in this page is about the S word.', 0 ); - $this->insertPage( 'Another_page', 'This page also is unrelated.', 0 ); - $this->insertPage( 'Help:Help', 'Help me!', 4 ); - $this->insertPage( 'Thppt', 'Blah blah', 0 ); - $this->insertPage( 'Alan_Smithee', 'yum', 0 ); - $this->insertPage( 'Pages', 'are\'food', 0 ); - $this->insertPage( 'HalfOneUp', 'AZ', 0 ); - $this->insertPage( 'FullOneUp', 'AZ', 0 ); - $this->insertPage( 'HalfTwoLow', 'az', 0 ); - $this->insertPage( 'FullTwoLow', 'az', 0 ); - $this->insertPage( 'HalfNumbers', '1234567890', 0 ); - $this->insertPage( 'FullNumbers', '1234567890', 0 ); - $this->insertPage( 'DomainName', 'example.com', 0 ); + } + $this->insertPage( "Not_Main_Page", "This is not a main page", 0 ); + $this->insertPage( 'Talk:Not_Main_Page', 'This is not a talk page to the main page, see [[smithee]]', 1 ); + $this->insertPage( 'Smithee', 'A smithee is one who smiths. See also [[Alan Smithee]]', 0 ); + $this->insertPage( 'Talk:Smithee', 'This article sucks.', 1 ); + $this->insertPage( 'Unrelated_page', 'Nothing in this page is about the S word.', 0 ); + $this->insertPage( 'Another_page', 'This page also is unrelated.', 0 ); + $this->insertPage( 'Help:Help', 'Help me!', 4 ); + $this->insertPage( 'Thppt', 'Blah blah', 0 ); + $this->insertPage( 'Alan_Smithee', 'yum', 0 ); + $this->insertPage( 'Pages', 'are\'food', 0 ); + $this->insertPage( 'HalfOneUp', 'AZ', 0 ); + $this->insertPage( 'FullOneUp', 'AZ', 0 ); + $this->insertPage( 'HalfTwoLow', 'az', 0 ); + $this->insertPage( 'FullTwoLow', 'az', 0 ); + $this->insertPage( 'HalfNumbers', '1234567890', 0 ); + $this->insertPage( 'FullNumbers', '1234567890', 0 ); + $this->insertPage( 'DomainName', 'example.com', 0 ); } function removeSearchData() { @@ -42,7 +42,7 @@ class SearchEngineTest extends MediaWikiTestSetup { $article = new Article( $title, $id ); $article->doDeleteArticle( "Search Test" ); }*/ - } + } function fetchIds( $results ) { $this->assertTrue( is_object( $results ) ); @@ -64,82 +64,82 @@ class SearchEngineTest extends MediaWikiTestSetup { // Modified version of WikiRevision::importOldRevision() function insertPage( $pageName, $text, $ns ) { - $dbw = $this->db; - $title = Title::newFromText( $pageName ); - - $userId = 0; - $userText = 'WikiSysop'; - $comment = 'Search Test'; - - // avoid memory leak...? - $linkCache = LinkCache::singleton(); - $linkCache->clear(); - - $article = new Article( $title ); - $pageId = $article->getId(); - $created = false; - if ( $pageId == 0 ) { - # must create the page... - $pageId = $article->insertOn( $dbw ); - $created = true; - } - - # FIXME: Use original rev_id optionally (better for backups) - # Insert the row - $revision = new Revision( array( - 'page' => $pageId, - 'text' => $text, - 'comment' => $comment, - 'user' => $userId, - 'user_text' => $userText, - 'timestamp' => 0, - 'minor_edit' => false, + $dbw = $this->db; + $title = Title::newFromText( $pageName ); + + $userId = 0; + $userText = 'WikiSysop'; + $comment = 'Search Test'; + + // avoid memory leak...? + $linkCache = LinkCache::singleton(); + $linkCache->clear(); + + $article = new Article( $title ); + $pageId = $article->getId(); + $created = false; + if ( $pageId == 0 ) { + # must create the page... + $pageId = $article->insertOn( $dbw ); + $created = true; + } + + # FIXME: Use original rev_id optionally (better for backups) + # Insert the row + $revision = new Revision( array( + 'page' => $pageId, + 'text' => $text, + 'comment' => $comment, + 'user' => $userId, + 'user_text' => $userText, + 'timestamp' => 0, + 'minor_edit' => false, ) ); - $revId = $revision->insertOn( $dbw ); - $changed = $article->updateIfNewerOn( $dbw, $revision ); + $revId = $revision->insertOn( $dbw ); + $changed = $article->updateIfNewerOn( $dbw, $revision ); - $GLOBALS['wgTitle'] = $title; - if ( $created ) { - Article::onArticleCreate( $title ); - $article->createUpdates( $revision ); - } elseif ( $changed ) { - Article::onArticleEdit( $title ); - $article->editUpdates( - $text, $comment, false, 0, $revId ); - } + $GLOBALS['wgTitle'] = $title; + if ( $created ) { + Article::onArticleCreate( $title ); + $article->createUpdates( $revision ); + } elseif ( $changed ) { + Article::onArticleEdit( $title ); + $article->editUpdates( + $text, $comment, false, 0, $revId ); + } - $su = new SearchUpdate( $article->getId(), $pageName, $text ); - $su->doUpdate(); + $su = new SearchUpdate( $article->getId(), $pageName, $text ); + $su->doUpdate(); - $this->pageList[] = array( $title, $article->getId() ); + $this->pageList[] = array( $title, $article->getId() ); - return true; - } + return true; + } function testFullWidth() { - $this->assertEquals( - array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ), - $this->fetchIds( $this->search->searchText( 'AZ' ) ), - "Search for normalized from Half-width Upper" ); - $this->assertEquals( - array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ), - $this->fetchIds( $this->search->searchText( 'az' ) ), - "Search for normalized from Half-width Lower" ); - $this->assertEquals( - array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ), - $this->fetchIds( $this->search->searchText( 'AZ' ) ), - "Search for normalized from Full-width Upper" ); - $this->assertEquals( - array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ), - $this->fetchIds( $this->search->searchText( 'az' ) ), - "Search for normalized from Full-width Lower" ); + $this->assertEquals( + array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ), + $this->fetchIds( $this->search->searchText( 'AZ' ) ), + "Search for normalized from Half-width Upper" ); + $this->assertEquals( + array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ), + $this->fetchIds( $this->search->searchText( 'az' ) ), + "Search for normalized from Half-width Lower" ); + $this->assertEquals( + array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ), + $this->fetchIds( $this->search->searchText( 'AZ' ) ), + "Search for normalized from Full-width Upper" ); + $this->assertEquals( + array( 'FullOneUp', 'FullTwoLow', 'HalfOneUp', 'HalfTwoLow' ), + $this->fetchIds( $this->search->searchText( 'az' ) ), + "Search for normalized from Full-width Lower" ); } function testTextSearch() { $this->assertEquals( - array( 'Smithee' ), - $this->fetchIds( $this->search->searchText( 'smithee' ) ), - "Plain search failed" ); + array( 'Smithee' ), + $this->fetchIds( $this->search->searchText( 'smithee' ) ), + "Plain search failed" ); } function testTextPowerSearch() { diff --git a/maintenance/tests/phpunit/suite.xml b/maintenance/tests/phpunit/suite.xml index fdda2b88bc..0a3a8f4f26 100644 --- a/maintenance/tests/phpunit/suite.xml +++ b/maintenance/tests/phpunit/suite.xml @@ -1,12 +1,13 @@ + stopOnFailure="false" + strict="true"> ./includes @@ -23,6 +24,7 @@ + Utility Broken Stub diff --git a/maintenance/tests/testHelpers.inc b/maintenance/tests/testHelpers.inc index 6153ca31b7..1099e8d557 100644 --- a/maintenance/tests/testHelpers.inc +++ b/maintenance/tests/testHelpers.inc @@ -62,9 +62,12 @@ class TestRecorder { $this->success = 0; } - function record( $test, $result ) { + function record( $test, $result, $recorder ) { $this->total++; - $this->success += ( $result ? 1 : 0 ); + if( $result ) { + $recorder->recordTest( $test ); + $this->success += ( $result ? 1 : 0 ); + } } function end() { @@ -96,10 +99,10 @@ class TestRecorder { } } -class DbTestPreviewer extends TestRecorder { - protected $lb; // /< Database load balancer - protected $db; // /< Database connection to the main DB - protected $curRun; // /< run ID number for the current run +class DbTestPreviewer extends TestRecorder { + protected $lb; // /< Database load balancer + protected $db; // /< Database connection to the main DB + protected $curRun; // /< run ID number for the current run protected $prevRun; // /< run ID number for the previous run, if any protected $results; // /< Result array @@ -202,7 +205,7 @@ class DbTestPreviewer extends TestRecorder { printf( "\n%4d %s\n", $count, $label ); foreach ( $breakdown[$code] as $differing_test_name => $statusInfo ) { - print " * $differing_test_name [$statusInfo]\n"; + print " * $differing_test_name [$statusInfo]\n"; } } } @@ -239,7 +242,7 @@ class DbTestPreviewer extends TestRecorder { // Otherwise, this test has previous recorded results. // See when this test last had a different result to what we're seeing now. $conds = array( - 'ti_name' => $testname, + 'ti_name' => $testname, 'ti_success' => ( $after == 'f' ? "1" : "0" ) ); if ( $this->curRun ) { @@ -278,7 +281,7 @@ class DbTestPreviewer extends TestRecorder { } return ( $after == "f" ? "Introduced" : "Fixed" ) . " between " - . date( "d-M-Y H:i:s", strtotime ( $pre->tr_date ) ) . ", " . $pre->tr_mw_version + . date( "d-M-Y H:i:s", strtotime ( $pre->tr_date ) ) . ", " . $pre->tr_mw_version . " and $postDate"; } @@ -324,11 +327,11 @@ class DbTestRecorder extends DbTestPreviewer { $this->db->insert( 'testrun', array( - 'tr_date' => $this->db->timestamp(), - 'tr_mw_version' => $this->version, + 'tr_date' => $this->db->timestamp(), + 'tr_mw_version' => $this->version, 'tr_php_version' => phpversion(), - 'tr_db_version' => $this->db->getServerVersion(), - 'tr_uname' => php_uname() + 'tr_db_version' => $this->db->getServerVersion(), + 'tr_uname' => php_uname() ), __METHOD__ ); if ( $wgDBtype === 'postgres' ) { @@ -349,8 +352,8 @@ class DbTestRecorder extends DbTestPreviewer { $this->db->insert( 'testitem', array( - 'ti_run' => $this->curRun, - 'ti_name' => $test, + 'ti_run' => $this->curRun, + 'ti_name' => $test, 'ti_success' => $result ? 1 : 0, ), __METHOD__ ); @@ -379,8 +382,8 @@ class RemoteTestRecorder extends TestRecorder { * Inform a CodeReview instance that we've started or completed a test run... * * @param $status string: "running" - tell it we've started - * "complete" - provide test results array - * "abort" - something went horribly awry + * "complete" - provide test results array + * "abort" - something went horribly awry * @param $results array of test name => true/false */ function ping( $status, $results = false ) { @@ -411,11 +414,11 @@ class RemoteTestRecorder extends TestRecorder { $postData = array( 'action' => 'codetestupload', 'format' => 'json', - 'repo' => $remote['repo'], - 'suite' => $remote['suite'], - 'rev' => $revId, + 'repo' => $remote['repo'], + 'suite' => $remote['suite'], + 'rev' => $revId, 'status' => $status, - 'hmac' => $hmac, + 'hmac' => $hmac, ); if ( $status == "complete" ) { @@ -478,7 +481,7 @@ class TestFileIterator implements Iterator { $this->lineNum = $this->index = 0; } - function setParser( ParserTest $parser ) { + function setParser( MediaWikiParserTest $parser ) { $this->parser = $parser; }