From ac63001d8e2ee5cee8455fe7f8a23f84b4cc32bf Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Thu, 14 Feb 2013 12:22:13 +0100 Subject: [PATCH] Update formatting 1 of n. Change-Id: I852729f08bbb0c5e39c2db44362ccdc7f59dcc08 --- tests/RunSeleniumTests.php | 74 ++++-- tests/parser/parserTest.inc | 206 +++++++-------- tests/parser/parserTestsParserHook.php | 16 +- tests/parserTests.php | 2 +- tests/phpunit/MediaWikiLangTestCase.php | 2 +- tests/phpunit/MediaWikiPHPUnitCommand.php | 18 +- tests/phpunit/MediaWikiTestCase.php | 78 +++--- tests/phpunit/StructureTest.php | 4 +- tests/phpunit/bootstrap.php | 2 +- tests/phpunit/docs/ExportDemoTest.php | 2 +- tests/phpunit/includes/ArticleTest.php | 6 +- tests/phpunit/includes/BlockTest.php | 12 +- tests/phpunit/includes/EditPageTest.php | 27 +- tests/phpunit/includes/ExtraParserTest.php | 46 ++-- .../FormOptionsInitializationTest.php | 26 +- tests/phpunit/includes/FormOptionsTest.php | 24 +- .../includes/GlobalFunctions/GlobalTest.php | 246 +++++++++--------- .../GlobalFunctions/wfAssembleUrlTest.php | 2 +- .../includes/GlobalFunctions/wfBCP47Test.php | 47 ++-- .../GlobalFunctions/wfBaseConvertTest.php | 6 +- .../GlobalFunctions/wfBaseNameTest.php | 4 +- .../GlobalFunctions/wfExpandUrlTest.php | 2 +- .../GlobalFunctions/wfGetCallerTest.php | 5 +- .../wfShorthandToIntegerTest.php | 2 +- .../GlobalFunctions/wfTimestampTest.php | 8 +- .../GlobalFunctions/wfUrlencodeTest.php | 35 ++- tests/phpunit/includes/HtmlTest.php | 212 +++++++-------- tests/phpunit/includes/HttpTest.php | 54 ++-- tests/phpunit/includes/IPTest.php | 113 ++++---- tests/phpunit/includes/JsonTest.php | 16 +- .../includes/LanguageConverterTest.php | 6 +- tests/phpunit/includes/LicensesTest.php | 4 +- tests/phpunit/includes/LinkerTest.php | 4 +- tests/phpunit/includes/LocalFileTest.php | 12 +- tests/phpunit/includes/MWFunctionTest.php | 27 +- tests/phpunit/includes/MWNamespaceTest.php | 140 +++++----- tests/phpunit/includes/OutputPageTest.php | 22 +- tests/phpunit/includes/PathRouterTest.php | 44 ++-- tests/phpunit/includes/PreferencesTest.php | 6 +- tests/phpunit/includes/Providers.php | 8 +- 40 files changed, 799 insertions(+), 771 deletions(-) diff --git a/tests/RunSeleniumTests.php b/tests/RunSeleniumTests.php index 28501eaa1b..77dc7d468a 100644 --- a/tests/RunSeleniumTests.php +++ b/tests/RunSeleniumTests.php @@ -32,7 +32,7 @@ define( 'SELENIUMTEST', true ); require( __DIR__ . '/../maintenance/Maintenance.php' ); require_once( 'PHPUnit/Runner/Version.php' ); -if( version_compare( PHPUnit_Runner_Version::id(), '3.5.0', '>=' ) ) { +if ( version_compare( PHPUnit_Runner_Version::id(), '3.5.0', '>=' ) ) { # PHPUnit 3.5.0 introduced a nice autoloader based on class name require_once( 'PHPUnit/Autoload.php' ); } else { @@ -75,7 +75,7 @@ class SeleniumTester extends Maintenance { public function listBrowsers() { $desc = "Available browsers:\n"; - foreach ($this->selenium->getAvailableBrowsers() as $k => $v) { + foreach ( $this->selenium->getAvailableBrowsers() as $k => $v ) { $desc .= " $k => $v\n"; } @@ -85,8 +85,8 @@ class SeleniumTester extends Maintenance { protected function startServer() { if ( $this->seleniumServerExecPath == '' ) { die ( "The selenium server exec path is not set in " . - "selenium_settings.ini. Cannot start server \n" . - "as requested - terminating RunSeleniumTests\n" ); + "selenium_settings.ini. Cannot start server \n" . + "as requested - terminating RunSeleniumTests\n" ); } $this->serverManager = new SeleniumServerManager( 'true', $this->selenium->getPort(), @@ -159,20 +159,20 @@ class SeleniumTester extends Maintenance { $configFile = $this->getOption( 'seleniumConfig', '' ); if ( strlen( $configFile ) > 0 ) { - $this->output("Using Selenium Configuration file: " . $configFile . "\n"); + $this->output( "Using Selenium Configuration file: " . $configFile . "\n" ); SeleniumConfig::getSeleniumSettings( $seleniumSettings, $seleniumBrowsers, $seleniumTestSuites, $configFile ); } elseif ( !isset( $wgHooks['SeleniumSettings'] ) ) { - $this->output("No command line, configuration file or configuration hook found.\n"); + $this->output( "No command line, configuration file or configuration hook found.\n" ); SeleniumConfig::getSeleniumSettings( $seleniumSettings, $seleniumBrowsers, $seleniumTestSuites - ); + ); } else { - $this->output("Using 'SeleniumSettings' hook for configuration.\n"); - wfRunHooks('SeleniumSettings', array( $seleniumSettings, + $this->output( "Using 'SeleniumSettings' hook for configuration.\n" ); + wfRunHooks( 'SeleniumSettings', array( $seleniumSettings, $seleniumBrowsers, $seleniumTestSuites ) ); } @@ -180,24 +180,48 @@ class SeleniumTester extends Maintenance { // State for starting/stopping the Selenium server has nothing to do with the Selenium // class. Keep this state local to SeleniumTester class. Using getOption() is clumsy, but // the Maintenance class does not have a setOption() - if ( ! isset( $seleniumSettings['startserver'] ) ) $this->getOption( 'startserver', true ); - if ( ! isset( $seleniumSettings['stopserver'] ) ) $this->getOption( 'stopserver', true ); - if ( !isset( $seleniumSettings['seleniumserverexecpath'] ) ) $seleniumSettings['seleniumserverexecpath'] = ''; + if ( !isset( $seleniumSettings['startserver'] ) ) { + $this->getOption( 'startserver', true ); + } + if ( !isset( $seleniumSettings['stopserver'] ) ) { + $this->getOption( 'stopserver', true ); + } + if ( !isset( $seleniumSettings['seleniumserverexecpath'] ) ) { + $seleniumSettings['seleniumserverexecpath'] = ''; + } $this->seleniumServerExecPath = $seleniumSettings['seleniumserverexecpath']; //set reasonable defaults if we did not find the settings - if ( !isset( $seleniumBrowsers ) ) $seleniumBrowsers = array ('firefox' => '*firefox'); - if ( !isset( $seleniumSettings['host'] ) ) $seleniumSettings['host'] = $wgServer . $wgScriptPath; - if ( !isset( $seleniumSettings['port'] ) ) $seleniumSettings['port'] = '4444'; - if ( !isset( $seleniumSettings['wikiUrl'] ) ) $seleniumSettings['wikiUrl'] = 'http://localhost'; - if ( !isset( $seleniumSettings['username'] ) ) $seleniumSettings['username'] = ''; - if ( !isset( $seleniumSettings['userPassword'] ) ) $seleniumSettings['userPassword'] = ''; - if ( !isset( $seleniumSettings['testBrowser'] ) ) $seleniumSettings['testBrowser'] = 'firefox'; - if ( !isset( $seleniumSettings['jUnitLogFile'] ) ) $seleniumSettings['jUnitLogFile'] = false; - if ( !isset( $seleniumSettings['runAgainstGrid'] ) ) $seleniumSettings['runAgainstGrid'] = false; + if ( !isset( $seleniumBrowsers ) ) { + $seleniumBrowsers = array( 'firefox' => '*firefox' ); + } + if ( !isset( $seleniumSettings['host'] ) ) { + $seleniumSettings['host'] = $wgServer . $wgScriptPath; + } + if ( !isset( $seleniumSettings['port'] ) ) { + $seleniumSettings['port'] = '4444'; + } + if ( !isset( $seleniumSettings['wikiUrl'] ) ) { + $seleniumSettings['wikiUrl'] = 'http://localhost'; + } + if ( !isset( $seleniumSettings['username'] ) ) { + $seleniumSettings['username'] = ''; + } + if ( !isset( $seleniumSettings['userPassword'] ) ) { + $seleniumSettings['userPassword'] = ''; + } + if ( !isset( $seleniumSettings['testBrowser'] ) ) { + $seleniumSettings['testBrowser'] = 'firefox'; + } + if ( !isset( $seleniumSettings['jUnitLogFile'] ) ) { + $seleniumSettings['jUnitLogFile'] = false; + } + if ( !isset( $seleniumSettings['runAgainstGrid'] ) ) { + $seleniumSettings['runAgainstGrid'] = false; + } // Setup Selenium class - $this->selenium = new Selenium( ); + $this->selenium = new Selenium(); $this->selenium->setAvailableBrowsers( $seleniumBrowsers ); $this->selenium->setRunAgainstGrid( $this->getOption( 'runAgainstGrid', $seleniumSettings['runAgainstGrid'] ) ); $this->selenium->setUrl( $this->getOption( 'wikiUrl', $seleniumSettings['wikiUrl'] ) ); @@ -209,9 +233,9 @@ class SeleniumTester extends Maintenance { $this->selenium->setVerbose( $this->hasOption( 'verbose' ) ); $this->selenium->setJUnitLogFile( $this->getOption( 'jUnitLogFile', $seleniumSettings['jUnitLogFile'] ) ); - if( $this->hasOption( 'list-browsers' ) ) { + if ( $this->hasOption( 'list-browsers' ) ) { $this->listBrowsers(); - exit(0); + exit( 0 ); } if ( $this->hasOption( 'startserver' ) ) { $this->startServer(); @@ -222,7 +246,7 @@ class SeleniumTester extends Maintenance { $this->runTests( $seleniumTestSuites ); - if ( $this->hasOption( 'stopserver' ) ) { + if ( $this->hasOption( 'stopserver' ) ) { $this->stopServer(); } } diff --git a/tests/parser/parserTest.inc b/tests/parser/parserTest.inc index 05a6f15426..b9bb33fdf0 100644 --- a/tests/parser/parserTest.inc +++ b/tests/parser/parserTest.inc @@ -74,6 +74,7 @@ class ParserTest { public $regex = ""; private $savedGlobals = array(); + /** * Sets terminal colorization and diff/quick modes depending on OS and * command-line options (--color and --quick). @@ -83,14 +84,14 @@ class ParserTest { $this->color = !wfIsWindows() && Maintenance::posix_isatty( 1 ); if ( isset( $options['color'] ) ) { - switch( $options['color'] ) { - case 'no': - $this->color = false; - break; - case 'yes': - default: - $this->color = true; - break; + switch ( $options['color'] ) { + case 'no': + $this->color = false; + break; + case 'yes': + default: + $this->color = true; + break; } } @@ -102,7 +103,7 @@ class ParserTest { $this->showProgress = !isset( $options['quiet'] ); $this->showFailure = !( isset( $options['quiet'] ) - && ( isset( $options['record'] ) + && ( isset( $options['record'] ) || isset( $options['compare'] ) ) ); // redundant output $this->showOutput = isset( $options['show-output'] ); @@ -152,26 +153,26 @@ class ParserTest { $wgExtensionAssetsPath = '/extensions'; $wgThumbnailScriptPath = false; $wgLockManagers = array( array( - 'name' => 'fsLockManager', - 'class' => 'FSLockManager', + 'name' => 'fsLockManager', + 'class' => 'FSLockManager', 'lockDirectory' => wfTempDir() . '/test-repo/lockdir', ), array( - 'name' => 'nullLockManager', - 'class' => 'NullLockManager', + 'name' => 'nullLockManager', + 'class' => 'NullLockManager', ) ); $wgLocalFileRepo = array( - 'class' => 'LocalRepo', - 'name' => 'local', - 'url' => 'http://example.com/images', - 'hashLevels' => 2, + 'class' => 'LocalRepo', + 'name' => 'local', + 'url' => 'http://example.com/images', + 'hashLevels' => 2, 'transformVia404' => false, - 'backend' => new FSFileBackend( array( - 'name' => 'local-backend', + 'backend' => new FSFileBackend( array( + 'name' => 'local-backend', 'lockManager' => 'fsLockManager', 'containerPaths' => array( - 'local-public' => wfTempDir() . '/test-repo/public', - 'local-thumb' => wfTempDir() . '/test-repo/thumb', - 'local-temp' => wfTempDir() . '/test-repo/temp', + 'local-public' => wfTempDir() . '/test-repo/public', + 'local-thumb' => wfTempDir() . '/test-repo/thumb', + 'local-temp' => wfTempDir() . '/test-repo/temp', 'local-deleted' => wfTempDir() . '/test-repo/deleted', ) ) ) @@ -206,16 +207,16 @@ class ParserTest { $wgRequest = $context->getRequest(); if ( $wgStyleDirectory === false ) { - $wgStyleDirectory = "$IP/skins"; + $wgStyleDirectory = "$IP/skins"; } } - public function setupRecorder ( $options ) { + public function setupRecorder( $options ) { if ( isset( $options['record'] ) ) { $this->recorder = new DbTestRecorder( $this ); $this->recorder->version = isset( $options['setversion'] ) ? - $options['setversion'] : SpecialVersion::getVersion(); + $options['setversion'] : SpecialVersion::getVersion(); } elseif ( isset( $options['compare'] ) ) { $this->recorder = new DbTestPreviewer( $this ); } else { @@ -230,8 +231,7 @@ class ParserTest { static public function chomp( $s ) { if ( substr( $s, -1 ) === "\n" ) { return substr( $s, 0, -1 ); - } - else { + } else { return $s; } } @@ -390,7 +390,7 @@ class ParserTest { $this->teardownDatabase(); $this->recorder->report(); - } catch (DBError $e) { + } catch ( DBError $e ) { echo $e->getMessage(); } $this->recorder->end(); @@ -463,8 +463,7 @@ class ParserTest { if ( isset( $opts['title'] ) ) { $titleText = $opts['title']; - } - else { + } else { $titleText = 'Parser test'; } @@ -638,12 +637,12 @@ class ParserTest { 'wgArticlePath' => '/wiki/$1', 'wgActionPaths' => array(), 'wgLockManagers' => array( array( - 'name' => 'fsLockManager', - 'class' => 'FSLockManager', + 'name' => 'fsLockManager', + 'class' => 'FSLockManager', 'lockDirectory' => $this->uploadDir . '/lockdir', ), array( - 'name' => 'nullLockManager', - 'class' => 'NullLockManager', + 'name' => 'nullLockManager', + 'class' => 'NullLockManager', ) ), 'wgLocalFileRepo' => array( 'class' => 'LocalRepo', @@ -651,13 +650,13 @@ class ParserTest { 'url' => 'http://example.com/images', 'hashLevels' => 2, 'transformVia404' => false, - 'backend' => new FSFileBackend( array( - 'name' => 'local-backend', + 'backend' => new FSFileBackend( array( + 'name' => 'local-backend', 'lockManager' => 'fsLockManager', 'containerPaths' => array( - 'local-public' => $this->uploadDir, - 'local-thumb' => $this->uploadDir . '/thumb', - 'local-temp' => $this->uploadDir . '/temp', + 'local-public' => $this->uploadDir, + 'local-thumb' => $this->uploadDir . '/thumb', + 'local-temp' => $this->uploadDir . '/temp', 'local-deleted' => $this->uploadDir . '/delete', ) ) ) @@ -685,10 +684,10 @@ class ParserTest { 'wgVariantArticlePath' => false, 'wgGroupPermissions' => array( '*' => array( 'createaccount' => true, - 'read' => true, - 'edit' => true, - 'createpage' => true, - 'createtalk' => true, + 'read' => true, + 'edit' => true, + 'createpage' => true, + 'createtalk' => true, ) ), 'wgNamespaceProtection' => array( NS_MEDIAWIKI => 'editinterface' ), 'wgDefaultExternalStore' => array(), @@ -755,7 +754,7 @@ class ParserTest { $tables = array( 'user', 'user_properties', 'user_former_groups', 'page', 'page_restrictions', 'protected_titles', 'revision', 'text', 'pagelinks', 'imagelinks', 'categorylinks', 'templatelinks', 'externallinks', 'langlinks', 'iwlinks', - 'site_stats', 'hitcounter', 'ipblocks', 'image', 'oldimage', + 'site_stats', 'hitcounter', 'ipblocks', 'image', 'oldimage', 'recentchanges', 'watchlist', 'interwiki', 'logging', 'querycache', 'objectcache', 'job', 'l10n_cache', 'redirect', 'querycachetwo', 'archive', 'user_groups', 'page_props', 'category', 'msg_resource', 'msg_resource_links' @@ -818,44 +817,44 @@ class ParserTest { # Anonymous user $this->db->insert( 'user', array( - 'user_id' => 0, - 'user_name' => 'Anonymous' ) ); + 'user_id' => 0, + 'user_name' => 'Anonymous' ) ); } # Hack: insert a few Wikipedia in-project interwiki prefixes, # for testing inter-language links $this->db->insert( 'interwiki', array( array( 'iw_prefix' => 'wikipedia', - 'iw_url' => 'http://en.wikipedia.org/wiki/$1', - 'iw_api' => '', - 'iw_wikiid' => '', - 'iw_local' => 0 ), + 'iw_url' => 'http://en.wikipedia.org/wiki/$1', + 'iw_api' => '', + 'iw_wikiid' => '', + 'iw_local' => 0 ), array( 'iw_prefix' => 'meatball', - 'iw_url' => 'http://www.usemod.com/cgi-bin/mb.pl?$1', - 'iw_api' => '', - 'iw_wikiid' => '', - 'iw_local' => 0 ), + 'iw_url' => 'http://www.usemod.com/cgi-bin/mb.pl?$1', + 'iw_api' => '', + 'iw_wikiid' => '', + 'iw_local' => 0 ), array( 'iw_prefix' => 'zh', - 'iw_url' => 'http://zh.wikipedia.org/wiki/$1', - 'iw_api' => '', - 'iw_wikiid' => '', - 'iw_local' => 1 ), + 'iw_url' => 'http://zh.wikipedia.org/wiki/$1', + 'iw_api' => '', + 'iw_wikiid' => '', + 'iw_local' => 1 ), array( 'iw_prefix' => 'es', - 'iw_url' => 'http://es.wikipedia.org/wiki/$1', - 'iw_api' => '', - 'iw_wikiid' => '', - 'iw_local' => 1 ), + 'iw_url' => 'http://es.wikipedia.org/wiki/$1', + 'iw_api' => '', + 'iw_wikiid' => '', + 'iw_local' => 1 ), array( 'iw_prefix' => 'fr', - 'iw_url' => 'http://fr.wikipedia.org/wiki/$1', - 'iw_api' => '', - 'iw_wikiid' => '', - 'iw_local' => 1 ), + 'iw_url' => 'http://fr.wikipedia.org/wiki/$1', + 'iw_api' => '', + 'iw_wikiid' => '', + 'iw_local' => 1 ), array( 'iw_prefix' => 'ru', - 'iw_url' => 'http://ru.wikipedia.org/wiki/$1', - 'iw_api' => '', - 'iw_wikiid' => '', - 'iw_local' => 1 ), - ) ); + 'iw_url' => 'http://ru.wikipedia.org/wiki/$1', + 'iw_api' => '', + 'iw_wikiid' => '', + 'iw_local' => 1 ), + ) ); # Update certain things in site_stats $this->db->insert( 'site_stats', array( 'ss_row_id' => 1, 'ss_images' => 2, 'ss_good_articles' => 1 ) ); @@ -870,30 +869,30 @@ class ParserTest { $user = User::createNew( 'WikiSysop' ); $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Foobar.jpg' ) ); $image->recordUpload2( '', 'Upload of some lame file', 'Some lame file', array( - 'size' => 12345, - 'width' => 1941, - 'height' => 220, - 'bits' => 24, - 'media_type' => MEDIATYPE_BITMAP, - 'mime' => 'image/jpeg', - 'metadata' => serialize( array() ), - 'sha1' => wfBaseConvert( '', 16, 36, 31 ), - 'fileExists' => true - ), $this->db->timestamp( '20010115123500' ), $user ); + 'size' => 12345, + 'width' => 1941, + 'height' => 220, + 'bits' => 24, + 'media_type' => MEDIATYPE_BITMAP, + 'mime' => 'image/jpeg', + 'metadata' => serialize( array() ), + 'sha1' => wfBaseConvert( '', 16, 36, 31 ), + 'fileExists' => true + ), $this->db->timestamp( '20010115123500' ), $user ); # This image will be blacklisted in [[MediaWiki:Bad image list]] $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Bad.jpg' ) ); $image->recordUpload2( '', 'zomgnotcensored', 'Borderline image', array( - 'size' => 12345, - 'width' => 320, - 'height' => 240, - 'bits' => 24, - 'media_type' => MEDIATYPE_BITMAP, - 'mime' => 'image/jpeg', - 'metadata' => serialize( array() ), - 'sha1' => wfBaseConvert( '', 16, 36, 31 ), - 'fileExists' => true - ), $this->db->timestamp( '20010115123500' ), $user ); + 'size' => 12345, + 'width' => 320, + 'height' => 240, + 'bits' => 24, + 'media_type' => MEDIATYPE_BITMAP, + 'mime' => 'image/jpeg', + 'metadata' => serialize( array() ), + 'sha1' => wfBaseConvert( '', 16, 36, 31 ), + 'fileExists' => true + ), $this->db->timestamp( '20010115123500' ), $user ); } public function teardownDatabase() { @@ -907,7 +906,7 @@ class ParserTest { $this->databaseSetupDone = false; if ( $this->useTemporaryTables ) { - if( $this->db->getType() == 'sqlite' ) { + if ( $this->db->getType() == 'sqlite' ) { # Under SQLite the searchindex table is virtual and need # to be explicitly destroyed. See bug 29912 # See also MediaWikiTestCase::destroyDB() @@ -926,8 +925,9 @@ class ParserTest { $this->db->query( $sql ); } - if ( $this->db->getType() == 'oracle' ) + if ( $this->db->getType() == 'oracle' ) { $this->db->query( 'BEGIN FILL_WIKI_INFO; END;' ); + } $this->teardownGlobals(); } @@ -990,7 +990,7 @@ class ParserTest { // delete the files first, then the dirs. self::deleteFiles( - array ( + array( "$dir/3/3a/Foobar.jpg", "$dir/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg", "$dir/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg", @@ -1014,7 +1014,7 @@ class ParserTest { ); self::deleteDirs( - array ( + array( "$dir/3/3a", "$dir/3", "$dir/thumb/6/65", @@ -1135,8 +1135,8 @@ class ParserTest { $outfile = "$prefix-$outFileTail"; $this->dumpToFile( $output, $outfile ); - $shellInfile = wfEscapeShellArg($infile); - $shellOutfile = wfEscapeShellArg($outfile); + $shellInfile = wfEscapeShellArg( $infile ); + $shellOutfile = wfEscapeShellArg( $outfile ); global $wgDiff3; // we assume that people with diff3 also have usual diff @@ -1172,7 +1172,7 @@ class ParserTest { return preg_replace( array( '/^(-.*)$/m', '/^(\+.*)$/m' ), array( $this->term->color( 34 ) . '$1' . $this->term->reset(), - $this->term->color( 31 ) . '$1' . $this->term->reset() ), + $this->term->color( 31 ) . '$1' . $this->term->reset() ), $text ); } @@ -1237,7 +1237,7 @@ class ParserTest { public function requireHook( $name ) { global $wgParser; - $wgParser->firstCallInit( ); // make sure hooks are loaded. + $wgParser->firstCallInit(); // make sure hooks are loaded. if ( isset( $wgParser->mTagHooks[$name] ) ) { $this->hooks[$name] = $wgParser->mTagHooks[$name]; @@ -1260,7 +1260,7 @@ class ParserTest { public function requireFunctionHook( $name ) { global $wgParser; - $wgParser->firstCallInit( ); // make sure hooks are loaded. + $wgParser->firstCallInit(); // make sure hooks are loaded. if ( isset( $wgParser->mFunctionHooks[$name] ) ) { $this->functionHooks[$name] = $wgParser->mFunctionHooks[$name]; @@ -1292,9 +1292,9 @@ class ParserTest { private function wellFormed( $text ) { $html = Sanitizer::hackDocType() . - '' . - $text . - ''; + '' . + $text . + ''; $parser = xml_parser_create( "UTF-8" ); diff --git a/tests/parser/parserTestsParserHook.php b/tests/parser/parserTestsParserHook.php index f01665c1d4..c8b3e8974b 100644 --- a/tests/parser/parserTestsParserHook.php +++ b/tests/parser/parserTestsParserHook.php @@ -35,18 +35,18 @@ class ParserTestParserHook { static function dumpHook( $in, $argv ) { return "
\n" .
-			   var_export( $in, true ) . "\n" .
-			   var_export( $argv, true ) . "\n" .
-			   "
"; + var_export( $in, true ) . "\n" . + var_export( $argv, true ) . "\n" . + ""; } static function staticTagHook( $in, $argv, $parser ) { - if ( ! count( $argv ) ) { + if ( !count( $argv ) ) { $parser->static_tag_buf = $in; return ''; } elseif ( count( $argv ) === 1 && isset( $argv['action'] ) - && $argv['action'] === 'flush' && $in === null ) - { + && $argv['action'] === 'flush' && $in === null + ) { // Clear the buffer, we probably don't need to if ( isset( $parser->static_tag_buf ) ) { $tmp = $parser->static_tag_buf; @@ -55,12 +55,12 @@ class ParserTestParserHook { } $parser->static_tag_buf = null; return $tmp; - } else - // wtf? + } else { // wtf? return "\nCall this extension as string or as" . " , not in any other way.\n" . "text: " . var_export( $in, true ) . "\n" . "argv: " . var_export( $argv, true ) . "\n"; + } } } diff --git a/tests/parserTests.php b/tests/parserTests.php index 1ef6473aa3..4d2c402ded 100644 --- a/tests/parserTests.php +++ b/tests/parserTests.php @@ -72,7 +72,7 @@ if ( $wgDBtype == 'sqlite' ) { # refer to $wgTitle directly, but instead use the title # passed to it. $wgTitle = Title::newFromText( 'Parser test script do not use' ); -$tester = new ParserTest($options); +$tester = new ParserTest( $options ); if ( isset( $options['file'] ) ) { $files = array( $options['file'] ); diff --git a/tests/phpunit/MediaWikiLangTestCase.php b/tests/phpunit/MediaWikiLangTestCase.php index 3034601132..0cf6e383e5 100644 --- a/tests/phpunit/MediaWikiLangTestCase.php +++ b/tests/phpunit/MediaWikiLangTestCase.php @@ -10,7 +10,7 @@ abstract class MediaWikiLangTestCase extends MediaWikiTestCase { parent::setUp(); if ( $wgLanguageCode != $wgContLang->getCode() ) { - throw new MWException("Error in MediaWikiLangTestCase::setUp(): " . + throw new MWException( "Error in MediaWikiLangTestCase::setUp(): " . "\$wgLanguageCode ('$wgLanguageCode') is different from " . "\$wgContLang->getCode() (" . $wgContLang->getCode() . ")" ); } diff --git a/tests/phpunit/MediaWikiPHPUnitCommand.php b/tests/phpunit/MediaWikiPHPUnitCommand.php index 0434bb3fcc..c139f0b166 100644 --- a/tests/phpunit/MediaWikiPHPUnitCommand.php +++ b/tests/phpunit/MediaWikiPHPUnitCommand.php @@ -14,7 +14,7 @@ class MediaWikiPHPUnitCommand extends PHPUnit_TextUI_Command { ); public function __construct() { - foreach( self::$additionalOptions as $option => $default ) { + foreach ( self::$additionalOptions as $option => $default ) { $this->longOptions[$option] = $option . 'Handler'; } @@ -23,7 +23,7 @@ class MediaWikiPHPUnitCommand extends PHPUnit_TextUI_Command { public static function main( $exit = true ) { $command = new self; - if( wfIsWindows() ) { + if ( wfIsWindows() ) { # Windows does not come anymore with ANSI.SYS loaded by default # PHPUnit uses the suite.xml parameters to enable/disable colors # which can be then forced to be enabled with --colors. @@ -40,18 +40,20 @@ class MediaWikiPHPUnitCommand extends PHPUnit_TextUI_Command { # See bug 32022 set_include_path( __DIR__ - .PATH_SEPARATOR - . get_include_path() + . PATH_SEPARATOR + . get_include_path() ); - $command->run($_SERVER['argv'], $exit); + $command->run( $_SERVER['argv'], $exit ); } public function __call( $func, $args ) { - if( substr( $func, -7 ) == 'Handler' ) { - if( is_null( $args[0] ) ) $args[0] = true; //Booleans - self::$additionalOptions[substr( $func, 0, -7 ) ] = $args[0]; + if ( substr( $func, -7 ) == 'Handler' ) { + if ( is_null( $args[0] ) ) { + $args[0] = true; + } //Booleans + self::$additionalOptions[substr( $func, 0, -7 )] = $args[0]; } } diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index dfc58816a1..f16d06c4b0 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -81,17 +81,17 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { $needsResetDB = false; $logName = get_class( $this ) . '::' . $this->getName( false ); - if( $this->needsDB() ) { + if ( $this->needsDB() ) { // set up a DB connection for this test to use self::$useTemporaryTables = !$this->getCliArg( 'use-normal-tables' ); - self::$reuseDB = $this->getCliArg('reuse-db'); + self::$reuseDB = $this->getCliArg( 'reuse-db' ); $this->db = wfGetDB( DB_MASTER ); $this->checkDbIsSupported(); - if( !self::$dbSetup ) { + if ( !self::$dbSetup ) { wfProfileIn( $logName . ' (clone-db)' ); // switch to a temporary clone of the database @@ -116,7 +116,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { parent::run( $result ); wfProfileOut( $logName ); - if( $needsResetDB ) { + if ( $needsResetDB ) { wfProfileIn( $logName . ' (reset-db)' ); $this->resetDB(); wfProfileOut( $logName . ' (reset-db)' ); @@ -188,7 +188,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { if ( $this->needsDB() && $this->db ) { // Clean up open transactions - while( $this->db->trxLevel() > 0 ) { + while ( $this->db->trxLevel() > 0 ) { $this->db->rollback(); } @@ -213,7 +213,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { if ( $this->needsDB() && $this->db ) { // Clean up open transactions - while( $this->db->trxLevel() > 0 ) { + while ( $this->db->trxLevel() > 0 ) { $this->db->rollback(); } @@ -276,7 +276,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { protected function setMwGlobals( $pairs, $value = null ) { // Normalize (string, value) to an array - if( is_string( $pairs ) ) { + if ( is_string( $pairs ) ) { $pairs = array( $pairs => $value ); } @@ -356,8 +356,8 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { # Insert 0 user to prevent FK violations # Anonymous user $this->db->insert( 'user', array( - 'user_id' => 0, - 'user_name' => 'Anonymous' ), __METHOD__, array( 'IGNORE' ) ); + 'user_id' => 0, + 'user_name' => 'Anonymous' ), __METHOD__, array( 'IGNORE' ) ); # Insert 0 page to prevent FK violations # Blank page @@ -471,20 +471,24 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { * Empty all tables so they can be repopulated for tests */ private function resetDB() { - if( $this->db ) { - if ( $this->db->getType() == 'oracle' ) { + if ( $this->db ) { + if ( $this->db->getType() == 'oracle' ) { if ( self::$useTemporaryTables ) { wfGetLB()->closeAll(); $this->db = wfGetDB( DB_MASTER ); } else { - foreach( $this->tablesUsed as $tbl ) { - if( $tbl == 'interwiki') continue; - $this->db->query( 'TRUNCATE TABLE '.$this->db->tableName($tbl), __METHOD__ ); + foreach ( $this->tablesUsed as $tbl ) { + if ( $tbl == 'interwiki' ) { + continue; + } + $this->db->query( 'TRUNCATE TABLE ' . $this->db->tableName( $tbl ), __METHOD__ ); } } } else { - foreach( $this->tablesUsed as $tbl ) { - if( $tbl == 'interwiki' || $tbl == 'user' ) continue; + foreach ( $this->tablesUsed as $tbl ) { + if ( $tbl == 'interwiki' || $tbl == 'user' ) { + continue; + } $this->db->delete( $tbl, '*', __METHOD__ ); } } @@ -500,9 +504,9 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { ); if ( method_exists( $this->suite, $func ) ) { - return call_user_func_array( array( $this->suite, $func ), $args); + return call_user_func_array( array( $this->suite, $func ), $args ); } elseif ( isset( $compatibility[$func] ) ) { - return call_user_func_array( array( $this, $compatibility[$func] ), $args); + return call_user_func_array( array( $this, $compatibility[$func] ), $args ); } else { throw new MWException( "Called non-existant $func method on " . get_class( $this ) ); @@ -543,14 +547,14 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { } protected function checkDbIsSupported() { - if( !in_array( $this->db->getType(), $this->supportedDBs ) ) { + if ( !in_array( $this->db->getType(), $this->supportedDBs ) ) { throw new MWException( $this->db->getType() . " is not currently supported for unit testing." ); } } public function getCliArg( $offset ) { - if( isset( MediaWikiPHPUnitCommand::$additionalOptions[$offset] ) ) { + if ( isset( MediaWikiPHPUnitCommand::$additionalOptions[$offset] ) ) { return MediaWikiPHPUnitCommand::$additionalOptions[$offset]; } @@ -595,7 +599,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { protected function assertSelect( $table, $fields, $condition, array $expectedRows ) { if ( !$this->needsDB() ) { throw new MWException( 'When testing database state, the test cases\'s needDB()' . - ' method should return true. Use @group Database or $this->tablesUsed.'); + ' method should return true. Use @group Database or $this->tablesUsed.' ); } $db = wfGetDB( DB_SLAVE ); @@ -634,7 +638,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { */ protected function arrayWrap( array $elements ) { return array_map( - function( $element ) { + function ( $element ) { return array( $element ); }, $elements @@ -682,9 +686,9 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { * @param String $actual HTML on oneline * @param String $msg Optional message */ - protected function assertHTMLEquals( $expected, $actual, $msg='' ) { + protected function assertHTMLEquals( $expected, $actual, $msg = '' ) { $expected = str_replace( '>', ">\n", $expected ); - $actual = str_replace( '>', ">\n", $actual ); + $actual = str_replace( '>', ">\n", $actual ); $this->assertEquals( $expected, $actual, $msg ); } @@ -699,7 +703,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { protected function objectAssociativeSort( array &$array ) { uasort( $array, - function( $a, $b ) { + function ( $a, $b ) { return serialize( $a ) > serialize( $b ) ? 1 : -1; } ); @@ -742,8 +746,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { protected function assertTypeOrValue( $type, $actual, $value = false, $message = '' ) { if ( $actual === $value ) { $this->assertTrue( true, $message ); - } - else { + } else { $this->assertType( $type, $actual, $message ); } } @@ -762,8 +765,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { protected function assertType( $type, $actual, $message = '' ) { if ( class_exists( $type ) || interface_exists( $type ) ) { $this->assertInstanceOf( $type, $actual, $message ); - } - else { + } else { $this->assertInternalType( $type, $actual, $message ); } } @@ -816,7 +818,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { $namespaces = array_diff( $namespaces, array( NS_FILE, NS_CATEGORY, NS_MEDIAWIKI, NS_USER // don't mess with magic namespaces - )); + ) ); $talk = array_filter( $namespaces, function ( $ns ) { return MWNamespace::isTalk( $ns ); @@ -829,7 +831,8 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { // check default content model of each namespace foreach ( $namespaces as $ns ) { if ( !isset( $wgNamespaceContentModels[$ns] ) || - $wgNamespaceContentModels[$ns] === CONTENT_MODEL_WIKITEXT ) { + $wgNamespaceContentModels[$ns] === CONTENT_MODEL_WIKITEXT + ) { $wikitextNS = $ns; return $wikitextNS; @@ -857,7 +860,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { $haveDiff3 = $wgDiff3 && file_exists( $wgDiff3 ); wfRestoreWarnings(); - if( !$haveDiff3 ) { + if ( !$haveDiff3 ) { $this->markTestSkipped( "Skip test, since diff3 is not configured" ); } } @@ -875,13 +878,13 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { protected function checkHasGzip() { static $haveGzip; - if( $haveGzip === null ) { + if ( $haveGzip === null ) { $retval = null; wfShellExec( 'gzip -V', $retval ); - $haveGzip = ($retval === 0); + $haveGzip = ( $retval === 0 ); } - if( !$haveGzip ) { + if ( !$haveGzip ) { $this->markTestSkipped( "Skip test, requires the gzip utility in PATH" ); } @@ -896,7 +899,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { */ protected function checkPHPExtension( $extName ) { $loaded = extension_loaded( $extName ); - if( ! $loaded ) { + if ( !$loaded ) { $this->markTestSkipped( "PHP extension '$extName' is not loaded, skipping." ); } return $loaded; @@ -917,8 +920,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { try { call_user_func( $code ); - } - catch ( Exception $pokemons ) { + } catch ( Exception $pokemons ) { // Gotta Catch 'Em All! } diff --git a/tests/phpunit/StructureTest.php b/tests/phpunit/StructureTest.php index dfbcc9dce7..e3e213834a 100644 --- a/tests/phpunit/StructureTest.php +++ b/tests/phpunit/StructureTest.php @@ -29,7 +29,7 @@ class StructureTest extends MediaWikiTestCase { $results = null; $exitCode = null; - exec($finder, $results, $exitCode); + exec( $finder, $results, $exitCode ); $this->assertEquals( 0, @@ -42,7 +42,7 @@ class StructureTest extends MediaWikiTestCase { array( $this, 'filterSuites' ) ); $strip = strlen( $rootPath ) - 1; - foreach( $results as $k => $v) { + foreach ( $results as $k => $v ) { $results[$k] = substr( $v, $strip ); } $this->assertEquals( diff --git a/tests/phpunit/bootstrap.php b/tests/phpunit/bootstrap.php index 933767e7e9..01caf8f478 100644 --- a/tests/phpunit/bootstrap.php +++ b/tests/phpunit/bootstrap.php @@ -16,7 +16,7 @@ EOF; // Output a notice when running with older versions of PHPUnit if ( version_compare( PHPUnit_Runner_Version::id(), "3.6.7", "<" ) ) { - echo <<assertTrue( $dom->schemaValidate( "../../docs/export-" . $version . ".xsd" ), "schemaValidate has found an error" ); - } catch( Exception $e ) { + } catch ( Exception $e ) { $this->fail( "xml not valid against xsd: " . $e->getMessage() ); } } diff --git a/tests/phpunit/includes/ArticleTest.php b/tests/phpunit/includes/ArticleTest.php index 82b947bb7c..867c4f007b 100644 --- a/tests/phpunit/includes/ArticleTest.php +++ b/tests/phpunit/includes/ArticleTest.php @@ -50,7 +50,7 @@ class ArticleTest extends MediaWikiTestCase { $this->article->ext_someNewProperty = 12; $this->assertEquals( 12, $this->article->ext_someNewProperty, "Article get/set magic on new field" ); - + $this->article->ext_someNewProperty = -8; $this->assertEquals( -8, $this->article->ext_someNewProperty, "Article get/set magic on update to new field" ); @@ -80,11 +80,11 @@ class ArticleTest extends MediaWikiTestCase { $title = Title::makeTitle( NS_FILE, 'Someimage.png' ); $page = WikiPage::factory( $title ); $this->assertEquals( 'WikiFilePage', get_class( $page ) ); - + $title = Title::makeTitle( NS_CATEGORY, 'SomeCategory' ); $page = WikiPage::factory( $title ); $this->assertEquals( 'WikiCategoryPage', get_class( $page ) ); - + $title = Title::makeTitle( NS_MAIN, 'SomePage' ); $page = WikiPage::factory( $title ); $this->assertEquals( 'WikiPage', get_class( $page ) ); diff --git a/tests/phpunit/includes/BlockTest.php b/tests/phpunit/includes/BlockTest.php index bdd4853c23..19c9b6874d 100644 --- a/tests/phpunit/includes/BlockTest.php +++ b/tests/phpunit/includes/BlockTest.php @@ -59,7 +59,7 @@ class BlockTest extends MediaWikiLangTestCase { function dumpBlocks() { $v = $this->db->query( 'SELECT * FROM unittest_ipblocks' ); print "Got " . $v->numRows() . " rows. Full dump follow:\n"; - foreach( $v as $row ) { + foreach ( $v as $row ) { print_r( $row ); } } @@ -67,9 +67,9 @@ class BlockTest extends MediaWikiLangTestCase { function testInitializerFunctionsReturnCorrectBlock() { // $this->dumpBlocks(); - $this->assertTrue( $this->block->equals( Block::newFromTarget('UTBlockee') ), "newFromTarget() returns the same block as the one that was made"); + $this->assertTrue( $this->block->equals( Block::newFromTarget( 'UTBlockee' ) ), "newFromTarget() returns the same block as the one that was made" ); - $this->assertTrue( $this->block->equals( Block::newFromID( $this->blockId ) ), "newFromID() returns the same block as the one that was made"); + $this->assertTrue( $this->block->equals( Block::newFromID( $this->blockId ) ), "newFromID() returns the same block as the one that was made" ); } @@ -79,7 +79,7 @@ class BlockTest extends MediaWikiLangTestCase { function testBug26425BlockTimestampDefaultsToTime() { // delta to stop one-off errors when things happen to go over a second mark. $delta = abs( $this->madeAt - $this->block->mTimestamp ); - $this->assertLessThan( 2, $delta, "If no timestamp is specified, the block is recorded as time()"); + $this->assertLessThan( 2, $delta, "If no timestamp is specified, the block is recorded as time()" ); } @@ -95,7 +95,7 @@ class BlockTest extends MediaWikiLangTestCase { $this->hideDeprecated( 'Block::load' ); $uid = User::idFromName( 'UTBlockee' ); - $this->assertTrue( ($uid > 0), 'Must be able to look up the target user during tests' ); + $this->assertTrue( ( $uid > 0 ), 'Must be able to look up the target user during tests' ); $block = new Block(); $ok = $block->load( $vagueTarget, $uid ); @@ -112,7 +112,7 @@ class BlockTest extends MediaWikiLangTestCase { * @dataProvider provideBug29116Data */ function testBug29116NewFromTargetWithEmptyIp( $vagueTarget ) { - $block = Block::newFromTarget('UTBlockee', $vagueTarget); + $block = Block::newFromTarget( 'UTBlockee', $vagueTarget ); $this->assertTrue( $this->block->equals( $block ), "newFromTarget() returns the same block as the one that was made when given empty vagueTarget param " . var_export( $vagueTarget, true ) ); } diff --git a/tests/phpunit/includes/EditPageTest.php b/tests/phpunit/includes/EditPageTest.php index 36fde854d7..b64a54e3a6 100644 --- a/tests/phpunit/includes/EditPageTest.php +++ b/tests/phpunit/includes/EditPageTest.php @@ -59,8 +59,8 @@ class EditPageTest extends MediaWikiTestCase { * wrapper around assertEquals() which calls rrtrim() to normalize the * expected and actual texts. */ - function assertEditedTextEquals( $expected, $actual, $msg='' ) { - return $this->assertEquals( rtrim($expected), rtrim($actual), $msg ); + function assertEditedTextEquals( $expected, $actual, $msg = '' ) { + return $this->assertEquals( rtrim( $expected ), rtrim( $actual ), $msg ); } /** @@ -209,8 +209,7 @@ class EditPageTest extends MediaWikiTestCase { } public static function provideSectionEdit() { - $text = -'Intro + $text = 'Intro == one == first section. @@ -219,19 +218,19 @@ first section. second section. '; - $sectionOne = -'== one == + $sectionOne = '== one == hello '; - $newSection = -'== new section == + $newSection = '== new section == hello '; - $textWithNewSectionOne = preg_replace( '/== one ==.*== two ==/ms', - "$sectionOne\n== two ==", $text ); + $textWithNewSectionOne = preg_replace( + '/== one ==.*== two ==/ms', + "$sectionOne\n== two ==", $text + ); $textWithNewSectionAdded = "$text\n$newSection"; @@ -343,12 +342,12 @@ hello ); // see whether it makes a difference who did the base edit - $testsWithAdam = array_map( function( $test ) { + $testsWithAdam = array_map( function ( $test ) { $test[0] = 'Adam'; // change base edit user return $test; }, $tests ); - $testsWithBerta = array_map( function( $test ) { + $testsWithBerta = array_map( function ( $test ) { $test[0] = 'Berta'; // change base edit user return $test; }, $tests ); @@ -360,7 +359,7 @@ hello * @dataProvider provideAutoMerge */ public function testAutoMerge( $baseUser, $text, $adamsEdit, $bertasEdit, - $expectedCode, $expectedText, $message = null + $expectedCode, $expectedText, $message = null ) { $this->checkHasDiff3(); @@ -378,7 +377,7 @@ hello ); $page = $this->assertEdit( 'EditPageTest_testAutoMerge', null, - $baseUser, $baseEdit, null, null, __METHOD__ ); + $baseUser, $baseEdit, null, null, __METHOD__ ); $this->forceRevisionDate( $page, '20120101000000' ); diff --git a/tests/phpunit/includes/ExtraParserTest.php b/tests/phpunit/includes/ExtraParserTest.php index 46aa6fc9ac..067cfc4a73 100644 --- a/tests/phpunit/includes/ExtraParserTest.php +++ b/tests/phpunit/includes/ExtraParserTest.php @@ -18,7 +18,7 @@ class ExtraParserTest extends MediaWikiTestCase { 'wgAlwaysUseTidy' => false, 'wgCleanSignatures' => true, ) ); - + $this->options = ParserOptions::newFromUserAndLang( new User, $contLang ); $this->options->setTemplateCallback( array( __CLASS__, 'statelessFetchTemplate' ) ); $this->parser = new Parser; @@ -30,20 +30,20 @@ class ExtraParserTest extends MediaWikiTestCase { function testBug8689() { global $wgUser; $longLine = '1.' . str_repeat( '1234567890', 100000 ) . "\n"; - + $t = Title::newFromText( 'Unit test' ); $options = ParserOptions::newFromUser( $wgUser ); $this->assertEquals( "

$longLine

", $this->parser->parse( $longLine, $t, $options )->getText() ); } - + /* Test the parser entry points */ function testParse() { $title = Title::newFromText( __FUNCTION__ ); $parserOutput = $this->parser->parse( "Test\n{{Foo}}\n{{Bar}}", $title, $this->options ); $this->assertEquals( "

Test\nContent of Template:Foo\nContent of Template:Bar\n

", $parserOutput->getText() ); } - + function testPreSaveTransform() { global $wgUser; $title = Title::newFromText( __FUNCTION__ ); @@ -51,21 +51,21 @@ class ExtraParserTest extends MediaWikiTestCase { $this->assertEquals( "Test\nContent of ''Template:Foo''\n{{Bar}}", $outputText ); } - + function testPreprocess() { $title = Title::newFromText( __FUNCTION__ ); $outputText = $this->parser->preprocess( "Test\n{{Foo}}\n{{Bar}}", $title, $this->options ); - + $this->assertEquals( "Test\nContent of ''Template:Foo''\nContent of ''Template:Bar''", $outputText ); } - + /** * cleanSig() makes all templates substs and removes tildes */ function testCleanSig() { $title = Title::newFromText( __FUNCTION__ ); $outputText = $this->parser->cleanSig( "{{Foo}} ~~~~" ); - + $this->assertEquals( "{{SUBST:Foo}} ", $outputText ); } @@ -78,18 +78,18 @@ class ExtraParserTest extends MediaWikiTestCase { $title = Title::newFromText( __FUNCTION__ ); $outputText = $this->parser->cleanSig( "{{Foo}} ~~~~" ); - + $this->assertEquals( "{{Foo}} ~~~~", $outputText ); } - + /** * cleanSigInSig() just removes tildes * @dataProvider provideStringsForCleanSigInSig */ function testCleanSigInSig( $in, $out ) { - $this->assertEquals( Parser::cleanSigInSig( $in), $out ); + $this->assertEquals( Parser::cleanSigInSig( $in ), $out ); } - + public static function provideStringsForCleanSigInSig() { return array( array( "{{Foo}} ~~~~", "{{Foo}} " ), @@ -97,35 +97,35 @@ class ExtraParserTest extends MediaWikiTestCase { array( "~~~~~", "" ), ); } - + function testGetSection() { $outputText2 = $this->parser->getSection( "Section 0\n== Heading 1 ==\nSection 1\n=== Heading 2 ===\nSection 2\n== Heading 3 ==\nSection 3\n", 2 ); $outputText1 = $this->parser->getSection( "Section 0\n== Heading 1 ==\nSection 1\n=== Heading 2 ===\nSection 2\n== Heading 3 ==\nSection 3\n", 1 ); - + $this->assertEquals( "=== Heading 2 ===\nSection 2", $outputText2 ); $this->assertEquals( "== Heading 1 ==\nSection 1\n=== Heading 2 ===\nSection 2", $outputText1 ); } - + function testReplaceSection() { $outputText = $this->parser->replaceSection( "Section 0\n== Heading 1 ==\nSection 1\n=== Heading 2 ===\nSection 2\n== Heading 3 ==\nSection 3\n", 1, "New section 1" ); - + $this->assertEquals( "Section 0\nNew section 1\n\n== Heading 3 ==\nSection 3", $outputText ); } - + /** * Templates and comments are not affected, but noinclude/onlyinclude is. */ function testGetPreloadText() { $title = Title::newFromText( __FUNCTION__ ); $outputText = $this->parser->getPreloadText( "{{Foo}} censored information ", $title, $this->options ); - + $this->assertEquals( "{{Foo}} information ", $outputText ); } - - static function statelessFetchTemplate( $title, $parser=false ) { + + static function statelessFetchTemplate( $title, $parser = false ) { $text = "Content of ''" . $title->getFullText() . "''"; $deps = array(); - + return array( 'text' => $text, 'finalTitle' => $title, @@ -137,7 +137,7 @@ class ExtraParserTest extends MediaWikiTestCase { */ function testTrackingCategory() { $title = Title::newFromText( __FUNCTION__ ); - $catName = wfMessage( 'broken-file-category' )->inContentLanguage()->text(); + $catName = wfMessage( 'broken-file-category' )->inContentLanguage()->text(); $cat = Title::makeTitleSafe( NS_CATEGORY, $catName ); $expected = array( $cat->getDBkey() ); $parserOutput = $this->parser->parse( "[[file:nonexistent]]", $title, $this->options ); @@ -155,4 +155,4 @@ class ExtraParserTest extends MediaWikiTestCase { $result = $parserOutput->getCategoryLinks(); $this->assertEmpty( $result ); } - } +} diff --git a/tests/phpunit/includes/FormOptionsInitializationTest.php b/tests/phpunit/includes/FormOptionsInitializationTest.php index 99f8fb7fb7..4053683f8e 100644 --- a/tests/phpunit/includes/FormOptionsInitializationTest.php +++ b/tests/phpunit/includes/FormOptionsInitializationTest.php @@ -46,15 +46,15 @@ class FormOptionsInitializationTest extends MediaWikiTestCase { } public function testAddStringOption() { - $this->object->add( 'foo', 'string value' ); + $this->object->add( 'foo', 'string value' ); $this->assertEquals( array( 'foo' => array( - 'default' => 'string value', + 'default' => 'string value', 'consumed' => false, - 'type' => FormOptions::STRING, - 'value' => null, - ) + 'type' => FormOptions::STRING, + 'value' => null, + ) ), $this->object->getOptions() ); @@ -66,17 +66,17 @@ class FormOptionsInitializationTest extends MediaWikiTestCase { $this->assertEquals( array( 'negone' => array( - 'default' => -1, - 'value' => null, + 'default' => -1, + 'value' => null, 'consumed' => false, - 'type' => FormOptions::INT, - ), + 'type' => FormOptions::INT, + ), 'one' => array( - 'default' => 1, - 'value' => null, + 'default' => 1, + 'value' => null, 'consumed' => false, - 'type' => FormOptions::INT, - ) + 'type' => FormOptions::INT, + ) ), $this->object->getOptions() ); diff --git a/tests/phpunit/includes/FormOptionsTest.php b/tests/phpunit/includes/FormOptionsTest.php index bdc5f1259e..0a13cfec59 100644 --- a/tests/phpunit/includes/FormOptionsTest.php +++ b/tests/phpunit/includes/FormOptionsTest.php @@ -62,30 +62,30 @@ class FormOptionsTest extends MediaWikiTestCase { * Reuse helpers above assertGuessBoolean assertGuessInt assertGuessString */ public function testGuessTypeDetection() { - $this->assertGuessBoolean( true ); + $this->assertGuessBoolean( true ); $this->assertGuessBoolean( false ); - $this->assertGuessInt( 0 ); - $this->assertGuessInt( -5 ); - $this->assertGuessInt( 5 ); + $this->assertGuessInt( 0 ); + $this->assertGuessInt( -5 ); + $this->assertGuessInt( 5 ); $this->assertGuessInt( 0x0F ); - $this->assertGuessString( 'true' ); - $this->assertGuessString( 'false' ); - $this->assertGuessString( '5' ); - $this->assertGuessString( '0' ); + $this->assertGuessString( 'true' ); + $this->assertGuessString( 'false' ); + $this->assertGuessString( '5' ); + $this->assertGuessString( '0' ); } /** - * @expectedException MWException + * @expectedException MWException */ public function testGuessTypeOnArrayThrowException() { - $this->object->guessType( array( 'foo' ) ); + $this->object->guessType( array( 'foo' ) ); } /** - * @expectedException MWException + * @expectedException MWException */ public function testGuessTypeOnNullThrowException() { - $this->object->guessType( null ); + $this->object->guessType( null ); } } diff --git a/tests/phpunit/includes/GlobalFunctions/GlobalTest.php b/tests/phpunit/includes/GlobalFunctions/GlobalTest.php index 1219d4397a..24fc47cf84 100644 --- a/tests/phpunit/includes/GlobalFunctions/GlobalTest.php +++ b/tests/phpunit/includes/GlobalFunctions/GlobalTest.php @@ -32,7 +32,7 @@ class GlobalTest extends MediaWikiTestCase { /** @dataProvider provideForWfArrayDiff2 */ public function testWfArrayDiff2( $a, $b, $expected ) { $this->assertEquals( - wfArrayDiff2( $a, $b), $expected + wfArrayDiff2( $a, $b ), $expected ); } @@ -41,13 +41,13 @@ class GlobalTest extends MediaWikiTestCase { // $a $b $expected return array( array( - array( 'a', 'b'), - array( 'a', 'b'), + array( 'a', 'b' ), + array( 'a', 'b' ), array(), ), array( - array( array( 'a'), array( 'a', 'b', 'c' )), - array( array( 'a'), array( 'a', 'b' )), + array( array( 'a' ), array( 'a', 'b', 'c' ) ), + array( array( 'a' ), array( 'a', 'b' ) ), array( 1 => array( 'a', 'b', 'c' ) ), ), ); @@ -191,21 +191,21 @@ class GlobalTest extends MediaWikiTestCase { 'text/html', mimeTypeMatch( 'text/html', array( 'application/xhtml+xml' => 1.0, - 'text/html' => 0.7, - 'text/plain' => 0.3 ) ) ); + 'text/html' => 0.7, + 'text/plain' => 0.3 ) ) ); $this->assertEquals( 'text/*', mimeTypeMatch( 'text/html', array( 'image/*' => 1.0, - 'text/*' => 0.5 ) ) ); + 'text/*' => 0.5 ) ) ); $this->assertEquals( '*/*', mimeTypeMatch( 'text/html', array( '*/*' => 1.0 ) ) ); $this->assertNull( mimeTypeMatch( 'text/html', - array( 'image/png' => 1.0, - 'image/svg+xml' => 0.5 ) ) ); + array( 'image/png' => 1.0, + 'image/svg+xml' => 0.5 ) ) ); } function testNegotiateType() { @@ -213,51 +213,51 @@ class GlobalTest extends MediaWikiTestCase { 'text/html', wfNegotiateType( array( 'application/xhtml+xml' => 1.0, - 'text/html' => 0.7, - 'text/plain' => 0.5, - 'text/*' => 0.2 ), - array( 'text/html' => 1.0 ) ) ); + 'text/html' => 0.7, + 'text/plain' => 0.5, + 'text/*' => 0.2 ), + array( 'text/html' => 1.0 ) ) ); $this->assertEquals( 'application/xhtml+xml', wfNegotiateType( array( 'application/xhtml+xml' => 1.0, - 'text/html' => 0.7, - 'text/plain' => 0.5, - 'text/*' => 0.2 ), + 'text/html' => 0.7, + 'text/plain' => 0.5, + 'text/*' => 0.2 ), array( 'application/xhtml+xml' => 1.0, - 'text/html' => 0.5 ) ) ); + 'text/html' => 0.5 ) ) ); $this->assertEquals( 'text/html', wfNegotiateType( - array( 'text/html' => 1.0, - 'text/plain' => 0.5, - 'text/*' => 0.5, - 'application/xhtml+xml' => 0.2 ), + array( 'text/html' => 1.0, + 'text/plain' => 0.5, + 'text/*' => 0.5, + 'application/xhtml+xml' => 0.2 ), array( 'application/xhtml+xml' => 1.0, - 'text/html' => 0.5 ) ) ); + 'text/html' => 0.5 ) ) ); $this->assertEquals( 'text/html', wfNegotiateType( - array( 'text/*' => 1.0, - 'image/*' => 0.7, - '*/*' => 0.3 ), + array( 'text/*' => 1.0, + 'image/*' => 0.7, + '*/*' => 0.3 ), array( 'application/xhtml+xml' => 1.0, - 'text/html' => 0.5 ) ) ); + 'text/html' => 0.5 ) ) ); $this->assertNull( wfNegotiateType( - array( 'text/*' => 1.0 ), + array( 'text/*' => 1.0 ), array( 'application/xhtml+xml' => 1.0 ) ) ); } - + function testFallbackMbstringFunctions() { - - if( !extension_loaded( 'mbstring' ) ) { + + if ( !extension_loaded( 'mbstring' ) ) { $this->markTestSkipped( "The mb_string functions must be installed to test the fallback functions" ); } - + $sampleUTF = "Östergötland_coat_of_arms.png"; - - + + //mb_substr $substr_params = array( array( 0, 0 ), @@ -268,27 +268,27 @@ class GlobalTest extends MediaWikiTestCase { array( 1, 1 ), array( 2, -1 ) ); - - foreach( $substr_params as $param_set ) { + + foreach ( $substr_params as $param_set ) { $old_param_set = $param_set; array_unshift( $param_set, $sampleUTF ); - + $this->assertEquals( MWFunction::callArray( 'mb_substr', $param_set ), MWFunction::callArray( 'Fallback::mb_substr', $param_set ), 'Fallback mb_substr with params ' . implode( ', ', $old_param_set ) - ); + ); } - - + + //mb_strlen $this->assertEquals( mb_strlen( $sampleUTF ), Fallback::mb_strlen( $sampleUTF ), 'Fallback mb_strlen' - ); - - + ); + + //mb_str(r?)pos $strpos_params = array( //array( 'ter' ), @@ -298,24 +298,24 @@ class GlobalTest extends MediaWikiTestCase { //array( 'c', -10 ), //Broken for now ); - - foreach( $strpos_params as $param_set ) { + + foreach ( $strpos_params as $param_set ) { $old_param_set = $param_set; array_unshift( $param_set, $sampleUTF ); - + $this->assertEquals( MWFunction::callArray( 'mb_strpos', $param_set ), MWFunction::callArray( 'Fallback::mb_strpos', $param_set ), 'Fallback mb_strpos with params ' . implode( ', ', $old_param_set ) - ); - + ); + $this->assertEquals( MWFunction::callArray( 'mb_strrpos', $param_set ), MWFunction::callArray( 'Fallback::mb_strrpos', $param_set ), 'Fallback mb_strrpos with params ' . implode( ', ', $old_param_set ) - ); + ); } - + } @@ -347,7 +347,7 @@ class GlobalTest extends MediaWikiTestCase { $this->assertGreaterThan( 5000, preg_replace( '/\D/', '', file_get_contents( $wgDebugLogFile ) ) ); unlink( $wgDebugLogFile ); - wfDebugMem(true); + wfDebugMem( true ); $this->assertGreaterThan( 5000000, preg_replace( '/\D/', '', file_get_contents( $wgDebugLogFile ) ) ); unlink( $wgDebugLogFile ); @@ -357,7 +357,7 @@ class GlobalTest extends MediaWikiTestCase { } function testClientAcceptsGzipTest() { - + $settings = array( 'gzip' => true, 'bzip' => false, @@ -370,25 +370,24 @@ class GlobalTest extends MediaWikiTestCase { 'gzip;q=12345678.9' => true, ' gzip' => true, ); - - if( isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) $old_server_setting = $_SERVER['HTTP_ACCEPT_ENCODING']; - + + if ( isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) { + $old_server_setting = $_SERVER['HTTP_ACCEPT_ENCODING']; + } + foreach ( $settings as $encoding => $expect ) { $_SERVER['HTTP_ACCEPT_ENCODING'] = $encoding; - + $this->assertEquals( $expect, wfClientAcceptsGzip( true ), "'$encoding' => " . wfBoolToStr( $expect ) ); } - - if( isset( $old_server_setting ) ) $_SERVER['HTTP_ACCEPT_ENCODING'] = $old_server_setting; + if ( isset( $old_server_setting ) ) { + $_SERVER['HTTP_ACCEPT_ENCODING'] = $old_server_setting; + } } - - - - function testSwapVarsTest() { - + function testSwapVarsTest() { $var1 = 1; $var2 = 2; @@ -402,27 +401,29 @@ class GlobalTest extends MediaWikiTestCase { } - function testWfPercentTest() { $pcts = array( - array( 6/7, '0.86%', 2, false ), - array( 3/3, '1%' ), - array( 22/7, '3.14286%', 5 ), - array( 3/6, '0.5%' ), - array( 1/3, '0%', 0 ), - array( 10/3, '0%', -1 ), - array( 3/4/5, '0.1%', 1 ), - array( 6/7*8, '6.8571428571%', 10 ), + array( 6 / 7, '0.86%', 2, false ), + array( 3 / 3, '1%' ), + array( 22 / 7, '3.14286%', 5 ), + array( 3 / 6, '0.5%' ), + array( 1 / 3, '0%', 0 ), + array( 10 / 3, '0%', -1 ), + array( 3 / 4 / 5, '0.1%', 1 ), + array( 6 / 7 * 8, '6.8571428571%', 10 ), ); - - foreach( $pcts as $pct ) { - if( !isset( $pct[2] ) ) $pct[2] = 2; - if( !isset( $pct[3] ) ) $pct[3] = true; - + + foreach ( $pcts as $pct ) { + if ( !isset( $pct[2] ) ) { + $pct[2] = 2; + } + if ( !isset( $pct[3] ) ) { + $pct[3] = true; + } + $this->assertEquals( wfPercent( $pct[0], $pct[2], $pct[3] ), $pct[1], $pct[1] ); } - } /** @@ -432,47 +433,47 @@ class GlobalTest extends MediaWikiTestCase { public function testWfShorthandToInteger( $shorthand, $expected ) { $this->assertEquals( $expected, wfShorthandToInteger( $shorthand ) - ); + ); } /** array( shorthand, expected integer ) */ public static function provideShorthand() { return array( # Null, empty ... - array( '', -1), - array( ' ', -1), - array( null, -1), + array( '', -1 ), + array( ' ', -1 ), + array( null, -1 ), # Failures returns 0 :( array( 'ABCDEFG', 0 ), - array( 'Ak', 0 ), + array( 'Ak', 0 ), # Int, strings with spaces - array( 1, 1 ), - array( ' 1 ', 1 ), - array( 1023, 1023 ), + array( 1, 1 ), + array( ' 1 ', 1 ), + array( 1023, 1023 ), array( ' 1023 ', 1023 ), # kilo, Mega, Giga - array( '1k', 1024 ), - array( '1K', 1024 ), - array( '1m', 1024 * 1024 ), - array( '1M', 1024 * 1024 ), - array( '1g', 1024 * 1024 * 1024 ), - array( '1G', 1024 * 1024 * 1024 ), + array( '1k', 1024 ), + array( '1K', 1024 ), + array( '1m', 1024 * 1024 ), + array( '1M', 1024 * 1024 ), + array( '1g', 1024 * 1024 * 1024 ), + array( '1G', 1024 * 1024 * 1024 ), # Negatives - array( -1, -1 ), - array( -500, -500 ), - array( '-500', -500 ), - array( '-1k', -1024 ), + array( -1, -1 ), + array( -500, -500 ), + array( '-500', -500 ), + array( '-1k', -1024 ), # Zeroes - array( '0', 0 ), - array( '0k', 0 ), - array( '0M', 0 ), - array( '0G', 0 ), - array( '-0', 0 ), + array( '0', 0 ), + array( '0k', 0 ), + array( '0M', 0 ), + array( '0G', 0 ), + array( '-0', 0 ), array( '-0k', 0 ), array( '-0M', 0 ), array( '-0G', 0 ), @@ -499,7 +500,7 @@ class GlobalTest extends MediaWikiTestCase { $msg .= $expectedMergeResult ? 'success' : 'failure'; $this->assertEquals( $expectedMergeResult, $isMerged, $msg ); - if( $isMerged ) { + if ( $isMerged ) { // Verify the merged text $this->assertEquals( $expectedText, $mergedText, 'is merged text as expected?' ); @@ -511,31 +512,30 @@ class GlobalTest extends MediaWikiTestCase { $EXPECT_MERGE_FAILURE = false; return array( - // #0: clean merge array( // old: "one one one\n" . // trimmed - "\n" . - "two two two", + "\n" . + "two two two", // mine: "one one one ONE ONE\n" . - "\n" . - "two two two\n", // with tailing whitespace + "\n" . + "two two two\n", // with tailing whitespace // yours: "one one one\n" . - "\n" . - "two two TWO TWO", // trimmed + "\n" . + "two two TWO TWO", // trimmed // ok: $EXPECT_MERGE_SUCCESS, // result: "one one one ONE ONE\n" . - "\n" . - "two two TWO TWO\n", // note: will always end in a newline + "\n" . + "two two TWO TWO\n", // note: will always end in a newline ), // #1: conflict, fail @@ -545,14 +545,14 @@ class GlobalTest extends MediaWikiTestCase { // mine: "one one one ONE ONE\n" . - "\n" . - "bla bla\n" . - "\n", // with tailing whitespace + "\n" . + "bla bla\n" . + "\n", // with tailing whitespace // yours: "one one one\n" . - "\n" . - "two two", // trimmed + "\n" . + "two two", // trimmed $EXPECT_MERGE_FAILURE, @@ -618,7 +618,7 @@ class GlobalTest extends MediaWikiTestCase { ), ); } - + /** * @dataProvider provideWfMatchesDomainList */ @@ -626,7 +626,7 @@ class GlobalTest extends MediaWikiTestCase { $actual = wfMatchesDomainList( $url, $domains ); $this->assertEquals( $expected, $actual, $description ); } - + function provideWfMatchesDomainList() { $a = array(); $protocols = array( 'HTTP' => 'http:', 'HTTPS' => 'https:', 'protocol-relative' => '' ); @@ -638,7 +638,7 @@ class GlobalTest extends MediaWikiTestCase { array( "$p//www.example2.com", array( 'www.example.com', 'www.example2.com', 'www.example3.com' ), true, "Exact match with other domains in array, $pDesc URL" ), array( "$p//www.example2.com", array( 'example.com', 'example2.com', 'example3,com' ), true, "Match without subdomain with other domains in array, $pDesc URL" ), array( "$p//www.example4.com", array( 'example.com', 'example2.com', 'example3,com' ), false, "Domain not in array, $pDesc URL" ), - + // FIXME: This is a bug in wfMatchesDomainList(). If and when this is fixed, update this test case array( "$p//nds-nl.wikipedia.org", array( 'nl.wikipedia.org' ), true, "Substrings of domains match while they shouldn't, $pDesc URL" ), ) ); @@ -650,7 +650,7 @@ class GlobalTest extends MediaWikiTestCase { * @dataProvider provideWfShellMaintenanceCmdList */ function testWfShellMaintenanceCmd( $script, $parameters, $options, $expected, $description ) { - if( wfIsWindows() ) { + if ( wfIsWindows() ) { // Approximation that's good enough for our purposes just now $expected = str_replace( "'", '"', $expected ); } @@ -664,13 +664,13 @@ class GlobalTest extends MediaWikiTestCase { array( 'eval.php', array( '--help', '--test' ), array(), "'$wgPhpCli' 'eval.php' '--help' '--test'", "Called eval.php --help --test" ), - array( 'eval.php', array( '--help', '--test space' ), array('php' => 'php5'), + array( 'eval.php', array( '--help', '--test space' ), array( 'php' => 'php5' ), "'php5' 'eval.php' '--help' '--test space'", "Called eval.php --help --test with php option" ), - array( 'eval.php', array( '--help', '--test', 'X' ), array('wrapper' => 'MWScript.php'), + array( 'eval.php', array( '--help', '--test', 'X' ), array( 'wrapper' => 'MWScript.php' ), "'$wgPhpCli' 'MWScript.php' 'eval.php' '--help' '--test' 'X'", "Called eval.php --help --test with wrapper option" ), - array( 'eval.php', array( '--help', '--test', 'y' ), array('php' => 'php5', 'wrapper' => 'MWScript.php'), + array( 'eval.php', array( '--help', '--test', 'y' ), array( 'php' => 'php5', 'wrapper' => 'MWScript.php' ), "'php5' 'MWScript.php' 'eval.php' '--help' '--test' 'y'", "Called eval.php --help --test with wrapper and php option" ), ); diff --git a/tests/phpunit/includes/GlobalFunctions/wfAssembleUrlTest.php b/tests/phpunit/includes/GlobalFunctions/wfAssembleUrlTest.php index bed435a64f..21fff68403 100644 --- a/tests/phpunit/includes/GlobalFunctions/wfAssembleUrlTest.php +++ b/tests/phpunit/includes/GlobalFunctions/wfAssembleUrlTest.php @@ -83,7 +83,7 @@ class wfAssembleUrl extends MediaWikiTestCase { $parts['query'] = $query; $url .= '?' . $query; } - if( $fragment ) { + if ( $fragment ) { $parts['fragment'] = $fragment; $url .= '#' . $fragment; } diff --git a/tests/phpunit/includes/GlobalFunctions/wfBCP47Test.php b/tests/phpunit/includes/GlobalFunctions/wfBCP47Test.php index 4a0f406854..0b048b45c6 100644 --- a/tests/phpunit/includes/GlobalFunctions/wfBCP47Test.php +++ b/tests/phpunit/includes/GlobalFunctions/wfBCP47Test.php @@ -15,12 +15,12 @@ class wfBCP47 extends MediaWikiTestCase { */ function testBCP47( $code, $expected ) { $code = strtolower( $code ); - $this->assertEquals( $expected, wfBCP47($code), + $this->assertEquals( $expected, wfBCP47( $code ), "Applying BCP47 standard to lower case '$code'" ); $code = strtoupper( $code ); - $this->assertEquals( $expected, wfBCP47($code), + $this->assertEquals( $expected, wfBCP47( $code ), "Applying BCP47 standard to upper case '$code'" ); } @@ -32,15 +32,15 @@ class wfBCP47 extends MediaWikiTestCase { return array( // Extracted from BCP47 (list not exhaustive) # 2.1.1 - array( 'en-ca-x-ca' , 'en-CA-x-ca' ), - array( 'sgn-be-fr' , 'sgn-BE-FR' ), + array( 'en-ca-x-ca', 'en-CA-x-ca' ), + array( 'sgn-be-fr', 'sgn-BE-FR' ), array( 'az-latn-x-latn', 'az-Latn-x-latn' ), # 2.2 array( 'sr-Latn-RS', 'sr-Latn-RS' ), array( 'az-arab-ir', 'az-Arab-IR' ), # 2.2.5 - array( 'sl-nedis' , 'sl-nedis' ), + array( 'sl-nedis', 'sl-nedis' ), array( 'de-ch-1996', 'de-CH-1996' ), # 2.2.6 @@ -56,40 +56,40 @@ class wfBCP47 extends MediaWikiTestCase { array( 'ja', 'ja' ), # Language subtag plus script subtag: - array( 'zh-hans', 'zh-Hans'), - array( 'sr-cyrl', 'sr-Cyrl'), - array( 'sr-latn', 'sr-Latn'), + array( 'zh-hans', 'zh-Hans' ), + array( 'sr-cyrl', 'sr-Cyrl' ), + array( 'sr-latn', 'sr-Latn' ), # Extended language subtags and their primary language subtag # counterparts: array( 'zh-cmn-hans-cn', 'zh-cmn-Hans-CN' ), - array( 'cmn-hans-cn' , 'cmn-Hans-CN' ), - array( 'zh-yue-hk' , 'zh-yue-HK' ), - array( 'yue-hk' , 'yue-HK' ), + array( 'cmn-hans-cn', 'cmn-Hans-CN' ), + array( 'zh-yue-hk', 'zh-yue-HK' ), + array( 'yue-hk', 'yue-HK' ), # Language-Script-Region: array( 'zh-hans-cn', 'zh-Hans-CN' ), array( 'sr-latn-RS', 'sr-Latn-RS' ), # Language-Variant: - array( 'sl-rozaj' , 'sl-rozaj' ), + array( 'sl-rozaj', 'sl-rozaj' ), array( 'sl-rozaj-biske', 'sl-rozaj-biske' ), - array( 'sl-nedis' , 'sl-nedis' ), + array( 'sl-nedis', 'sl-nedis' ), # Language-Region-Variant: - array( 'de-ch-1901' , 'de-CH-1901' ), - array( 'sl-it-nedis' , 'sl-IT-nedis' ), + array( 'de-ch-1901', 'de-CH-1901' ), + array( 'sl-it-nedis', 'sl-IT-nedis' ), # Language-Script-Region-Variant: array( 'hy-latn-it-arevela', 'hy-Latn-IT-arevela' ), # Language-Region: - array( 'de-de' , 'de-DE' ), - array( 'en-us' , 'en-US' ), - array( 'es-419', 'es-419'), + array( 'de-de', 'de-DE' ), + array( 'en-us', 'en-US' ), + array( 'es-419', 'es-419' ), # Private use subtags: - array( 'de-ch-x-phonebk' , 'de-CH-x-phonebk' ), + array( 'de-ch-x-phonebk', 'de-CH-x-phonebk' ), array( 'az-arab-x-aze-derbend', 'az-Arab-x-aze-derbend' ), /** * Previous test does not reflect the BCP which states: @@ -102,7 +102,7 @@ class wfBCP47 extends MediaWikiTestCase { # Private use registry values: array( 'x-whatever', 'x-whatever' ), array( 'qaa-qaaa-qm-x-southern', 'qaa-Qaaa-QM-x-southern' ), - array( 'de-qaaa' , 'de-Qaaa' ), + array( 'de-qaaa', 'de-Qaaa' ), array( 'sr-latn-qm', 'sr-Latn-QM' ), array( 'sr-qaaa-rs', 'sr-Qaaa-RS' ), @@ -115,8 +115,8 @@ class wfBCP47 extends MediaWikiTestCase { // de-419-DE // a-DE // ar-a-aaa-b-bbb-a-ccc - - /* + + /* // ISO 15924 : array( 'sr-Cyrl', 'sr-Cyrl' ), # @todo FIXME: Fix our function? @@ -128,6 +128,7 @@ class wfBCP47 extends MediaWikiTestCase { array( 'uS', 'us' ), # USA array( 'Fr', 'fr' ), # France array( 'va', 'va' ), # Holy See (Vatican City State) - */); + */ + ); } } diff --git a/tests/phpunit/includes/GlobalFunctions/wfBaseConvertTest.php b/tests/phpunit/includes/GlobalFunctions/wfBaseConvertTest.php index 21e50328b8..1731fa0c21 100644 --- a/tests/phpunit/includes/GlobalFunctions/wfBaseConvertTest.php +++ b/tests/phpunit/includes/GlobalFunctions/wfBaseConvertTest.php @@ -142,13 +142,13 @@ class wfBaseConvertTest extends MediaWikiTestCase { public static function provideNumbers() { $x = array(); $chars = '0123456789abcdefghijklmnopqrstuvwxyz'; - for( $i = 0; $i < 50; $i++ ) { + for ( $i = 0; $i < 50; $i++ ) { $base = mt_rand( 2, 36 ); $len = mt_rand( 10, 100 ); $str = ''; - for( $j = 0; $j < $len; $j++ ) { - $str .= $chars[mt_rand(0, $base - 1)]; + for ( $j = 0; $j < $len; $j++ ) { + $str .= $chars[mt_rand( 0, $base - 1 )]; } $x[] = array( $base, $str ); diff --git a/tests/phpunit/includes/GlobalFunctions/wfBaseNameTest.php b/tests/phpunit/includes/GlobalFunctions/wfBaseNameTest.php index 59954b235d..f90c8d0d07 100644 --- a/tests/phpunit/includes/GlobalFunctions/wfBaseNameTest.php +++ b/tests/phpunit/includes/GlobalFunctions/wfBaseNameTest.php @@ -8,9 +8,9 @@ class wfBaseName extends MediaWikiTestCase { */ function testBaseName( $fullpath, $basename ) { $this->assertEquals( $basename, wfBaseName( $fullpath ), - "wfBaseName('$fullpath') => '$basename'" ); + "wfBaseName('$fullpath') => '$basename'" ); } - + function providePaths() { return array( array( '', '' ), diff --git a/tests/phpunit/includes/GlobalFunctions/wfExpandUrlTest.php b/tests/phpunit/includes/GlobalFunctions/wfExpandUrlTest.php index cb6e6c4564..ac39c80c31 100644 --- a/tests/phpunit/includes/GlobalFunctions/wfExpandUrlTest.php +++ b/tests/phpunit/includes/GlobalFunctions/wfExpandUrlTest.php @@ -51,7 +51,7 @@ class wfExpandUrl extends MediaWikiTestCase { foreach ( $modes as $mode ) { $httpsMode = $mode == 'https'; foreach ( $servers as $serverDesc => $server ) { - foreach ( $modes as $canServerMode ) { + foreach ( $modes as $canServerMode ) { $canServer = "$canServerMode://example2.com"; foreach ( $defaultProtos as $protoDesc => $defaultProto ) { $retval[] = array( diff --git a/tests/phpunit/includes/GlobalFunctions/wfGetCallerTest.php b/tests/phpunit/includes/GlobalFunctions/wfGetCallerTest.php index 15f3507027..3b4ac650b1 100644 --- a/tests/phpunit/includes/GlobalFunctions/wfGetCallerTest.php +++ b/tests/phpunit/includes/GlobalFunctions/wfGetCallerTest.php @@ -15,8 +15,9 @@ class wfGetCaller extends MediaWikiTestCase { } function intermediateFunction( $level = 2, $n = 0 ) { - if ( $n > 0 ) + if ( $n > 0 ) { return self::intermediateFunction( $level, $n - 1 ); + } return wfGetCaller( $level ); } @@ -28,7 +29,7 @@ class wfGetCaller extends MediaWikiTestCase { $this->assertEquals( "wfGetCaller::testN", self::intermediateFunction( 2, 0 ) ); $this->assertEquals( "wfGetCaller::intermediateFunction", self::intermediateFunction( 1, 0 ) ); - for ($i=0; $i < 10; $i++) + for ( $i = 0; $i < 10; $i++ ) $this->assertEquals( "wfGetCaller::intermediateFunction", self::intermediateFunction( $i + 1, $i ) ); } } diff --git a/tests/phpunit/includes/GlobalFunctions/wfShorthandToIntegerTest.php b/tests/phpunit/includes/GlobalFunctions/wfShorthandToIntegerTest.php index 1df26d2cb8..da6c936460 100644 --- a/tests/phpunit/includes/GlobalFunctions/wfShorthandToIntegerTest.php +++ b/tests/phpunit/includes/GlobalFunctions/wfShorthandToIntegerTest.php @@ -24,5 +24,5 @@ class wfShorthandToIntegerTest extends MediaWikiTestCase { array( '1k', 1024, 'One kb lowercased' ), ); } - + } diff --git a/tests/phpunit/includes/GlobalFunctions/wfTimestampTest.php b/tests/phpunit/includes/GlobalFunctions/wfTimestampTest.php index 505c28c79a..5fd0ed000f 100644 --- a/tests/phpunit/includes/GlobalFunctions/wfTimestampTest.php +++ b/tests/phpunit/includes/GlobalFunctions/wfTimestampTest.php @@ -13,7 +13,7 @@ class wfTimestamp extends MediaWikiTestCase { function provideNormalTimestamps() { $t = gmmktime( 12, 34, 56, 1, 15, 2001 ); - return array ( + return array( // TS_UNIX array( $t, TS_MW, '20010115123456', 'TS_UNIX to TS_MW' ), array( -30281104, TS_MW, '19690115123456', 'Negative TS_UNIX to TS_MW' ), @@ -21,13 +21,13 @@ class wfTimestamp extends MediaWikiTestCase { array( $t, TS_DB, '2001-01-15 12:34:56', 'TS_UNIX to TS_DB' ), array( $t, TS_ISO_8601_BASIC, '20010115T123456Z', 'TS_ISO_8601_BASIC to TS_DB' ), - + // TS_MW array( '20010115123456', TS_MW, '20010115123456', 'TS_MW to TS_MW' ), array( '20010115123456', TS_UNIX, 979562096, 'TS_MW to TS_UNIX' ), array( '20010115123456', TS_DB, '2001-01-15 12:34:56', 'TS_MW to TS_DB' ), array( '20010115123456', TS_ISO_8601_BASIC, '20010115T123456Z', 'TS_MW to TS_ISO_8601_BASIC' ), - + // TS_DB array( '2001-01-15 12:34:56', TS_MW, '20010115123456', 'TS_DB to TS_MW' ), array( '2001-01-15 12:34:56', TS_UNIX, 979562096, 'TS_DB to TS_UNIX' ), @@ -62,7 +62,7 @@ class wfTimestamp extends MediaWikiTestCase { } function provideOldTimestamps() { - return array ( + return array( array( '19011213204554', TS_RFC2822, 'Fri, 13 Dec 1901 20:45:54 GMT', 'Earliest time according to php documentation' ), array( '20380119031407', TS_RFC2822, 'Tue, 19 Jan 2038 03:14:07 GMT', 'Latest 32 bit time' ), array( '19011213204552', TS_UNIX, '-2147483648', 'Earliest 32 bit unix time' ), diff --git a/tests/phpunit/includes/GlobalFunctions/wfUrlencodeTest.php b/tests/phpunit/includes/GlobalFunctions/wfUrlencodeTest.php index 673702e5f1..285a2d6fce 100644 --- a/tests/phpunit/includes/GlobalFunctions/wfUrlencodeTest.php +++ b/tests/phpunit/includes/GlobalFunctions/wfUrlencodeTest.php @@ -6,9 +6,8 @@ */ class wfUrlencodeTest extends MediaWikiTestCase { - #### TESTS ############################################################## - + /** @dataProvider provideURLS */ public function testEncodingUrlWith( $input, $expected ) { $this->verifyEncodingFor( 'Apache', $input, $expected ); @@ -20,7 +19,7 @@ class wfUrlencodeTest extends MediaWikiTestCase { } #### HELPERS ############################################################# - + /** * Internal helper that actually run the test. * Called by the public methods testEncodingUrlWith...() @@ -30,10 +29,9 @@ class wfUrlencodeTest extends MediaWikiTestCase { $expected = $this->extractExpect( $server, $expectations ); // save up global - $old = isset($_SERVER['SERVER_SOFTWARE']) + $old = isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] - : null - ; + : null; $_SERVER['SERVER_SOFTWARE'] = $server; wfUrlencode( null ); @@ -45,7 +43,7 @@ class wfUrlencodeTest extends MediaWikiTestCase { ); // restore global - if( $old === null ) { + if ( $old === null ) { unset( $_SERVER['SERVER_SOFTWARE'] ); } else { $_SERVER['SERVER_SOFTWARE'] = $old; @@ -58,19 +56,18 @@ class wfUrlencodeTest extends MediaWikiTestCase { * the HTTP server name. */ private function extractExpect( $server, $expectations ) { - if( is_string( $expectations ) ) { + if ( is_string( $expectations ) ) { return $expectations; - } elseif( is_array( $expectations ) ) { - if( !array_key_exists( $server, $expectations ) ) { + } elseif ( is_array( $expectations ) ) { + if ( !array_key_exists( $server, $expectations ) ) { throw new MWException( __METHOD__ . " expectation does not have any value for server name $server. Check the provider array.\n" ); } else { return $expectations[$server]; } - } else { + } else { throw new MWException( __METHOD__ . " given invalid expectation for '$server'. Should be a string or an array( => ).\n" ); - } - } - + } + } #### PROVIDERS ########################################################### @@ -83,11 +80,11 @@ class wfUrlencodeTest extends MediaWikiTestCase { * array( 'Microsoft-IIS/7', 'expected' ), * ), * If you want to add other HTTP server name, you will have to add a new - * testing method much like the testEncodingUrlWith() method above. + * testing method much like the testEncodingUrlWith() method above. */ public static function provideURLS() { return array( - ### RFC 1738 chars + ### RFC 1738 chars // + is not safe array( '+', '%2B' ), // & and = not safe in queries @@ -95,7 +92,7 @@ class wfUrlencodeTest extends MediaWikiTestCase { array( '=', '%3D' ), array( ':', array( - 'Apache' => ':', + 'Apache' => ':', 'Microsoft-IIS/7' => '%3A', ) ), @@ -105,10 +102,10 @@ class wfUrlencodeTest extends MediaWikiTestCase { ';@$-_.!*', ), - ### Other tests + ### Other tests // slash remain unchanged. %2F seems to break things array( '/', '/' ), - + // Other 'funnies' chars array( '[]', '%5B%5D' ), array( '<>', '%3C%3E' ), diff --git a/tests/phpunit/includes/HtmlTest.php b/tests/phpunit/includes/HtmlTest.php index 32b791e35e..b6e23abf9e 100644 --- a/tests/phpunit/includes/HtmlTest.php +++ b/tests/phpunit/includes/HtmlTest.php @@ -15,22 +15,22 @@ class HtmlTest extends MediaWikiTestCase { $langObj->setNamespaces( array( -2 => 'Media', -1 => 'Special', - 0 => '', - 1 => 'Talk', - 2 => 'User', - 3 => 'User_talk', - 4 => 'MyWiki', - 5 => 'MyWiki_Talk', - 6 => 'File', - 7 => 'File_talk', - 8 => 'MediaWiki', - 9 => 'MediaWiki_talk', - 10 => 'Template', - 11 => 'Template_talk', - 14 => 'Category', - 15 => 'Category_talk', - 100 => 'Custom', - 101 => 'Custom_talk', + 0 => '', + 1 => 'Talk', + 2 => 'User', + 3 => 'User_talk', + 4 => 'MyWiki', + 5 => 'MyWiki_Talk', + 6 => 'File', + 7 => 'File_talk', + 8 => 'MediaWiki', + 9 => 'MediaWiki_talk', + 10 => 'Template', + 11 => 'Template_talk', + 14 => 'Category', + 15 => 'Category_talk', + 100 => 'Custom', + 101 => 'Custom_talk', ) ); $this->setMwGlobals( array( @@ -248,12 +248,12 @@ class HtmlTest extends MediaWikiTestCase { 'one' => 1, # Method use isset() internally, make sure we do discard - # attributes values which have been assigned well known values + # attributes values which have been assigned well known values 'emptystring' => '', 'boolfalse' => false, 'zero' => 0, 'null' => null, - ))) + ) ) ) ); } @@ -271,55 +271,55 @@ class HtmlTest extends MediaWikiTestCase { 'GREEN', 'GREEN' => false, 'GREEN', - ))) + ) ) ) ); } function testNamespaceSelector() { $this->assertEquals( '', + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '', Html::namespaceSelector(), 'Basic namespace selector without custom options' ); $this->assertEquals( ' ' . -'', + '', Html::namespaceSelector( array( 'selected' => '2', 'all' => 'all', 'label' => 'Select a namespace:' ), array( 'name' => 'wpNamespace', 'id' => 'mw-test-namespace' ) @@ -329,24 +329,24 @@ class HtmlTest extends MediaWikiTestCase { $this->assertEquals( ' ' . -'', + '', Html::namespaceSelector( array( 'label' => 'Select a namespace:' ) ), @@ -356,19 +356,19 @@ class HtmlTest extends MediaWikiTestCase { function testCanFilterOutNamespaces() { $this->assertEquals( -'', + '', Html::namespaceSelector( array( 'exclude' => array( 0, 1, 3, 100, 101 ) ) ), @@ -378,24 +378,24 @@ class HtmlTest extends MediaWikiTestCase { function testCanDisableANamespaces() { $this->assertEquals( -'', + '', Html::namespaceSelector( array( 'disable' => array( 0, 1, 2, 3, 4 ) ) ), @@ -435,7 +435,7 @@ class HtmlTest extends MediaWikiTestCase { 'color', ); $cases = array(); - foreach( $types as $type ) { + foreach ( $types as $type ) { $cases[] = array( $type ); } return $cases; @@ -595,7 +595,7 @@ class HtmlTest extends MediaWikiTestCase { # Craft the Html elements $ret = array(); - foreach( $cases as $case ) { + foreach ( $cases as $case ) { $ret[] = array( $case[0], $case[1], $case[2], diff --git a/tests/phpunit/includes/HttpTest.php b/tests/phpunit/includes/HttpTest.php index 92a1c9c14b..7698776c74 100644 --- a/tests/phpunit/includes/HttpTest.php +++ b/tests/phpunit/includes/HttpTest.php @@ -19,10 +19,10 @@ class HttpTest extends MediaWikiTestCase { public static function cookieDomains() { return array( - array( false, "org"), - array( false, ".org"), - array( true, "wikipedia.org"), - array( true, ".wikipedia.org"), + array( false, "org" ), + array( false, ".org" ), + array( true, "wikipedia.org" ), + array( true, ".wikipedia.org" ), array( false, "co.uk" ), array( false, ".co.uk" ), array( false, "gov.uk" ), @@ -68,26 +68,26 @@ class HttpTest extends MediaWikiTestCase { array( false, '¿non sens before!! http://a', 'Allow anything before URI' ), # (http|https) - only two schemes allowed - array( true, 'http://www.example.org/' ), - array( true, 'https://www.example.org/' ), - array( true, 'http://www.example.org', 'URI without directory' ), - array( true, 'http://a', 'Short name' ), - array( true, 'http://étoile', 'Allow UTF-8 in hostname' ), # 'étoile' is french for 'star' + array( true, 'http://www.example.org/' ), + array( true, 'https://www.example.org/' ), + array( true, 'http://www.example.org', 'URI without directory' ), + array( true, 'http://a', 'Short name' ), + array( true, 'http://étoile', 'Allow UTF-8 in hostname' ), # 'étoile' is french for 'star' array( false, '\\host\directory', 'CIFS share' ), array( false, 'gopher://host/dir', 'Reject gopher scheme' ), array( false, 'telnet://host', 'Reject telnet scheme' ), # :\/\/ - double slashes - array( false, 'http//example.org', 'Reject missing colon in protocol' ), - array( false, 'http:/example.org', 'Reject missing slash in protocol' ), - array( false, 'http:example.org', 'Must have two slashes' ), + array( false, 'http//example.org', 'Reject missing colon in protocol' ), + array( false, 'http:/example.org', 'Reject missing slash in protocol' ), + array( false, 'http:example.org', 'Must have two slashes' ), # Following fail since hostname can be made of anything - array( false, 'http:///example.org', 'Must have exactly two slashes, not three' ), + array( false, 'http:///example.org', 'Must have exactly two slashes, not three' ), # (\w+:{0,1}\w*@)? - optional user:pass - array( true, 'http://user@host', 'Username provided' ), - array( true, 'http://user:@host', 'Username provided, no password' ), - array( true, 'http://user:pass@host', 'Username and password provided' ), + array( true, 'http://user@host', 'Username provided' ), + array( true, 'http://user:@host', 'Username provided, no password' ), + array( true, 'http://user:pass@host', 'Username and password provided' ), # (\S+) - host part is made of anything not whitespaces array( false, 'http://!"èèè¿¿¿~~\'', 'hostname is made of any non whitespace' ), @@ -115,7 +115,7 @@ class HttpTest extends MediaWikiTestCase { array( true, 'http://example/&' ), # Fragment - array( true, 'http://exam#ple.org', ), # This one is valid, really! + array( true, 'http://exam#ple.org', ), # This one is valid, really! array( true, 'http://example.org:80#anchor' ), array( true, 'http://example.org/?id#anchor' ), array( true, 'http://example.org/?#anchor' ), @@ -126,7 +126,7 @@ class HttpTest extends MediaWikiTestCase { /** * Warning: - * + * * These tests are for code that makes use of an artifact of how CURL * handles header reporting on redirect pages, and will need to be * rewritten when bug 29232 is taken care of (high-level handling of @@ -137,8 +137,8 @@ class HttpTest extends MediaWikiTestCase { # Forge a Location header $h->setRespHeaders( 'location', array( - 'http://newsite/file.ext', - '/newfile.ext', + 'http://newsite/file.ext', + '/newfile.ext', ) ); # Verify we correctly fix the Location @@ -149,7 +149,7 @@ class HttpTest extends MediaWikiTestCase { ); $h->setRespHeaders( 'location', array( - 'https://oldsite/file.ext' + 'https://oldsite/file.ext' ) ); $this->assertEquals( @@ -159,14 +159,14 @@ class HttpTest extends MediaWikiTestCase { ); $h->setRespHeaders( 'location', array( - '/anotherfile.ext', - 'http://anotherfile/hoster.ext', - 'https://anotherfile/hoster.ext' + '/anotherfile.ext', + 'http://anotherfile/hoster.ext', + 'https://anotherfile/hoster.ext' ) ); $this->assertEquals( 'https://anotherfile/hoster.ext', - $h->getFinalUrl( "Relative file path Location: should keep the latest host and scheme!") + $h->getFinalUrl( "Relative file path Location: should keep the latest host and scheme!" ) ); } } @@ -183,10 +183,10 @@ class MWHttpRequestTester extends MWHttpRequest { Http::$httpEngine = function_exists( 'curl_init' ) ? 'curl' : 'php'; } elseif ( Http::$httpEngine == 'curl' && !function_exists( 'curl_init' ) ) { throw new MWException( __METHOD__ . ': curl (http://php.net/curl) is not installed, but' . - 'Http::$httpEngine is set to "curl"' ); + 'Http::$httpEngine is set to "curl"' ); } - switch( Http::$httpEngine ) { + switch ( Http::$httpEngine ) { case 'curl': return new CurlHttpRequestTester( $url, $options ); case 'php': diff --git a/tests/phpunit/includes/IPTest.php b/tests/phpunit/includes/IPTest.php index 5284812bbb..7bc2938521 100644 --- a/tests/phpunit/includes/IPTest.php +++ b/tests/phpunit/includes/IPTest.php @@ -11,13 +11,13 @@ class IPTest extends MediaWikiTestCase { */ public function testisIPAddress() { $this->assertFalse( IP::isIPAddress( false ), 'Boolean false is not an IP' ); - $this->assertFalse( IP::isIPAddress( true ), 'Boolean true is not an IP' ); + $this->assertFalse( IP::isIPAddress( true ), 'Boolean true is not an IP' ); $this->assertFalse( IP::isIPAddress( "" ), 'Empty string is not an IP' ); $this->assertFalse( IP::isIPAddress( 'abc' ), 'Garbage IP string' ); $this->assertFalse( IP::isIPAddress( ':' ), 'Single ":" is not an IP' ); - $this->assertFalse( IP::isIPAddress( '2001:0DB8::A:1::1'), 'IPv6 with a double :: occurrence' ); - $this->assertFalse( IP::isIPAddress( '2001:0DB8::A:1::'), 'IPv6 with a double :: occurrence, last at end' ); - $this->assertFalse( IP::isIPAddress( '::2001:0DB8::5:1'), 'IPv6 with a double :: occurrence, firt at beginning' ); + $this->assertFalse( IP::isIPAddress( '2001:0DB8::A:1::1' ), 'IPv6 with a double :: occurrence' ); + $this->assertFalse( IP::isIPAddress( '2001:0DB8::A:1::' ), 'IPv6 with a double :: occurrence, last at end' ); + $this->assertFalse( IP::isIPAddress( '::2001:0DB8::5:1' ), 'IPv6 with a double :: occurrence, firt at beginning' ); $this->assertFalse( IP::isIPAddress( '124.24.52' ), 'IPv4 not enough quads' ); $this->assertFalse( IP::isIPAddress( '24.324.52.13' ), 'IPv4 out of range' ); $this->assertFalse( IP::isIPAddress( '.24.52.13' ), 'IPv4 starts with period' ); @@ -81,9 +81,9 @@ class IPTest extends MediaWikiTestCase { $this->assertTrue( IP::isIPv6( 'fc::100:a:d:1' ), 'IPv6 with "::" and 5 words' ); $this->assertTrue( IP::isIPv6( 'fc::100:a:d:1:e' ), 'IPv6 with "::" and 6 words' ); $this->assertTrue( IP::isIPv6( 'fc::100:a:d:1:e:ac' ), 'IPv6 with "::" and 7 words' ); - $this->assertTrue( IP::isIPv6( '2001::df'), 'IPv6 with "::" and 2 words' ); - $this->assertTrue( IP::isIPv6( '2001:5c0:1400:a::df'), 'IPv6 with "::" and 5 words' ); - $this->assertTrue( IP::isIPv6( '2001:5c0:1400:a::df:2'), 'IPv6 with "::" and 6 words' ); + $this->assertTrue( IP::isIPv6( '2001::df' ), 'IPv6 with "::" and 2 words' ); + $this->assertTrue( IP::isIPv6( '2001:5c0:1400:a::df' ), 'IPv6 with "::" and 5 words' ); + $this->assertTrue( IP::isIPv6( '2001:5c0:1400:a::df:2' ), 'IPv6 with "::" and 6 words' ); $this->assertFalse( IP::isIPv6( 'fc::100:a:d:1:e:ac:0' ), 'IPv6 with "::" and 8 words' ); $this->assertFalse( IP::isIPv6( 'fc::100:a:d:1:e:ac:0:1' ), 'IPv6 with 9 words' ); @@ -96,7 +96,7 @@ class IPTest extends MediaWikiTestCase { */ public function testisIPv4() { $this->assertFalse( IP::isIPv4( false ), 'Boolean false is not an IP' ); - $this->assertFalse( IP::isIPv4( true ), 'Boolean true is not an IP' ); + $this->assertFalse( IP::isIPv4( true ), 'Boolean true is not an IP' ); $this->assertFalse( IP::isIPv4( "" ), 'Empty string is not an IP' ); $this->assertFalse( IP::isIPv4( 'abc' ) ); $this->assertFalse( IP::isIPv4( ':' ) ); @@ -143,9 +143,9 @@ class IPTest extends MediaWikiTestCase { $this->assertTrue( IP::isValid( 'fc::100' ), 'IPv6 with "::" and 2 words' ); $this->assertTrue( IP::isValid( 'fc::100:a' ), 'IPv6 with "::" and 3 words' ); - $this->assertTrue( IP::isValid( '2001::df'), 'IPv6 with "::" and 2 words' ); - $this->assertTrue( IP::isValid( '2001:5c0:1400:a::df'), 'IPv6 with "::" and 5 words' ); - $this->assertTrue( IP::isValid( '2001:5c0:1400:a::df:2'), 'IPv6 with "::" and 6 words' ); + $this->assertTrue( IP::isValid( '2001::df' ), 'IPv6 with "::" and 2 words' ); + $this->assertTrue( IP::isValid( '2001:5c0:1400:a::df' ), 'IPv6 with "::" and 5 words' ); + $this->assertTrue( IP::isValid( '2001:5c0:1400:a::df:2' ), 'IPv6 with "::" and 6 words' ); $this->assertTrue( IP::isValid( 'fc::100:a:d:1' ), 'IPv6 with "::" and 5 words' ); $this->assertTrue( IP::isValid( 'fc::100:a:d:1:e:ac' ), 'IPv6 with "::" and 7 words' ); @@ -254,8 +254,8 @@ class IPTest extends MediaWikiTestCase { * @todo Most probably incomplete */ public function testSanitizeIP() { - $this->assertNull( IP::sanitizeIP('') ); - $this->assertNull( IP::sanitizeIP(' ') ); + $this->assertNull( IP::sanitizeIP( '' ) ); + $this->assertNull( IP::sanitizeIP( ' ' ) ); } /** @@ -264,7 +264,7 @@ class IPTest extends MediaWikiTestCase { */ public function testip2longWrapper() { // @todo FIXME: Add more tests ? - $this->assertEquals( pow(2,32) - 1, IP::toUnsigned( '255.255.255.255' ) ); + $this->assertEquals( pow( 2, 32 ) - 1, IP::toUnsigned( '255.255.255.255' ) ); $i = 'IN.VA.LI.D'; $this->assertFalse( IP::toUnSigned( $i ) ); } @@ -284,7 +284,7 @@ class IPTest extends MediaWikiTestCase { } // Private wrapper used to test CIDR Parsing. - private function assertFalseCIDR( $CIDR, $msg='' ) { + private function assertFalseCIDR( $CIDR, $msg = '' ) { $ff = array( false, false ); $this->assertEquals( $ff, IP::parseCIDR( $CIDR ), $msg ); } @@ -299,15 +299,15 @@ class IPTest extends MediaWikiTestCase { * @covers IP::hexToQuad */ public function testHexToQuad() { - $this->assertEquals( '0.0.0.1' , IP::hexToQuad( '00000001' ) ); - $this->assertEquals( '255.0.0.0' , IP::hexToQuad( 'FF000000' ) ); + $this->assertEquals( '0.0.0.1', IP::hexToQuad( '00000001' ) ); + $this->assertEquals( '255.0.0.0', IP::hexToQuad( 'FF000000' ) ); $this->assertEquals( '255.255.255.255', IP::hexToQuad( 'FFFFFFFF' ) ); - $this->assertEquals( '10.188.222.255' , IP::hexToQuad( '0ABCDEFF' ) ); + $this->assertEquals( '10.188.222.255', IP::hexToQuad( '0ABCDEFF' ) ); // hex not left-padded... - $this->assertEquals( '0.0.0.0' , IP::hexToQuad( '0' ) ); - $this->assertEquals( '0.0.0.1' , IP::hexToQuad( '1' ) ); - $this->assertEquals( '0.0.0.255' , IP::hexToQuad( 'FF' ) ); - $this->assertEquals( '0.0.255.0' , IP::hexToQuad( 'FF00' ) ); + $this->assertEquals( '0.0.0.0', IP::hexToQuad( '0' ) ); + $this->assertEquals( '0.0.0.1', IP::hexToQuad( '1' ) ); + $this->assertEquals( '0.0.0.255', IP::hexToQuad( 'FF' ) ); + $this->assertEquals( '0.0.255.0', IP::hexToQuad( 'FF00' ) ); } /** @@ -325,11 +325,11 @@ class IPTest extends MediaWikiTestCase { $this->assertEquals( 'FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF', IP::hexToOctet( 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' ) ); // hex not left-padded... - $this->assertEquals( '0:0:0:0:0:0:0:0' , IP::hexToOctet( '0' ) ); - $this->assertEquals( '0:0:0:0:0:0:0:1' , IP::hexToOctet( '1' ) ); - $this->assertEquals( '0:0:0:0:0:0:0:FF' , IP::hexToOctet( 'FF' ) ); - $this->assertEquals( '0:0:0:0:0:0:0:FFD0' , IP::hexToOctet( 'FFD0' ) ); - $this->assertEquals( '0:0:0:0:0:0:FA00:0' , IP::hexToOctet( 'FA000000' ) ); + $this->assertEquals( '0:0:0:0:0:0:0:0', IP::hexToOctet( '0' ) ); + $this->assertEquals( '0:0:0:0:0:0:0:1', IP::hexToOctet( '1' ) ); + $this->assertEquals( '0:0:0:0:0:0:0:FF', IP::hexToOctet( 'FF' ) ); + $this->assertEquals( '0:0:0:0:0:0:0:FFD0', IP::hexToOctet( 'FFD0' ) ); + $this->assertEquals( '0:0:0:0:0:0:FA00:0', IP::hexToOctet( 'FA000000' ) ); $this->assertEquals( '0:0:0:0:0:0:FCCF:FAFF', IP::hexToOctet( 'FCCFFAFF' ) ); } @@ -339,42 +339,41 @@ class IPTest extends MediaWikiTestCase { * @covers IP::parseCIDR */ function testCIDRParsing() { - $this->assertFalseCIDR( '192.0.2.0' , "missing mask" ); + $this->assertFalseCIDR( '192.0.2.0', "missing mask" ); $this->assertFalseCIDR( '192.0.2.0/', "missing bitmask" ); // Verify if statement - $this->assertFalseCIDR( '256.0.0.0/32', "invalid net" ); + $this->assertFalseCIDR( '256.0.0.0/32', "invalid net" ); $this->assertFalseCIDR( '192.0.2.0/AA', "mask not numeric" ); - $this->assertFalseCIDR( '192.0.2.0/-1', "mask < 0" ); - $this->assertFalseCIDR( '192.0.2.0/33', "mask > 32" ); + $this->assertFalseCIDR( '192.0.2.0/-1', "mask < 0" ); + $this->assertFalseCIDR( '192.0.2.0/33', "mask > 32" ); // Check internal logic # 0 mask always result in array(0,0) - $this->assertEquals( array( 0, 0 ), IP::parseCIDR('192.0.0.2/0') ); - $this->assertEquals( array( 0, 0 ), IP::parseCIDR('0.0.0.0/0') ); - $this->assertEquals( array( 0, 0 ), IP::parseCIDR('255.255.255.255/0') ); + $this->assertEquals( array( 0, 0 ), IP::parseCIDR( '192.0.0.2/0' ) ); + $this->assertEquals( array( 0, 0 ), IP::parseCIDR( '0.0.0.0/0' ) ); + $this->assertEquals( array( 0, 0 ), IP::parseCIDR( '255.255.255.255/0' ) ); // @todo FIXME: Add more tests. # This part test network shifting - $this->assertNet( '192.0.0.0' , '192.0.0.2/24' ); - $this->assertNet( '192.168.5.0', '192.168.5.13/24'); - $this->assertNet( '10.0.0.160' , '10.0.0.161/28' ); - $this->assertNet( '10.0.0.0' , '10.0.0.3/28' ); - $this->assertNet( '10.0.0.0' , '10.0.0.3/30' ); - $this->assertNet( '10.0.0.4' , '10.0.0.4/30' ); + $this->assertNet( '192.0.0.0', '192.0.0.2/24' ); + $this->assertNet( '192.168.5.0', '192.168.5.13/24' ); + $this->assertNet( '10.0.0.160', '10.0.0.161/28' ); + $this->assertNet( '10.0.0.0', '10.0.0.3/28' ); + $this->assertNet( '10.0.0.0', '10.0.0.3/30' ); + $this->assertNet( '10.0.0.4', '10.0.0.4/30' ); $this->assertNet( '172.17.32.0', '172.17.35.48/21' ); - $this->assertNet( '10.128.0.0' , '10.135.0.0/9' ); - $this->assertNet( '134.0.0.0' , '134.0.5.1/8' ); + $this->assertNet( '10.128.0.0', '10.135.0.0/9' ); + $this->assertNet( '134.0.0.0', '134.0.5.1/8' ); } - /** * @covers IP::canonicalize */ public function testIPCanonicalizeOnValidIp() { $this->assertEquals( '192.0.2.152', IP::canonicalize( '192.0.2.152' ), - 'Canonicalization of a valid IP returns it unchanged' ); + 'Canonicalization of a valid IP returns it unchanged' ); } /** @@ -406,26 +405,26 @@ class IPTest extends MediaWikiTestCase { /** Provider for testIPIsInRange() */ public static function provideIPsAndRanges() { - # Format: (expected boolean, address, range, optional message) + # Format: (expected boolean, address, range, optional message) return array( # IPv4 - array( true , '192.0.2.0' , '192.0.2.0/24', 'Network address' ), - array( true , '192.0.2.77' , '192.0.2.0/24', 'Simple address' ), - array( true , '192.0.2.255' , '192.0.2.0/24', 'Broadcast address' ), + array( true, '192.0.2.0', '192.0.2.0/24', 'Network address' ), + array( true, '192.0.2.77', '192.0.2.0/24', 'Simple address' ), + array( true, '192.0.2.255', '192.0.2.0/24', 'Broadcast address' ), - array( false, '0.0.0.0' , '192.0.2.0/24' ), - array( false, '255.255.255' , '192.0.2.0/24' ), + array( false, '0.0.0.0', '192.0.2.0/24' ), + array( false, '255.255.255', '192.0.2.0/24' ), # IPv6 - array( false, '::1' , '2001:DB8::/32' ), - array( false, '::' , '2001:DB8::/32' ), + array( false, '::1', '2001:DB8::/32' ), + array( false, '::', '2001:DB8::/32' ), array( false, 'FE80::1', '2001:DB8::/32' ), - array( true , '2001:DB8::' , '2001:DB8::/32' ), - array( true , '2001:0DB8::' , '2001:DB8::/32' ), - array( true , '2001:DB8::1' , '2001:DB8::/32' ), - array( true , '2001:0DB8::1', '2001:DB8::/32' ), - array( true , '2001:0DB8:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF', + array( true, '2001:DB8::', '2001:DB8::/32' ), + array( true, '2001:0DB8::', '2001:DB8::/32' ), + array( true, '2001:DB8::1', '2001:DB8::/32' ), + array( true, '2001:0DB8::1', '2001:DB8::/32' ), + array( true, '2001:0DB8:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF', '2001:DB8::/32' ), array( false, '2001:0DB8:F::', '2001:DB8::/96' ), diff --git a/tests/phpunit/includes/JsonTest.php b/tests/phpunit/includes/JsonTest.php index 9b508f7096..96a2ead528 100644 --- a/tests/phpunit/includes/JsonTest.php +++ b/tests/phpunit/includes/JsonTest.php @@ -1,25 +1,25 @@ assertNotEquals( - '\ud840\udc00', + $this->assertNotEquals( + '\ud840\udc00', strtolower( FormatJson::encode( "\xf0\xa0\x80\x80" ) ), 'Test encoding an broken json_encode character (U+20000)' ); } - + function testDecodeVarTypes() { - $this->assertInternalType( - 'object', + $this->assertInternalType( + 'object', FormatJson::decode( '{"Name": "Cheeso", "Rank": 7}' ), 'Default to object' ); - $this->assertInternalType( - 'array', + $this->assertInternalType( + 'array', FormatJson::decode( '{"Name": "Cheeso", "Rank": 7}', true ), 'Optional array' ); diff --git a/tests/phpunit/includes/LanguageConverterTest.php b/tests/phpunit/includes/LanguageConverterTest.php index eb8912d54c..d4d93b07ab 100644 --- a/tests/phpunit/includes/LanguageConverterTest.php +++ b/tests/phpunit/includes/LanguageConverterTest.php @@ -84,8 +84,8 @@ class LanguageConverterTest extends MediaWikiLangTestCase { $wgUser->setId( 1 ); $wgUser->mFrom = 'defaults'; $wgUser->mOptionsLoaded = true; - $wgUser->setOption( 'variant', 'tg-latn' ); // The user's data is ignored - // because the variant is set in the URL. + // The user's data is ignored because the variant is set in the URL. + $wgUser->setOption( 'variant', 'tg-latn' ); $this->assertEquals( 'tg', $this->lc->getPreferredVariant() ); } @@ -120,7 +120,7 @@ class TestConverter extends LanguageConverter { function loadDefaultTables() { $this->mTables = array( 'tg-latn' => new ReplacementArray( $this->table ), - 'tg' => new ReplacementArray() + 'tg' => new ReplacementArray() ); } diff --git a/tests/phpunit/includes/LicensesTest.php b/tests/phpunit/includes/LicensesTest.php index e467f3cdbc..212b3b3bf0 100644 --- a/tests/phpunit/includes/LicensesTest.php +++ b/tests/phpunit/includes/LicensesTest.php @@ -14,8 +14,8 @@ class LicensesTest extends MediaWikiTestCase { 'section' => 'description', 'id' => 'wpLicense', 'label' => 'A label text', # Note can't test label-message because $wgOut is not defined - 'name' => 'AnotherName', - 'licenses' => $str, + 'name' => 'AnotherName', + 'licenses' => $str, ) ); $this->assertThat( $lc, $this->isInstanceOf( 'Licenses' ) ); } diff --git a/tests/phpunit/includes/LinkerTest.php b/tests/phpunit/includes/LinkerTest.php index abb8374d1f..90de96da24 100644 --- a/tests/phpunit/includes/LinkerTest.php +++ b/tests/phpunit/includes/LinkerTest.php @@ -6,11 +6,11 @@ class LinkerTest extends MediaWikiLangTestCase { * @dataProvider provideCasesForUserLink * @cover Linker::userLink */ - function testUserLink( $expected, $userId, $userName, $altUserName = false, $msg='' ) { + function testUserLink( $expected, $userId, $userName, $altUserName = false, $msg = '' ) { $this->setMwGlobals( array( 'wgArticlePath' => '/wiki/$1', 'wgWellFormedXml' => true, - ) ); + ) ); $this->assertEquals( $expected, Linker::userLink( $userId, $userName, $altUserName, $msg ) diff --git a/tests/phpunit/includes/LocalFileTest.php b/tests/phpunit/includes/LocalFileTest.php index 7b64a33166..d6f0d2eeaa 100644 --- a/tests/phpunit/includes/LocalFileTest.php +++ b/tests/phpunit/includes/LocalFileTest.php @@ -13,13 +13,13 @@ class LocalFileTest extends MediaWikiTestCase { $this->setMwGlobals( 'wgCapitalLinks', true ); $info = array( - 'name' => 'test', - 'directory' => '/testdir', - 'url' => '/testurl', - 'hashLevels' => 2, + 'name' => 'test', + 'directory' => '/testdir', + 'url' => '/testurl', + 'hashLevels' => 2, 'transformVia404' => false, - 'backend' => new FSFileBackend( array( - 'name' => 'local-backend', + 'backend' => new FSFileBackend( array( + 'name' => 'local-backend', 'lockManager' => 'fsLockManager', 'containerPaths' => array( 'cont1' => "/testdir/local-backend/tempimages/cont1", diff --git a/tests/phpunit/includes/MWFunctionTest.php b/tests/phpunit/includes/MWFunctionTest.php index f7be59f601..6c17bf4856 100644 --- a/tests/phpunit/includes/MWFunctionTest.php +++ b/tests/phpunit/includes/MWFunctionTest.php @@ -1,27 +1,26 @@ assertEquals( + $this->assertEquals( call_user_func( array( 'MWFunctionTest', 'someMethod' ) ), MWFunction::call( 'MWFunctionTest::someMethod' ) ); - $this->assertEquals( + $this->assertEquals( call_user_func( array( 'MWFunctionTest', 'someMethod' ), 'foo', 'bar', 'baz' ), MWFunction::call( 'MWFunctionTest::someMethod', 'foo', 'bar', 'baz' ) ); - $this->assertEquals( + $this->assertEquals( call_user_func_array( array( 'MWFunctionTest', 'someMethod' ), array() ), MWFunction::callArray( 'MWFunctionTest::someMethod', array() ) ); - $this->assertEquals( + $this->assertEquals( call_user_func_array( array( 'MWFunctionTest', 'someMethod' ), array( 'foo', 'bar', 'baz' ) ), MWFunction::callArray( 'MWFunctionTest::someMethod', array( 'foo', 'bar', 'baz' ) ) ); } - + function testNewObjFunction() { $arg1 = 'Foo'; $arg2 = 'Bar'; @@ -31,36 +30,36 @@ class MWFunctionTest extends MediaWikiTestCase { $args = array( $arg1, $arg2, $arg3, $arg4 ); $newObject = new MWBlankClass( $arg1, $arg2, $arg3, $arg4 ); - $this->assertEquals( - MWFunction::newObj( 'MWBlankClass', $args )->args, + $this->assertEquals( + MWFunction::newObj( 'MWBlankClass', $args )->args, $newObject->args ); - $this->assertEquals( - MWFunction::newObj( 'MWBlankClass', $args, true )->args, + $this->assertEquals( + MWFunction::newObj( 'MWBlankClass', $args, true )->args, $newObject->args, 'Works even with PHP version < 5.1.3' ); } - + /** * @expectedException MWException */ function testCallingParentFails() { MWFunction::call( 'parent::foo' ); } - + /** * @expectedException MWException */ function testCallingSelfFails() { MWFunction::call( 'self::foo' ); } - + public static function someMethod() { return func_get_args(); } - + } class MWBlankClass { diff --git a/tests/phpunit/includes/MWNamespaceTest.php b/tests/phpunit/includes/MWNamespaceTest.php index d0b3814ba5..45f8dafc45 100644 --- a/tests/phpunit/includes/MWNamespaceTest.php +++ b/tests/phpunit/includes/MWNamespaceTest.php @@ -17,9 +17,9 @@ class MWNamespaceTest extends MediaWikiTestCase { $this->setMwGlobals( array( 'wgContentNamespaces' => array( NS_MAIN ), 'wgNamespacesWithSubpages' => array( - NS_TALK => true, - NS_USER => true, - NS_USER_TALK => true, + NS_TALK => true, + NS_USER => true, + NS_USER_TALK => true, ), 'wgCapitalLinks' => true, 'wgCapitalLinkOverrides' => array(), @@ -42,18 +42,18 @@ class MWNamespaceTest extends MediaWikiTestCase { */ public function testIsSubject() { // Special namespaces - $this->assertIsSubject( NS_MEDIA ); + $this->assertIsSubject( NS_MEDIA ); $this->assertIsSubject( NS_SPECIAL ); // Subject pages $this->assertIsSubject( NS_MAIN ); $this->assertIsSubject( NS_USER ); - $this->assertIsSubject( 100 ); # user defined + $this->assertIsSubject( 100 ); # user defined // Talk pages - $this->assertIsNotSubject( NS_TALK ); + $this->assertIsNotSubject( NS_TALK ); $this->assertIsNotSubject( NS_USER_TALK ); - $this->assertIsNotSubject( 101 ); # user defined + $this->assertIsNotSubject( 101 ); # user defined } /** @@ -62,18 +62,18 @@ class MWNamespaceTest extends MediaWikiTestCase { */ public function testIsTalk() { // Special namespaces - $this->assertIsNotTalk( NS_MEDIA ); + $this->assertIsNotTalk( NS_MEDIA ); $this->assertIsNotTalk( NS_SPECIAL ); // Subject pages - $this->assertIsNotTalk( NS_MAIN ); - $this->assertIsNotTalk( NS_USER ); - $this->assertIsNotTalk( 100 ); # user defined + $this->assertIsNotTalk( NS_MAIN ); + $this->assertIsNotTalk( NS_USER ); + $this->assertIsNotTalk( 100 ); # user defined // Talk pages - $this->assertIsTalk( NS_TALK ); + $this->assertIsTalk( NS_TALK ); $this->assertIsTalk( NS_USER_TALK ); - $this->assertIsTalk( 101 ); # user defined + $this->assertIsTalk( 101 ); # user defined } /** @@ -135,7 +135,7 @@ class MWNamespaceTest extends MediaWikiTestCase { * @expectedException MWException */ public function testGetAssociatedExceptionsForNsMedia() { - $this->assertNull( MWNamespace::getAssociated( NS_MEDIA ) ); + $this->assertNull( MWNamespace::getAssociated( NS_MEDIA ) ); } /** @@ -148,14 +148,14 @@ class MWNamespaceTest extends MediaWikiTestCase { /** * @todo Implement testExists(). */ -/* + /* public function testExists() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet. Rely on $wgCanonicalNamespaces.' ); } -*/ + */ /** * Test MWNamespace::equals @@ -189,7 +189,7 @@ class MWNamespaceTest extends MediaWikiTestCase { $this->assertSameSubject( NS_USER, NS_USER_TALK ); $this->assertDifferentSubject( NS_PROJECT, NS_TEMPLATE ); - $this->assertDifferentSubject( NS_SPECIAL, NS_MAIN ); + $this->assertDifferentSubject( NS_SPECIAL, NS_MAIN ); } public function testSpecialAndMediaAreDifferentSubjects() { @@ -207,56 +207,58 @@ class MWNamespaceTest extends MediaWikiTestCase { /** * @todo Implement testGetCanonicalNamespaces(). */ -/* + /* public function testGetCanonicalNamespaces() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet. Rely on $wgCanonicalNamespaces.' ); } -*/ + */ /** * @todo Implement testGetCanonicalName(). */ -/* - public function testGetCanonicalName() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet. Rely on $wgCanonicalNamespaces.' - ); - } -*/ + /* + public function testGetCanonicalName() { + // Remove the following lines when you implement this test. + $this->markTestIncomplete( + 'This test has not been implemented yet. Rely on $wgCanonicalNamespaces.' + ); + } + */ /** * @todo Implement testGetCanonicalIndex(). */ -/* + /* public function testGetCanonicalIndex() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet. Rely on $wgCanonicalNamespaces.' ); } -*/ + */ + /** * @todo Implement testGetValidNamespaces(). */ -/* + /* public function testGetValidNamespaces() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet. Rely on $wgCanonicalNamespaces.' ); } -*/ + */ + /** */ public function testCanTalk() { - $this->assertCanNotTalk( NS_MEDIA ); + $this->assertCanNotTalk( NS_MEDIA ); $this->assertCanNotTalk( NS_SPECIAL ); - $this->assertCanTalk( NS_MAIN ); - $this->assertCanTalk( NS_TALK ); - $this->assertCanTalk( NS_USER ); + $this->assertCanTalk( NS_MAIN ); + $this->assertCanTalk( NS_TALK ); + $this->assertCanTalk( NS_USER ); $this->assertCanTalk( NS_USER_TALK ); // User defined namespaces @@ -303,7 +305,7 @@ class MWNamespaceTest extends MediaWikiTestCase { public function testIsWatchable() { // Specials namespaces are not watchable - $this->assertIsNotWatchable( NS_MEDIA ); + $this->assertIsNotWatchable( NS_MEDIA ); $this->assertIsNotWatchable( NS_SPECIAL ); // Core defined namespaces are watchables @@ -319,7 +321,7 @@ class MWNamespaceTest extends MediaWikiTestCase { global $wgNamespacesWithSubpages; // Special namespaces: - $this->assertHasNotSubpages( NS_MEDIA ); + $this->assertHasNotSubpages( NS_MEDIA ); $this->assertHasNotSubpages( NS_SPECIAL ); // Namespaces without subpages @@ -332,8 +334,8 @@ class MWNamespaceTest extends MediaWikiTestCase { $this->assertHasNotSubpages( NS_MAIN ); // Some namespaces with subpages - $this->assertHasSubpages( NS_TALK ); - $this->assertHasSubpages( NS_USER ); + $this->assertHasSubpages( NS_TALK ); + $this->assertHasSubpages( NS_USER ); $this->assertHasSubpages( NS_USER_TALK ); } @@ -392,7 +394,7 @@ class MWNamespaceTest extends MediaWikiTestCase { */ public function testGetSubjectNamespaces() { $subjectsNS = MWNamespace::getSubjectNamespaces(); - $this->assertContains( NS_MAIN, $subjectsNS, + $this->assertContains( NS_MAIN, $subjectsNS, "Talk namespaces should have NS_MAIN" ); $this->assertNotContains( NS_TALK, $subjectsNS, "Talk namespaces should have NS_TALK" ); @@ -407,7 +409,7 @@ class MWNamespaceTest extends MediaWikiTestCase { */ public function testGetTalkNamespaces() { $talkNS = MWNamespace::getTalkNamespaces(); - $this->assertContains( NS_TALK, $talkNS, + $this->assertContains( NS_TALK, $talkNS, "Subject namespaces should have NS_TALK" ); $this->assertNotContains( NS_MAIN, $talkNS, "Subject namespaces should not have NS_MAIN" ); @@ -426,18 +428,18 @@ class MWNamespaceTest extends MediaWikiTestCase { // NS_MEDIA and NS_FILE are treated the same $this->assertEquals( MWNamespace::isCapitalized( NS_MEDIA ), - MWNamespace::isCapitalized( NS_FILE ), + MWNamespace::isCapitalized( NS_FILE ), 'NS_MEDIA and NS_FILE have same capitalization rendering' ); // Boths are capitalized by default $this->assertIsCapitalized( NS_MEDIA ); - $this->assertIsCapitalized( NS_FILE ); + $this->assertIsCapitalized( NS_FILE ); // Always capitalized namespaces // @see MWNamespace::$alwaysCapitalizedNamespaces - $this->assertIsCapitalized( NS_SPECIAL ); - $this->assertIsCapitalized( NS_USER ); + $this->assertIsCapitalized( NS_SPECIAL ); + $this->assertIsCapitalized( NS_USER ); $this->assertIsCapitalized( NS_MEDIAWIKI ); } @@ -456,18 +458,18 @@ class MWNamespaceTest extends MediaWikiTestCase { public function testIsCapitalizedWithWgCapitalLinks() { global $wgCapitalLinks; - $this->assertIsCapitalized( NS_PROJECT ); + $this->assertIsCapitalized( NS_PROJECT ); $this->assertIsCapitalized( NS_PROJECT_TALK ); $wgCapitalLinks = false; // hardcoded namespaces (see above function) are still capitalized: - $this->assertIsCapitalized( NS_SPECIAL ); - $this->assertIsCapitalized( NS_USER ); + $this->assertIsCapitalized( NS_SPECIAL ); + $this->assertIsCapitalized( NS_USER ); $this->assertIsCapitalized( NS_MEDIAWIKI ); // setting is correctly applied - $this->assertIsNotCapitalized( NS_PROJECT ); + $this->assertIsNotCapitalized( NS_PROJECT ); $this->assertIsNotCapitalized( NS_PROJECT_TALK ); } @@ -481,27 +483,27 @@ class MWNamespaceTest extends MediaWikiTestCase { global $wgCapitalLinkOverrides; // Test default settings - $this->assertIsCapitalized( NS_PROJECT ); + $this->assertIsCapitalized( NS_PROJECT ); $this->assertIsCapitalized( NS_PROJECT_TALK ); // hardcoded namespaces (see above function) are capitalized: - $this->assertIsCapitalized( NS_SPECIAL ); - $this->assertIsCapitalized( NS_USER ); + $this->assertIsCapitalized( NS_SPECIAL ); + $this->assertIsCapitalized( NS_USER ); $this->assertIsCapitalized( NS_MEDIAWIKI ); // Hardcoded namespaces remains capitalized - $wgCapitalLinkOverrides[NS_SPECIAL] = false; - $wgCapitalLinkOverrides[NS_USER] = false; + $wgCapitalLinkOverrides[NS_SPECIAL] = false; + $wgCapitalLinkOverrides[NS_USER] = false; $wgCapitalLinkOverrides[NS_MEDIAWIKI] = false; - $this->assertIsCapitalized( NS_SPECIAL ); - $this->assertIsCapitalized( NS_USER ); + $this->assertIsCapitalized( NS_SPECIAL ); + $this->assertIsCapitalized( NS_USER ); $this->assertIsCapitalized( NS_MEDIAWIKI ); $wgCapitalLinkOverrides[NS_PROJECT] = false; $this->assertIsNotCapitalized( NS_PROJECT ); - $wgCapitalLinkOverrides[NS_PROJECT] = true ; + $wgCapitalLinkOverrides[NS_PROJECT] = true; $this->assertIsCapitalized( NS_PROJECT ); unset( $wgCapitalLinkOverrides[NS_PROJECT] ); @@ -510,15 +512,14 @@ class MWNamespaceTest extends MediaWikiTestCase { public function testHasGenderDistinction() { // Namespaces with gender distinctions - $this->assertTrue( MWNamespace::hasGenderDistinction( NS_USER ) ); + $this->assertTrue( MWNamespace::hasGenderDistinction( NS_USER ) ); $this->assertTrue( MWNamespace::hasGenderDistinction( NS_USER_TALK ) ); // Other ones, "genderless" - $this->assertFalse( MWNamespace::hasGenderDistinction( NS_MEDIA ) ); + $this->assertFalse( MWNamespace::hasGenderDistinction( NS_MEDIA ) ); $this->assertFalse( MWNamespace::hasGenderDistinction( NS_SPECIAL ) ); - $this->assertFalse( MWNamespace::hasGenderDistinction( NS_MAIN ) ); - $this->assertFalse( MWNamespace::hasGenderDistinction( NS_TALK ) ); - + $this->assertFalse( MWNamespace::hasGenderDistinction( NS_MAIN ) ); + $this->assertFalse( MWNamespace::hasGenderDistinction( NS_TALK ) ); } public function testIsNonincludable() { @@ -533,25 +534,25 @@ class MWNamespaceTest extends MediaWikiTestCase { ####### HELPERS ########################################################### function __call( $method, $args ) { // Call the real method if it exists - if( method_exists($this, $method ) ) { + if ( method_exists( $this, $method ) ) { return $this->$method( $args ); } - if( preg_match( '/^assert(Has|Is|Can)(Not|)(Subject|Talk|Watchable|Content|Subpages|Capitalized)$/', $method, $m ) ) { + if ( preg_match( '/^assert(Has|Is|Can)(Not|)(Subject|Talk|Watchable|Content|Subpages|Capitalized)$/', $method, $m ) ) { # Interprets arguments: - $ns = $args[0]; - $msg = isset($args[1]) ? $args[1] : " dummy message"; + $ns = $args[0]; + $msg = isset( $args[1] ) ? $args[1] : " dummy message"; # Forge the namespace constant name: - if( $ns === 0 ) { + if ( $ns === 0 ) { $ns_name = "NS_MAIN"; } else { - $ns_name = "NS_" . strtoupper( MWNamespace::getCanonicalName( $ns ) ); + $ns_name = "NS_" . strtoupper( MWNamespace::getCanonicalName( $ns ) ); } # ... and the MWNamespace method name $nsMethod = strtolower( $m[1] ) . $m[3]; - $expect = ($m[2] === ''); + $expect = ( $m[2] === '' ); $expect_name = $expect ? 'TRUE' : 'FALSE'; return $this->assertEquals( $expect, @@ -566,6 +567,7 @@ class MWNamespaceTest extends MediaWikiTestCase { function assertSameSubject( $ns1, $ns2, $msg = '' ) { $this->assertTrue( MWNamespace::subjectEquals( $ns1, $ns2, $msg ) ); } + function assertDifferentSubject( $ns1, $ns2, $msg = '' ) { $this->assertFalse( MWNamespace::subjectEquals( $ns1, $ns2, $msg ) ); } diff --git a/tests/phpunit/includes/OutputPageTest.php b/tests/phpunit/includes/OutputPageTest.php index 8b68703f80..4084fb1799 100644 --- a/tests/phpunit/includes/OutputPageTest.php +++ b/tests/phpunit/includes/OutputPageTest.php @@ -26,7 +26,7 @@ class OutputPageTest extends MediaWikiTestCase { * * @param array $args key-value array of arguments as shown above */ - protected function assertTransformCssMediaCase($args) { + protected function assertTransformCssMediaCase( $args ) { $queryData = array(); if ( isset( $args['printableQuery'] ) ) { $queryData['printable'] = $args['printableQuery']; @@ -38,12 +38,12 @@ class OutputPageTest extends MediaWikiTestCase { $fauxRequest = new FauxRequest( $queryData, false ); $this->setMWGlobals( array( - 'wgRequest' => $fauxRequest, - 'wgHandheldForIPhone' => $args['handheldForIPhone'] + 'wgRequest' => $fauxRequest, + 'wgHandheldForIPhone' => $args['handheldForIPhone'] ) ); $actualReturn = OutputPage::transformCssMedia( $args['media'] ); - $this->assertSame( $args['expectedReturn'], $actualReturn, $args['message']); + $this->assertSame( $args['expectedReturn'], $actualReturn, $args['message'] ); } /** @@ -55,11 +55,11 @@ class OutputPageTest extends MediaWikiTestCase { * @param array $args key-value array of arguments as shown in assertTransformCssMediaCase. * Will be mutated. */ - protected function assertTransformCssMediaCaseWithBothHandheldForIPhone($args) { + protected function assertTransformCssMediaCaseWithBothHandheldForIPhone( $args ) { $message = $args['message']; - foreach( array( true, false ) as $handheldForIPhone ) { + foreach ( array( true, false ) as $handheldForIPhone ) { $args['handheldForIPhone'] = $handheldForIPhone; - $stringHandheldForIPhone = var_export($handheldForIPhone, true); + $stringHandheldForIPhone = var_export( $handheldForIPhone, true ); $args['message'] = "$message. \$wgHandheldForIPhone was $stringHandheldForIPhone"; $this->assertTransformCssMediaCase( $args ); } @@ -132,14 +132,14 @@ class OutputPageTest extends MediaWikiTestCase { * Tests handheld and wgHandheldForIPhone behavior */ public function testHandheld() { - $this->assertTransformCssMediaCaseWithBothHandheldForIPhone(array( + $this->assertTransformCssMediaCaseWithBothHandheldForIPhone( array( 'handheldQuery' => '1', 'media' => 'handheld', 'expectedReturn' => '', 'message' => 'On request with handheld querystring and media is handheld, returns empty string' ) ); - $this->assertTransformCssMediaCaseWithBothHandheldForIPhone(array( + $this->assertTransformCssMediaCaseWithBothHandheldForIPhone( array( 'handheldQuery' => '1', 'media' => 'screen', 'expectedReturn' => null, @@ -147,7 +147,7 @@ class OutputPageTest extends MediaWikiTestCase { ) ); // A bit counter-intuitively, $wgHandheldForIPhone should only matter if the query handheld is false or omitted - $this->assertTransformCssMediaCase(array( + $this->assertTransformCssMediaCase( array( 'handheldQuery' => '0', 'media' => 'screen', 'handheldForIPhone' => true, @@ -155,7 +155,7 @@ class OutputPageTest extends MediaWikiTestCase { 'message' => 'With $wgHandheldForIPhone true, screen media type is transformed' ) ); - $this->assertTransformCssMediaCase(array( + $this->assertTransformCssMediaCase( array( 'media' => 'handheld', 'handheldForIPhone' => true, 'expectedReturn' => 'handheld, only screen and (max-device-width: 480px)', diff --git a/tests/phpunit/includes/PathRouterTest.php b/tests/phpunit/includes/PathRouterTest.php index 910743e047..f24cbab324 100644 --- a/tests/phpunit/includes/PathRouterTest.php +++ b/tests/phpunit/includes/PathRouterTest.php @@ -8,7 +8,7 @@ class PathRouterTest extends MediaWikiTestCase { protected function setUp() { parent::setUp(); $router = new PathRouter; - $router->add("/wiki/$1"); + $router->add( "/wiki/$1" ); $this->basicRouter = $router; } @@ -25,17 +25,17 @@ class PathRouterTest extends MediaWikiTestCase { */ public function testLoose() { $router = new PathRouter; - $router->add("/"); # Should be the same as "/$1" + $router->add( "/" ); # Should be the same as "/$1" $matches = $router->parse( "/Foo" ); $this->assertEquals( $matches, array( 'title' => "Foo" ) ); $router = new PathRouter; - $router->add("/wiki"); # Should be the same as /wiki/$1 + $router->add( "/wiki" ); # Should be the same as /wiki/$1 $matches = $router->parse( "/wiki/Foo" ); $this->assertEquals( $matches, array( 'title' => "Foo" ) ); $router = new PathRouter; - $router->add("/wiki/"); # Should be the same as /wiki/$1 + $router->add( "/wiki/" ); # Should be the same as /wiki/$1 $matches = $router->parse( "/wiki/Foo" ); $this->assertEquals( $matches, array( 'title' => "Foo" ) ); } @@ -45,16 +45,16 @@ class PathRouterTest extends MediaWikiTestCase { */ public function testOrder() { $router = new PathRouter; - $router->add("/$1"); - $router->add("/a/$1"); - $router->add("/b/$1"); + $router->add( "/$1" ); + $router->add( "/a/$1" ); + $router->add( "/b/$1" ); $matches = $router->parse( "/a/Foo" ); $this->assertEquals( $matches, array( 'title' => "Foo" ) ); $router = new PathRouter; - $router->add("/b/$1"); - $router->add("/a/$1"); - $router->add("/$1"); + $router->add( "/b/$1" ); + $router->add( "/a/$1" ); + $router->add( "/$1" ); $matches = $router->parse( "/a/Foo" ); $this->assertEquals( $matches, array( 'title' => "Foo" ) ); } @@ -151,18 +151,18 @@ class PathRouterTest extends MediaWikiTestCase { $router->add( array( 'qwerty' => "/qwerty/$1" ), array( 'qwerty' => '$key' ) ); $router->add( "/$2/$1", array( 'restricted-to-y' => '$2' ), array( '$2' => 'y' ) ); - foreach( array( - "/Foo" => array( 'title' => "Foo" ), - "/Bar" => array( 'ping' => 'pong' ), - "/Baz" => array( 'marco' => 'polo' ), - "/asdf-foo" => array( 'title' => "qwerty-foo" ), - "/qwerty-bar" => array( 'title' => "asdf-bar" ), - "/a/Foo" => array( 'title' => "Foo" ), - "/asdf/Foo" => array( 'title' => "Foo" ), - "/qwerty/Foo" => array( 'title' => "Foo", 'qwerty' => 'qwerty' ), - "/baz/Foo" => array( 'title' => "Foo", 'unrestricted' => 'baz' ), - "/y/Foo" => array( 'title' => "Foo", 'restricted-to-y' => 'y' ), - ) as $path => $result ) { + foreach ( array( + "/Foo" => array( 'title' => "Foo" ), + "/Bar" => array( 'ping' => 'pong' ), + "/Baz" => array( 'marco' => 'polo' ), + "/asdf-foo" => array( 'title' => "qwerty-foo" ), + "/qwerty-bar" => array( 'title' => "asdf-bar" ), + "/a/Foo" => array( 'title' => "Foo" ), + "/asdf/Foo" => array( 'title' => "Foo" ), + "/qwerty/Foo" => array( 'title' => "Foo", 'qwerty' => 'qwerty' ), + "/baz/Foo" => array( 'title' => "Foo", 'unrestricted' => 'baz' ), + "/y/Foo" => array( 'title' => "Foo", 'restricted-to-y' => 'y' ), + ) as $path => $result ) { $this->assertEquals( $router->parse( $path ), $result ); } } diff --git a/tests/phpunit/includes/PreferencesTest.php b/tests/phpunit/includes/PreferencesTest.php index 5e546ce324..7aa3c4a47a 100644 --- a/tests/phpunit/includes/PreferencesTest.php +++ b/tests/phpunit/includes/PreferencesTest.php @@ -17,14 +17,14 @@ class PreferencesTest extends MediaWikiTestCase { $this->prefUsers['notauth'] ->setEmail( 'noauth@example.org' ); - $this->prefUsers['auth'] = new User; + $this->prefUsers['auth'] = new User; $this->prefUsers['auth'] ->setEmail( 'noauth@example.org' ); $this->prefUsers['auth'] ->setEmailAuthenticationTimestamp( 1330946623 ); $this->context = new RequestContext; - $this->context->setTitle( Title::newFromText('PreferencesTest') ); + $this->context->setTitle( Title::newFromText( 'PreferencesTest' ) ); } protected function setUp() { @@ -44,6 +44,7 @@ class PreferencesTest extends MediaWikiTestCase { ); $this->assertEquals( 'mw-email-none', $prefs['emailaddress']['cssclass'] ); } + /** * Placeholder to verify bug 34302 * @covers Preferences::profilePreferences @@ -55,6 +56,7 @@ class PreferencesTest extends MediaWikiTestCase { ); $this->assertEquals( 'mw-email-not-authenticated', $prefs['emailaddress']['cssclass'] ); } + /** * Placeholder to verify bug 34302 * @covers Preferences::profilePreferences diff --git a/tests/phpunit/includes/Providers.php b/tests/phpunit/includes/Providers.php index f451f8a0da..948b635461 100644 --- a/tests/phpunit/includes/Providers.php +++ b/tests/phpunit/includes/Providers.php @@ -13,7 +13,7 @@ class MediaWikiProvide { /* provide an array of numbers from 1 up to @param $num */ private static function createProviderUpTo( $num ) { $ret = array(); - for( $i=1; $i<=$num;$i++ ) { + for ( $i = 1; $i <= $num; $i++ ) { $ret[] = array( $i ); } return $ret; @@ -33,9 +33,9 @@ class MediaWikiProvide { $ret = array(); $months = self::Months(); - $days = self::Days(); - foreach( $months as $month) { - foreach( $days as $day ) { + $days = self::Days(); + foreach ( $months as $month ) { + foreach ( $days as $day ) { $ret[] = array( $day[0], $month[0] ); } } -- 2.20.1