1 of n.
Change-Id: I852729f08bbb0c5e39c2db44362ccdc7f59dcc08
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 {
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";
}
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(),
$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 ) );
}
// 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'] ) );
$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();
$this->runTests( $seleniumTestSuites );
- if ( $this->hasOption( 'stopserver' ) ) {
+ if ( $this->hasOption( 'stopserver' ) ) {
$this->stopServer();
}
}
public $regex = "";
private $savedGlobals = array();
+
/**
* Sets terminal colorization and diff/quick modes depending on OS and
* command-line options (--color and --quick).
$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;
}
}
$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'] );
$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',
)
) )
$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 {
static public function chomp( $s ) {
if ( substr( $s, -1 ) === "\n" ) {
return substr( $s, 0, -1 );
- }
- else {
+ } else {
return $s;
}
}
$this->teardownDatabase();
$this->recorder->report();
- } catch (DBError $e) {
+ } catch ( DBError $e ) {
echo $e->getMessage();
}
$this->recorder->end();
if ( isset( $opts['title'] ) ) {
$titleText = $opts['title'];
- }
- else {
+ } else {
$titleText = 'Parser test';
}
'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',
'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',
)
) )
'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(),
$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'
# 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 ) );
$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() {
$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()
$this->db->query( $sql );
}
- if ( $this->db->getType() == 'oracle' )
+ if ( $this->db->getType() == 'oracle' ) {
$this->db->query( 'BEGIN FILL_WIKI_INFO; END;' );
+ }
$this->teardownGlobals();
}
// 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",
);
self::deleteDirs(
- array (
+ array(
"$dir/3/3a",
"$dir/3",
"$dir/thumb/6/65",
$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
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 );
}
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];
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];
private function wellFormed( $text ) {
$html =
Sanitizer::hackDocType() .
- '<html>' .
- $text .
- '</html>';
+ '<html>' .
+ $text .
+ '</html>';
$parser = xml_parser_create( "UTF-8" );
static function dumpHook( $in, $argv ) {
return "<pre>\n" .
- var_export( $in, true ) . "\n" .
- var_export( $argv, true ) . "\n" .
- "</pre>";
+ var_export( $in, true ) . "\n" .
+ var_export( $argv, true ) . "\n" .
+ "</pre>";
}
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;
}
$parser->static_tag_buf = null;
return $tmp;
- } else
- // wtf?
+ } else { // wtf?
return
"\nCall this extension as <statictag>string</statictag> or as" .
" <statictag action=flush/>, not in any other way.\n" .
"text: " . var_export( $in, true ) . "\n" .
"argv: " . var_export( $argv, true ) . "\n";
+ }
}
}
# 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'] );
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() . ")" );
}
);
public function __construct() {
- foreach( self::$additionalOptions as $option => $default ) {
+ foreach ( self::$additionalOptions as $option => $default ) {
$this->longOptions[$option] = $option . 'Handler';
}
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.
# 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];
}
}
$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
parent::run( $result );
wfProfileOut( $logName );
- if( $needsResetDB ) {
+ if ( $needsResetDB ) {
wfProfileIn( $logName . ' (reset-db)' );
$this->resetDB();
wfProfileOut( $logName . ' (reset-db)' );
if ( $this->needsDB() && $this->db ) {
// Clean up open transactions
- while( $this->db->trxLevel() > 0 ) {
+ while ( $this->db->trxLevel() > 0 ) {
$this->db->rollback();
}
if ( $this->needsDB() && $this->db ) {
// Clean up open transactions
- while( $this->db->trxLevel() > 0 ) {
+ while ( $this->db->trxLevel() > 0 ) {
$this->db->rollback();
}
protected function setMwGlobals( $pairs, $value = null ) {
// Normalize (string, value) to an array
- if( is_string( $pairs ) ) {
+ if ( is_string( $pairs ) ) {
$pairs = array( $pairs => $value );
}
# 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
* 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__ );
}
}
);
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 ) );
}
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];
}
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 );
*/
protected function arrayWrap( array $elements ) {
return array_map(
- function( $element ) {
+ function ( $element ) {
return array( $element );
},
$elements
* @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 );
}
protected function objectAssociativeSort( array &$array ) {
uasort(
$array,
- function( $a, $b ) {
+ function ( $a, $b ) {
return serialize( $a ) > serialize( $b ) ? 1 : -1;
}
);
protected function assertTypeOrValue( $type, $actual, $value = false, $message = '' ) {
if ( $actual === $value ) {
$this->assertTrue( true, $message );
- }
- else {
+ } else {
$this->assertType( $type, $actual, $message );
}
}
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 );
}
}
$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 );
// 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;
$haveDiff3 = $wgDiff3 && file_exists( $wgDiff3 );
wfRestoreWarnings();
- if( !$haveDiff3 ) {
+ if ( !$haveDiff3 ) {
$this->markTestSkipped( "Skip test, since diff3 is not configured" );
}
}
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" );
}
*/
protected function checkPHPExtension( $extName ) {
$loaded = extension_loaded( $extName );
- if( ! $loaded ) {
+ if ( !$loaded ) {
$this->markTestSkipped( "PHP extension '$extName' is not loaded, skipping." );
}
return $loaded;
try {
call_user_func( $code );
- }
- catch ( Exception $pokemons ) {
+ } catch ( Exception $pokemons ) {
// Gotta Catch 'Em All!
}
$results = null;
$exitCode = null;
- exec($finder, $results, $exitCode);
+ exec( $finder, $results, $exitCode );
$this->assertEquals(
0,
array( $this, 'filterSuites' )
);
$strip = strlen( $rootPath ) - 1;
- foreach( $results as $k => $v) {
+ foreach ( $results as $k => $v ) {
$results[$k] = substr( $v, $strip );
}
$this->assertEquals(
// Output a notice when running with older versions of PHPUnit
if ( version_compare( PHPUnit_Runner_Version::id(), "3.6.7", "<" ) ) {
- echo <<<EOF
+ echo <<<EOF
********************************************************************************
These tests run best with version PHPUnit 3.6.7 or better. Earlier versions may
try {
$this->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() );
}
}
$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" );
$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 ) );
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 );
}
}
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" );
}
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()" );
}
$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 );
* @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 ) );
}
* 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 );
}
/**
}
public static function provideSectionEdit() {
- $text =
-'Intro
+ $text = 'Intro
== one ==
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";
);
// 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 );
* @dataProvider provideAutoMerge
*/
public function testAutoMerge( $baseUser, $text, $adamsEdit, $bertasEdit,
- $expectedCode, $expectedText, $message = null
+ $expectedCode, $expectedText, $message = null
) {
$this->checkHasDiff3();
);
$page = $this->assertEdit( 'EditPageTest_testAutoMerge', null,
- $baseUser, $baseEdit, null, null, __METHOD__ );
+ $baseUser, $baseEdit, null, null, __METHOD__ );
$this->forceRevisionDate( $page, '20120101000000' );
'wgAlwaysUseTidy' => false,
'wgCleanSignatures' => true,
) );
-
+
$this->options = ParserOptions::newFromUserAndLang( new User, $contLang );
$this->options->setTemplateCallback( array( __CLASS__, 'statelessFetchTemplate' ) );
$this->parser = new Parser;
function testBug8689() {
global $wgUser;
$longLine = '1.' . str_repeat( '1234567890', 100000 ) . "\n";
-
+
$t = Title::newFromText( 'Unit test' );
$options = ParserOptions::newFromUser( $wgUser );
$this->assertEquals( "<p>$longLine</p>",
$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( "<p>Test\nContent of <i>Template:Foo</i>\nContent of <i>Template:Bar</i>\n</p>", $parserOutput->getText() );
}
-
+
function testPreSaveTransform() {
global $wgUser;
$title = Title::newFromText( __FUNCTION__ );
$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 );
}
$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}} " ),
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}}<noinclude> censored</noinclude> information <!-- is very secret -->", $title, $this->options );
-
+
$this->assertEquals( "{{Foo}} information <!-- is very secret -->", $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,
*/
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 );
$result = $parserOutput->getCategoryLinks();
$this->assertEmpty( $result );
}
- }
+}
}
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()
);
$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()
);
* 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 );
}
}
/** @dataProvider provideForWfArrayDiff2 */
public function testWfArrayDiff2( $a, $b, $expected ) {
$this->assertEquals(
- wfArrayDiff2( $a, $b), $expected
+ wfArrayDiff2( $a, $b ), $expected
);
}
// $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' ) ),
),
);
'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() {
'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 ),
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' ),
//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 )
- );
+ );
}
-
+
}
$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 );
}
function testClientAcceptsGzipTest() {
-
+
$settings = array(
'gzip' => true,
'bzip' => false,
'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;
}
-
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] );
}
-
}
/**
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 ),
$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?' );
$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
// 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,
),
);
}
-
+
/**
* @dataProvider provideWfMatchesDomainList
*/
$actual = wfMatchesDomainList( $url, $domains );
$this->assertEquals( $expected, $actual, $description );
}
-
+
function provideWfMatchesDomainList() {
$a = array();
$protocols = array( 'HTTP' => 'http:', 'HTTPS' => 'https:', 'protocol-relative' => '' );
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" ),
) );
* @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 );
}
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" ),
);
$parts['query'] = $query;
$url .= '?' . $query;
}
- if( $fragment ) {
+ if ( $fragment ) {
$parts['fragment'] = $fragment;
$url .= '#' . $fragment;
}
*/
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'"
);
}
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
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:
# 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' ),
// de-419-DE
// a-DE
// ar-a-aaa-b-bbb-a-ccc
-
- /*
+
+ /*
// ISO 15924 :
array( 'sr-Cyrl', 'sr-Cyrl' ),
# @todo FIXME: Fix our function?
array( 'uS', 'us' ), # USA
array( 'Fr', 'fr' ), # France
array( 'va', 'va' ), # Holy See (Vatican City State)
- */);
+ */
+ );
}
}
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 );
*/
function testBaseName( $fullpath, $basename ) {
$this->assertEquals( $basename, wfBaseName( $fullpath ),
- "wfBaseName('$fullpath') => '$basename'" );
+ "wfBaseName('$fullpath') => '$basename'" );
}
-
+
function providePaths() {
return array(
array( '', '' ),
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(
}
function intermediateFunction( $level = 2, $n = 0 ) {
- if ( $n > 0 )
+ if ( $n > 0 ) {
return self::intermediateFunction( $level, $n - 1 );
+ }
return wfGetCaller( $level );
}
$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 ) );
}
}
array( '1k', 1024, 'One kb lowercased' ),
);
}
-
+
}
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' ),
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' ),
}
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' ),
*/
class wfUrlencodeTest extends MediaWikiTestCase {
-
#### TESTS ##############################################################
-
+
/** @dataProvider provideURLS */
public function testEncodingUrlWith( $input, $expected ) {
$this->verifyEncodingFor( 'Apache', $input, $expected );
}
#### HELPERS #############################################################
-
+
/**
* Internal helper that actually run the test.
* Called by the public methods testEncodingUrlWith...()
$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 );
);
// restore global
- if( $old === null ) {
+ if ( $old === null ) {
unset( $_SERVER['SERVER_SOFTWARE'] );
} else {
$_SERVER['SERVER_SOFTWARE'] = $old;
* 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( <http server name> => <string> ).\n" );
- }
- }
-
+ }
+ }
#### PROVIDERS ###########################################################
* 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
array( '=', '%3D' ),
array( ':', array(
- 'Apache' => ':',
+ 'Apache' => ':',
'Microsoft-IIS/7' => '%3A',
) ),
';@$-_.!*',
),
- ### Other tests
+ ### Other tests
// slash remain unchanged. %2F seems to break things
array( '/', '/' ),
-
+
// Other 'funnies' chars
array( '[]', '%5B%5D' ),
array( '<>', '%3C%3E' ),
$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(
'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,
- )))
+ ) ) )
);
}
'GREEN',
'GREEN' => false,
'GREEN',
- )))
+ ) ) )
);
}
function testNamespaceSelector() {
$this->assertEquals(
'<select id=namespace name=namespace>' . "\n" .
-'<option value=0>(Main)</option>' . "\n" .
-'<option value=1>Talk</option>' . "\n" .
-'<option value=2>User</option>' . "\n" .
-'<option value=3>User talk</option>' . "\n" .
-'<option value=4>MyWiki</option>' . "\n" .
-'<option value=5>MyWiki Talk</option>' . "\n" .
-'<option value=6>File</option>' . "\n" .
-'<option value=7>File talk</option>' . "\n" .
-'<option value=8>MediaWiki</option>' . "\n" .
-'<option value=9>MediaWiki talk</option>' . "\n" .
-'<option value=10>Template</option>' . "\n" .
-'<option value=11>Template talk</option>' . "\n" .
-'<option value=14>Category</option>' . "\n" .
-'<option value=15>Category talk</option>' . "\n" .
-'<option value=100>Custom</option>' . "\n" .
-'<option value=101>Custom talk</option>' . "\n" .
-'</select>',
+ '<option value=0>(Main)</option>' . "\n" .
+ '<option value=1>Talk</option>' . "\n" .
+ '<option value=2>User</option>' . "\n" .
+ '<option value=3>User talk</option>' . "\n" .
+ '<option value=4>MyWiki</option>' . "\n" .
+ '<option value=5>MyWiki Talk</option>' . "\n" .
+ '<option value=6>File</option>' . "\n" .
+ '<option value=7>File talk</option>' . "\n" .
+ '<option value=8>MediaWiki</option>' . "\n" .
+ '<option value=9>MediaWiki talk</option>' . "\n" .
+ '<option value=10>Template</option>' . "\n" .
+ '<option value=11>Template talk</option>' . "\n" .
+ '<option value=14>Category</option>' . "\n" .
+ '<option value=15>Category talk</option>' . "\n" .
+ '<option value=100>Custom</option>' . "\n" .
+ '<option value=101>Custom talk</option>' . "\n" .
+ '</select>',
Html::namespaceSelector(),
'Basic namespace selector without custom options'
);
$this->assertEquals(
'<label for=mw-test-namespace>Select a namespace:</label> ' .
-'<select id=mw-test-namespace name=wpNamespace>' . "\n" .
-'<option value=all>all</option>' . "\n" .
-'<option value=0>(Main)</option>' . "\n" .
-'<option value=1>Talk</option>' . "\n" .
-'<option value=2 selected>User</option>' . "\n" .
-'<option value=3>User talk</option>' . "\n" .
-'<option value=4>MyWiki</option>' . "\n" .
-'<option value=5>MyWiki Talk</option>' . "\n" .
-'<option value=6>File</option>' . "\n" .
-'<option value=7>File talk</option>' . "\n" .
-'<option value=8>MediaWiki</option>' . "\n" .
-'<option value=9>MediaWiki talk</option>' . "\n" .
-'<option value=10>Template</option>' . "\n" .
-'<option value=11>Template talk</option>' . "\n" .
-'<option value=14>Category</option>' . "\n" .
-'<option value=15>Category talk</option>' . "\n" .
-'<option value=100>Custom</option>' . "\n" .
-'<option value=101>Custom talk</option>' . "\n" .
-'</select>',
+ '<select id=mw-test-namespace name=wpNamespace>' . "\n" .
+ '<option value=all>all</option>' . "\n" .
+ '<option value=0>(Main)</option>' . "\n" .
+ '<option value=1>Talk</option>' . "\n" .
+ '<option value=2 selected>User</option>' . "\n" .
+ '<option value=3>User talk</option>' . "\n" .
+ '<option value=4>MyWiki</option>' . "\n" .
+ '<option value=5>MyWiki Talk</option>' . "\n" .
+ '<option value=6>File</option>' . "\n" .
+ '<option value=7>File talk</option>' . "\n" .
+ '<option value=8>MediaWiki</option>' . "\n" .
+ '<option value=9>MediaWiki talk</option>' . "\n" .
+ '<option value=10>Template</option>' . "\n" .
+ '<option value=11>Template talk</option>' . "\n" .
+ '<option value=14>Category</option>' . "\n" .
+ '<option value=15>Category talk</option>' . "\n" .
+ '<option value=100>Custom</option>' . "\n" .
+ '<option value=101>Custom talk</option>' . "\n" .
+ '</select>',
Html::namespaceSelector(
array( 'selected' => '2', 'all' => 'all', 'label' => 'Select a namespace:' ),
array( 'name' => 'wpNamespace', 'id' => 'mw-test-namespace' )
$this->assertEquals(
'<label for=namespace>Select a namespace:</label> ' .
-'<select id=namespace name=namespace>' . "\n" .
-'<option value=0>(Main)</option>' . "\n" .
-'<option value=1>Talk</option>' . "\n" .
-'<option value=2>User</option>' . "\n" .
-'<option value=3>User talk</option>' . "\n" .
-'<option value=4>MyWiki</option>' . "\n" .
-'<option value=5>MyWiki Talk</option>' . "\n" .
-'<option value=6>File</option>' . "\n" .
-'<option value=7>File talk</option>' . "\n" .
-'<option value=8>MediaWiki</option>' . "\n" .
-'<option value=9>MediaWiki talk</option>' . "\n" .
-'<option value=10>Template</option>' . "\n" .
-'<option value=11>Template talk</option>' . "\n" .
-'<option value=14>Category</option>' . "\n" .
-'<option value=15>Category talk</option>' . "\n" .
-'<option value=100>Custom</option>' . "\n" .
-'<option value=101>Custom talk</option>' . "\n" .
-'</select>',
+ '<select id=namespace name=namespace>' . "\n" .
+ '<option value=0>(Main)</option>' . "\n" .
+ '<option value=1>Talk</option>' . "\n" .
+ '<option value=2>User</option>' . "\n" .
+ '<option value=3>User talk</option>' . "\n" .
+ '<option value=4>MyWiki</option>' . "\n" .
+ '<option value=5>MyWiki Talk</option>' . "\n" .
+ '<option value=6>File</option>' . "\n" .
+ '<option value=7>File talk</option>' . "\n" .
+ '<option value=8>MediaWiki</option>' . "\n" .
+ '<option value=9>MediaWiki talk</option>' . "\n" .
+ '<option value=10>Template</option>' . "\n" .
+ '<option value=11>Template talk</option>' . "\n" .
+ '<option value=14>Category</option>' . "\n" .
+ '<option value=15>Category talk</option>' . "\n" .
+ '<option value=100>Custom</option>' . "\n" .
+ '<option value=101>Custom talk</option>' . "\n" .
+ '</select>',
Html::namespaceSelector(
array( 'label' => 'Select a namespace:' )
),
function testCanFilterOutNamespaces() {
$this->assertEquals(
-'<select id=namespace name=namespace>' . "\n" .
-'<option value=2>User</option>' . "\n" .
-'<option value=4>MyWiki</option>' . "\n" .
-'<option value=5>MyWiki Talk</option>' . "\n" .
-'<option value=6>File</option>' . "\n" .
-'<option value=7>File talk</option>' . "\n" .
-'<option value=8>MediaWiki</option>' . "\n" .
-'<option value=9>MediaWiki talk</option>' . "\n" .
-'<option value=10>Template</option>' . "\n" .
-'<option value=11>Template talk</option>' . "\n" .
-'<option value=14>Category</option>' . "\n" .
-'<option value=15>Category talk</option>' . "\n" .
-'</select>',
+ '<select id=namespace name=namespace>' . "\n" .
+ '<option value=2>User</option>' . "\n" .
+ '<option value=4>MyWiki</option>' . "\n" .
+ '<option value=5>MyWiki Talk</option>' . "\n" .
+ '<option value=6>File</option>' . "\n" .
+ '<option value=7>File talk</option>' . "\n" .
+ '<option value=8>MediaWiki</option>' . "\n" .
+ '<option value=9>MediaWiki talk</option>' . "\n" .
+ '<option value=10>Template</option>' . "\n" .
+ '<option value=11>Template talk</option>' . "\n" .
+ '<option value=14>Category</option>' . "\n" .
+ '<option value=15>Category talk</option>' . "\n" .
+ '</select>',
Html::namespaceSelector(
array( 'exclude' => array( 0, 1, 3, 100, 101 ) )
),
function testCanDisableANamespaces() {
$this->assertEquals(
-'<select id=namespace name=namespace>' . "\n" .
-'<option disabled value=0>(Main)</option>' . "\n" .
-'<option disabled value=1>Talk</option>' . "\n" .
-'<option disabled value=2>User</option>' . "\n" .
-'<option disabled value=3>User talk</option>' . "\n" .
-'<option disabled value=4>MyWiki</option>' . "\n" .
-'<option value=5>MyWiki Talk</option>' . "\n" .
-'<option value=6>File</option>' . "\n" .
-'<option value=7>File talk</option>' . "\n" .
-'<option value=8>MediaWiki</option>' . "\n" .
-'<option value=9>MediaWiki talk</option>' . "\n" .
-'<option value=10>Template</option>' . "\n" .
-'<option value=11>Template talk</option>' . "\n" .
-'<option value=14>Category</option>' . "\n" .
-'<option value=15>Category talk</option>' . "\n" .
-'<option value=100>Custom</option>' . "\n" .
-'<option value=101>Custom talk</option>' . "\n" .
-'</select>',
+ '<select id=namespace name=namespace>' . "\n" .
+ '<option disabled value=0>(Main)</option>' . "\n" .
+ '<option disabled value=1>Talk</option>' . "\n" .
+ '<option disabled value=2>User</option>' . "\n" .
+ '<option disabled value=3>User talk</option>' . "\n" .
+ '<option disabled value=4>MyWiki</option>' . "\n" .
+ '<option value=5>MyWiki Talk</option>' . "\n" .
+ '<option value=6>File</option>' . "\n" .
+ '<option value=7>File talk</option>' . "\n" .
+ '<option value=8>MediaWiki</option>' . "\n" .
+ '<option value=9>MediaWiki talk</option>' . "\n" .
+ '<option value=10>Template</option>' . "\n" .
+ '<option value=11>Template talk</option>' . "\n" .
+ '<option value=14>Category</option>' . "\n" .
+ '<option value=15>Category talk</option>' . "\n" .
+ '<option value=100>Custom</option>' . "\n" .
+ '<option value=101>Custom talk</option>' . "\n" .
+ '</select>',
Html::namespaceSelector( array(
'disable' => array( 0, 1, 2, 3, 4 )
) ),
'color',
);
$cases = array();
- foreach( $types as $type ) {
+ foreach ( $types as $type ) {
$cases[] = array( $type );
}
return $cases;
# Craft the Html elements
$ret = array();
- foreach( $cases as $case ) {
+ foreach ( $cases as $case ) {
$ret[] = array(
$case[0],
$case[1], $case[2],
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" ),
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' ),
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' ),
/**
* 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
# 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
);
$h->setRespHeaders( 'location', array(
- 'https://oldsite/file.ext'
+ 'https://oldsite/file.ext'
)
);
$this->assertEquals(
);
$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!" )
);
}
}
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':
*/
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' );
$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' );
*/
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( ':' ) );
$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' );
* @todo Most probably incomplete
*/
public function testSanitizeIP() {
- $this->assertNull( IP::sanitizeIP('') );
- $this->assertNull( IP::sanitizeIP(' ') );
+ $this->assertNull( IP::sanitizeIP( '' ) );
+ $this->assertNull( IP::sanitizeIP( ' ' ) );
}
/**
*/
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 ) );
}
}
// 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 );
}
* @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' ) );
}
/**
$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' ) );
}
* @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' );
}
/**
/** 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' ),
<?php
class JsonTest extends MediaWikiTestCase {
-
+
function testPhpBug46944Test() {
- $this->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'
);
$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() );
}
function loadDefaultTables() {
$this->mTables = array(
'tg-latn' => new ReplacementArray( $this->table ),
- 'tg' => new ReplacementArray()
+ 'tg' => new ReplacementArray()
);
}
'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' ) );
}
* @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 )
$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",
<?php
class MWFunctionTest extends MediaWikiTestCase {
-
function testCallUserFuncWorkarounds() {
- $this->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';
$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 {
$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(),
*/
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
}
/**
*/
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
}
/**
* @expectedException MWException
*/
public function testGetAssociatedExceptionsForNsMedia() {
- $this->assertNull( MWNamespace::getAssociated( NS_MEDIA ) );
+ $this->assertNull( MWNamespace::getAssociated( NS_MEDIA ) );
}
/**
/**
* @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
$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() {
/**
* @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
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
global $wgNamespacesWithSubpages;
// Special namespaces:
- $this->assertHasNotSubpages( NS_MEDIA );
+ $this->assertHasNotSubpages( NS_MEDIA );
$this->assertHasNotSubpages( NS_SPECIAL );
// Namespaces without subpages
$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 );
}
*/
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" );
*/
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" );
// 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 );
}
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 );
}
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] );
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() {
####### 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,
function assertSameSubject( $ns1, $ns2, $msg = '' ) {
$this->assertTrue( MWNamespace::subjectEquals( $ns1, $ns2, $msg ) );
}
+
function assertDifferentSubject( $ns1, $ns2, $msg = '' ) {
$this->assertFalse( MWNamespace::subjectEquals( $ns1, $ns2, $msg ) );
}
*
* @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'];
$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'] );
}
/**
* @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 );
}
* 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,
) );
// 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,
'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)',
protected function setUp() {
parent::setUp();
$router = new PathRouter;
- $router->add("/wiki/$1");
+ $router->add( "/wiki/$1" );
$this->basicRouter = $router;
}
*/
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" ) );
}
*/
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" ) );
}
$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 );
}
}
$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() {
);
$this->assertEquals( 'mw-email-none', $prefs['emailaddress']['cssclass'] );
}
+
/**
* Placeholder to verify bug 34302
* @covers Preferences::profilePreferences
);
$this->assertEquals( 'mw-email-not-authenticated', $prefs['emailaddress']['cssclass'] );
}
+
/**
* Placeholder to verify bug 34302
* @covers Preferences::profilePreferences
/* 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;
$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] );
}
}