MediaWiki  1.23.6
/src/tests/phpunit/MediaWikiTestCase.php

Sets a global, maintaining a stashed version of the previous global to be restored in tearDownThe key is added to the array of globals that will be reset afterwards in the tearDown().

protected function setUp() { $this->setMwGlobals( 'wgRestrictStuff', true ); }

function testFoo() {}

function testBar() {} $this->assertTrue( self::getX()->doStuff() );

$this->setMwGlobals( 'wgRestrictStuff', false ); $this->assertTrue( self::getX()->doStuff() ); }

function testQuux() {}

Parameters
array | string$pairsKey to the global variable, or an array of key/value pairs.
mixed$valueValue to set the global to (ignored if an array is given as first argument).
Since
1.21
<?php
abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
private $called = array();
public static $users;
protected $db;
protected $tablesUsed = array(); // tables with data
private static $useTemporaryTables = true;
private static $reuseDB = false;
private static $dbSetup = false;
private static $oldTablePrefix = false;
private $phpErrorLevel;
private $tmpFiles = array();
private $mwGlobals = array();
const DB_PREFIX = 'unittest_';
const ORA_DB_PREFIX = 'ut_';
protected $supportedDBs = array(
'mysql',
'sqlite',
'postgres',
'oracle'
);
public function __construct( $name = null, array $data = array(), $dataName = '' ) {
parent::__construct( $name, $data, $dataName );
$this->backupGlobals = false;
$this->backupStaticAttributes = false;
}
public function run( PHPUnit_Framework_TestResult $result = null ) {
/* Some functions require some kind of caching, and will end up using the db,
* which we can't allow, as that would open a new connection for mysql.
* Replace with a HashBag. They would not be going to persist anyway.
*/
$needsResetDB = false;
$logName = get_class( $this ) . '::' . $this->getName( false );
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' );
$this->db = wfGetDB( DB_MASTER );
if ( !self::$dbSetup ) {
wfProfileIn( $logName . ' (clone-db)' );
// switch to a temporary clone of the database
self::setupTestDB( $this->db, $this->dbPrefix() );
if ( ( $this->db->getType() == 'oracle' || !self::$useTemporaryTables ) && self::$reuseDB ) {
$this->resetDB();
}
wfProfileOut( $logName . ' (clone-db)' );
}
wfProfileIn( $logName . ' (prepare-db)' );
$this->addCoreDBData();
$this->addDBData();
wfProfileOut( $logName . ' (prepare-db)' );
$needsResetDB = true;
}
wfProfileIn( $logName );
parent::run( $result );
wfProfileOut( $logName );
if ( $needsResetDB ) {
wfProfileIn( $logName . ' (reset-db)' );
$this->resetDB();
wfProfileOut( $logName . ' (reset-db)' );
}
}
public function usesTemporaryTables() {
}
protected function getNewTempFile() {
$fileName = tempnam( wfTempDir(), 'MW_PHPUnit_' . get_class( $this ) . '_' );
$this->tmpFiles[] = $fileName;
return $fileName;
}
protected function getNewTempDirectory() {
// Starting of with a temporary /file/.
$fileName = $this->getNewTempFile();
// Converting the temporary /file/ to a /directory/
//
// The following is not atomic, but at least we now have a single place,
// where temporary directory creation is bundled and can be improved
unlink( $fileName );
$this->assertTrue( wfMkdirParents( $fileName ) );
return $fileName;
}
protected function setUp() {
wfProfileIn( __METHOD__ );
parent::setUp();
$this->called['setUp'] = 1;
$this->phpErrorLevel = intval( ini_get( 'error_reporting' ) );
// Cleaning up temporary files
foreach ( $this->tmpFiles as $fileName ) {
if ( is_file( $fileName ) || ( is_link( $fileName ) ) ) {
unlink( $fileName );
} elseif ( is_dir( $fileName ) ) {
wfRecursiveRemoveDir( $fileName );
}
}
if ( $this->needsDB() && $this->db ) {
// Clean up open transactions
while ( $this->db->trxLevel() > 0 ) {
$this->db->rollback();
}
// don't ignore DB errors
$this->db->ignoreErrors( false );
}
wfProfileOut( __METHOD__ );
}
protected function tearDown() {
wfProfileIn( __METHOD__ );
// Cleaning up temporary files
foreach ( $this->tmpFiles as $fileName ) {
if ( is_file( $fileName ) || ( is_link( $fileName ) ) ) {
unlink( $fileName );
} elseif ( is_dir( $fileName ) ) {
wfRecursiveRemoveDir( $fileName );
}
}
if ( $this->needsDB() && $this->db ) {
// Clean up open transactions
while ( $this->db->trxLevel() > 0 ) {
$this->db->rollback();
}
// don't ignore DB errors
$this->db->ignoreErrors( false );
}
// Restore mw globals
foreach ( $this->mwGlobals as $key => $value ) {
$GLOBALS[$key] = $value;
}
$this->mwGlobals = array();
$phpErrorLevel = intval( ini_get( 'error_reporting' ) );
if ( $phpErrorLevel !== $this->phpErrorLevel ) {
ini_set( 'error_reporting', $this->phpErrorLevel );
$oldHex = strtoupper( dechex( $this->phpErrorLevel ) );
$newHex = strtoupper( dechex( $phpErrorLevel ) );
$message = "PHP error_reporting setting was left dirty: was 0x$oldHex before test, 0x$newHex after test!";
$this->fail( $message );
}
parent::tearDown();
wfProfileOut( __METHOD__ );
}
final public function testMediaWikiTestCaseParentSetupCalled() {
$this->assertArrayHasKey( 'setUp', $this->called,
get_called_class() . "::setUp() must call parent::setUp()"
);
}
protected function setMwGlobals( $pairs, $value = null ) {
if ( is_string( $pairs ) ) {
$pairs = array( $pairs => $value );
}
$this->stashMwGlobals( array_keys( $pairs ) );
foreach ( $pairs as $key => $value ) {
$GLOBALS[$key] = $value;
}
}
protected function stashMwGlobals( $globalKeys ) {
if ( is_string( $globalKeys ) ) {
$globalKeys = array( $globalKeys );
}
foreach ( $globalKeys as $globalKey ) {
// NOTE: make sure we only save the global once or a second call to
// setMwGlobals() on the same global would override the original
// value.
if ( !array_key_exists( $globalKey, $this->mwGlobals ) ) {
if ( !array_key_exists( $globalKey, $GLOBALS ) ) {
throw new Exception( "Global with key {$globalKey} doesn't exist and cant be stashed" );
}
// NOTE: we serialize then unserialize the value in case it is an object
// this stops any objects being passed by reference. We could use clone
// and if is_object but this does account for objects within objects!
try {
$this->mwGlobals[$globalKey] = unserialize( serialize( $GLOBALS[$globalKey] ) );
}
// NOTE; some things such as Closures are not serializable
// in this case just set the value!
catch ( Exception $e ) {
$this->mwGlobals[$globalKey] = $GLOBALS[$globalKey];
}
}
}
}
protected function mergeMwGlobalArrayValue( $name, $values ) {
if ( !isset( $GLOBALS[$name] ) ) {
$merged = $values;
} else {
if ( !is_array( $GLOBALS[$name] ) ) {
throw new MWException( "MW global $name is not an array." );
}
// NOTE: do not use array_merge, it screws up for numeric keys.
$merged = $GLOBALS[$name];
foreach ( $values as $k => $v ) {
$merged[$k] = $v;
}
}
$this->setMwGlobals( $name, $merged );
}
public function dbPrefix() {
return $this->db->getType() == 'oracle' ? self::ORA_DB_PREFIX : self::DB_PREFIX;
}
public function needsDB() {
# if the test says it uses database tables, it needs the database
if ( $this->tablesUsed ) {
return true;
}
# if the test says it belongs to the Database group, it needs the database
$rc = new ReflectionClass( $this );
if ( preg_match( '/@group +Database/im', $rc->getDocComment() ) ) {
return true;
}
return false;
}
public function addDBData() {
}
private function addCoreDBData() {
if ( $this->db->getType() == 'oracle' ) {
# Insert 0 user to prevent FK violations
# Anonymous user
$this->db->insert( 'user', array(
'user_id' => 0,
'user_name' => 'Anonymous' ), __METHOD__, array( 'IGNORE' ) );
# Insert 0 page to prevent FK violations
# Blank page
$this->db->insert( 'page', array(
'page_id' => 0,
'page_namespace' => 0,
'page_title' => ' ',
'page_restrictions' => null,
'page_counter' => 0,
'page_is_redirect' => 0,
'page_is_new' => 0,
'page_random' => 0,
'page_touched' => $this->db->timestamp(),
'page_latest' => 0,
'page_len' => 0 ), __METHOD__, array( 'IGNORE' ) );
}
//Make sysop user
$user = User::newFromName( 'UTSysop' );
if ( $user->idForName() == 0 ) {
$user->addToDatabase();
$user->setPassword( 'UTSysopPassword' );
$user->addGroup( 'sysop' );
$user->addGroup( 'bureaucrat' );
$user->saveSettings();
}
//Make 1 page with 1 revision
$page = WikiPage::factory( Title::newFromText( 'UTPage' ) );
if ( !$page->getId() == 0 ) {
$page->doEditContent(
new WikitextContent( 'UTContent' ),
'UTPageSummary',
false,
User::newFromName( 'UTSysop' ) );
}
}
public static function teardownTestDB() {
if ( !self::$dbSetup ) {
return;
}
CloneDatabase::changePrefix( self::$oldTablePrefix );
self::$oldTablePrefix = false;
self::$dbSetup = false;
}
public static function setupTestDB( DatabaseBase $db, $prefix ) {
global $wgDBprefix;
if ( $wgDBprefix === $prefix ) {
throw new MWException(
'Cannot run unit tests, the database prefix is already "' . $prefix . '"' );
}
if ( self::$dbSetup ) {
return;
}
$tablesCloned = self::listTables( $db );
$dbClone = new CloneDatabase( $db, $tablesCloned, $prefix );
$dbClone->useTemporaryTables( self::$useTemporaryTables );
self::$dbSetup = true;
self::$oldTablePrefix = $wgDBprefix;
if ( ( $db->getType() == 'oracle' || !self::$useTemporaryTables ) && self::$reuseDB ) {
return;
} else {
$dbClone->cloneTableStructure();
}
if ( $db->getType() == 'oracle' ) {
$db->query( 'BEGIN FILL_WIKI_INFO; END;' );
}
}
private function resetDB() {
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__ );
}
}
} else {
foreach ( $this->tablesUsed as $tbl ) {
if ( $tbl == 'interwiki' || $tbl == 'user' ) {
continue;
}
$this->db->delete( $tbl, '*', __METHOD__ );
}
}
}
}
public function __call( $func, $args ) {
static $compatibility = array(
'assertEmpty' => 'assertEmpty2', // assertEmpty was added in phpunit 3.7.32
);
if ( isset( $compatibility[$func] ) ) {
return call_user_func_array( array( $this, $compatibility[$func] ), $args );
} else {
throw new MWException( "Called non-existant $func method on "
. get_class( $this ) );
}
}
private function assertEmpty2( $value, $msg ) {
return $this->assertTrue( $value == '', $msg );
}
private static function unprefixTable( $tableName ) {
global $wgDBprefix;
return substr( $tableName, strlen( $wgDBprefix ) );
}
private static function isNotUnittest( $table ) {
return strpos( $table, 'unittest_' ) !== 0;
}
public static function listTables( $db ) {
global $wgDBprefix;
$tables = $db->listTables( $wgDBprefix, __METHOD__ );
if ( $db->getType() === 'mysql' ) {
# bug 43571: cannot clone VIEWs under MySQL
$views = $db->listViews( $wgDBprefix, __METHOD__ );
$tables = array_diff( $tables, $views );
}
$tables = array_map( array( __CLASS__, 'unprefixTable' ), $tables );
// Don't duplicate test tables from the previous fataled run
$tables = array_filter( $tables, array( __CLASS__, 'isNotUnittest' ) );
if ( $db->getType() == 'sqlite' ) {
$tables = array_flip( $tables );
// these are subtables of searchindex and don't need to be duped/dropped separately
unset( $tables['searchindex_content'] );
unset( $tables['searchindex_segdir'] );
unset( $tables['searchindex_segments'] );
$tables = array_flip( $tables );
}
return $tables;
}
protected function checkDbIsSupported() {
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 ) {
}
}
public function setCliArg( $offset, $value ) {
}
public function hideDeprecated( $function ) {
wfDeprecated( $function );
}
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.' );
}
$res = $db->select( $table, $fields, $condition, wfGetCaller(), array( 'ORDER BY' => $fields ) );
$this->assertNotEmpty( $res, "query failed: " . $db->lastError() );
$i = 0;
foreach ( $expectedRows as $expected ) {
$r = $res->fetchRow();
$i += 1;
$this->assertNotEmpty( $r, "row #$i missing" );
$this->assertEquals( $expected, $r, "row #$i mismatches" );
}
$r = $res->fetchRow();
$this->assertFalse( $r, "found extra row (after #$i)" );
}
protected function arrayWrap( array $elements ) {
return array_map(
function ( $element ) {
return array( $element );
},
$elements
);
}
protected function assertArrayEquals( array $expected, array $actual, $ordered = false, $named = false ) {
if ( !$ordered ) {
$this->objectAssociativeSort( $expected );
$this->objectAssociativeSort( $actual );
}
if ( !$named ) {
$expected = array_values( $expected );
$actual = array_values( $actual );
}
call_user_func_array(
array( $this, 'assertEquals' ),
array_merge( array( $expected, $actual ), array_slice( func_get_args(), 4 ) )
);
}
protected function assertHTMLEquals( $expected, $actual, $msg = '' ) {
$expected = str_replace( '>', ">\n", $expected );
$actual = str_replace( '>', ">\n", $actual );
$this->assertEquals( $expected, $actual, $msg );
}
protected function objectAssociativeSort( array &$array ) {
uasort(
$array,
function ( $a, $b ) {
return serialize( $a ) > serialize( $b ) ? 1 : -1;
}
);
}
protected static function stripStringKeys( &$r ) {
if ( !is_array( $r ) ) {
return;
}
foreach ( $r as $k => $v ) {
if ( is_string( $k ) ) {
unset( $r[$k] );
}
}
}
protected function assertTypeOrValue( $type, $actual, $value = false, $message = '' ) {
if ( $actual === $value ) {
$this->assertTrue( true, $message );
} 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 {
$this->assertInternalType( $type, $actual, $message );
}
}
protected function isWikitextNS( $ns ) {
global $wgNamespaceContentModels;
if ( isset( $wgNamespaceContentModels[$ns] ) ) {
return $wgNamespaceContentModels[$ns] === CONTENT_MODEL_WIKITEXT;
}
return true;
}
protected function getDefaultWikitextNS() {
global $wgNamespaceContentModels;
static $wikitextNS = null; // this is not going to change
if ( $wikitextNS !== null ) {
return $wikitextNS;
}
// quickly short out on most common case:
if ( !isset( $wgNamespaceContentModels[NS_MAIN] ) ) {
return NS_MAIN;
}
// NOTE: prefer content namespaces
$namespaces = array_unique( array_merge(
array( NS_MAIN, NS_HELP, NS_PROJECT ), // prefer these
) );
$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 );
} );
// prefer non-talk pages
$namespaces = array_diff( $namespaces, $talk );
$namespaces = array_merge( $namespaces, $talk );
// check default content model of each namespace
foreach ( $namespaces as $ns ) {
if ( !isset( $wgNamespaceContentModels[$ns] ) ||
$wgNamespaceContentModels[$ns] === CONTENT_MODEL_WIKITEXT
) {
$wikitextNS = $ns;
return $wikitextNS;
}
}
// give up
// @todo Inside a test, we could skip the test as incomplete.
// But frequently, this is used in fixture setup.
throw new MWException( "No namespace defaults to wikitext!" );
}
protected function checkHasDiff3() {
global $wgDiff3;
# This check may also protect against code injection in
# case of broken installations.
$haveDiff3 = $wgDiff3 && file_exists( $wgDiff3 );
if ( !$haveDiff3 ) {
$this->markTestSkipped( "Skip test, since diff3 is not configured" );
}
}
protected function checkHasGzip() {
static $haveGzip;
if ( $haveGzip === null ) {
$retval = null;
wfShellExec( 'gzip -V', $retval );
$haveGzip = ( $retval === 0 );
}
if ( !$haveGzip ) {
$this->markTestSkipped( "Skip test, requires the gzip utility in PATH" );
}
return $haveGzip;
}
protected function checkPHPExtension( $extName ) {
$loaded = extension_loaded( $extName );
if ( !$loaded ) {
$this->markTestSkipped( "PHP extension '$extName' is not loaded, skipping." );
}
return $loaded;
}
protected function assertException( $code, $expected = 'Exception', $message = '' ) {
$pokemons = null;
try {
call_user_func( $code );
} catch ( Exception $pokemons ) {
// Gotta Catch 'Em All!
}
if ( $message === '' ) {
$message = 'An exception of type "' . $expected . '" should have been thrown';
}
$this->assertInstanceOf( $expected, $pokemons, $message );
}
protected function assertValidHtmlSnippet( $html ) {
$html = '<!DOCTYPE html><html><head><title>test</title></head><body>' . $html . '</body></html>';
}
protected function assertValidHtmlDocument( $html ) {
// Note: we only validate if the tidy PHP extension is available.
// In case wgTidyInternal is false, MWTidy would fall back to the command line version
// of tidy. In that case however, we can not reliably detect whether a failing validation
// is due to malformed HTML, or caused by tidy not being installed as a command line tool.
// That would cause all HTML assertions to fail on a system that has no tidy installed.
if ( !$GLOBALS['wgTidyInternal'] ) {
$this->markTestSkipped( 'Tidy extension not installed' );
}
$errorBuffer = '';
MWTidy::checkErrors( $html, $errorBuffer );
$allErrors = preg_split( '/[\r\n]+/', $errorBuffer );
// Filter Tidy warnings which aren't useful for us.
// Tidy eg. often cries about parameters missing which have actually
// been deprecated since HTML4, thus we should not care about them.
$errors = preg_grep(
'/^(.*Warning: (trimming empty|.* lacks ".*?" attribute).*|\s*)$/m',
$allErrors, PREG_GREP_INVERT
);
$this->assertEmpty( $errors, implode( "\n", $errors ) );
}
}
MediaWikiTestCase\unprefixTable
static unprefixTable( $tableName)
Definition: MediaWikiTestCase.php:601
MediaWikiTestCase\$reuseDB
static $reuseDB
Definition: MediaWikiTestCase.php:39
MediaWikiTestCase\assertValidHtmlDocument
assertValidHtmlDocument( $html)
Asserts that the given string is valid HTML document.
Definition: MediaWikiTestCase.php:1071
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. $reader:XMLReader object $logInfo:Array of information Return false to stop further processing of the tag 'ImportHandlePageXMLTag':When parsing a XML tag in a page. $reader:XMLReader object $pageInfo:Array of information Return false to stop further processing of the tag 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information Return false to stop further processing of the tag 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. $reader:XMLReader object Return false to stop further processing of the tag 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. $reader:XMLReader object $revisionInfo:Array of information Return false to stop further processing of the tag 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. $title:Title object for the current page $request:WebRequest $ignoreRedirect:boolean to skip redirect check $target:Title/string of redirect target $article:Article object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) $article:article(object) being checked 'IsTrustedProxy':Override the result of wfIsTrustedProxy() $ip:IP being check $result:Change this value to override the result of wfIsTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of User::isValidEmailAddr(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetMagic':DEPRECATED, use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetSpecialPageAliases':DEPRECATED, use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Associative array mapping language codes to prefixed links of the form "language:title". & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LinkBegin':Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1528
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:189
MediaWikiTestCase\assertArrayEquals
assertArrayEquals(array $expected, array $actual, $ordered=false, $named=false)
Assert that two arrays are equal.
Definition: MediaWikiTestCase.php:764
DB_MASTER
const DB_MASTER
Definition: Defines.php:56
wfShellExec
wfShellExec( $cmd, &$retval=null, $environ=array(), $limits=array(), $options=array())
Execute a shell command, with time and memory limits mirrored from the PHP configuration if supported...
Definition: GlobalFunctions.php:2804
MediaWikiTestCase\stashMwGlobals
stashMwGlobals( $globalKeys)
Stashes the global, will be restored in tearDown()
Definition: MediaWikiTestCase.php:329
NS_HELP
const NS_HELP
Definition: Defines.php:91
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
MWNamespace\getValidNamespaces
static getValidNamespaces()
Returns an array of the namespaces (by integer id) that exist on the wiki.
Definition: Namespace.php:273
MWNamespace\isTalk
static isTalk( $index)
Is the given namespace a talk namespace?
Definition: Namespace.php:107
MediaWikiTestCase\mergeMwGlobalArrayValue
mergeMwGlobalArrayValue( $name, $values)
Merges the given values into a MW global array variable.
Definition: MediaWikiTestCase.php:369
HashBagOStuff
This is a test of the interface, mainly.
Definition: HashBagOStuff.php:30
$html
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition: hooks.txt:1530
$tables
namespace and then decline to actually register it RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist & $tables
Definition: hooks.txt:815
MediaWikiTestCase\stripStringKeys
static stripStringKeys(&$r)
Utility function for eliminating all string keys from an array.
Definition: MediaWikiTestCase.php:825
wfMkdirParents
wfMkdirParents( $dir, $mode=null, $caller=null)
Make directory, and make all parent directories if they don't exist.
Definition: GlobalFunctions.php:2590
MediaWikiTestCase\$tmpFiles
array $tmpFiles
Holds the paths of temporary files/directories created through getNewTempFile, and getNewTempDirector...
Definition: MediaWikiTestCase.php:54
wfGetLB
wfGetLB( $wiki=false)
Get a load balancer object.
Definition: GlobalFunctions.php:3669
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3659
MediaWikiTestCase\isWikitextNS
isWikitextNS( $ns)
Returns true if the given namespace defaults to Wikitext according to $wgNamespaceContentModels.
Definition: MediaWikiTestCase.php:886
DatabaseBase\query
query( $sql, $fname=__METHOD__, $tempIgnore=false)
Run an SQL query and return the result.
Definition: Database.php:1001
MediaWikiTestCase\needsDB
needsDB()
Definition: MediaWikiTestCase.php:399
wfProfileIn
wfProfileIn( $functionname)
Begin profiling of a function.
Definition: Profiler.php:33
wfSuppressWarnings
wfSuppressWarnings( $end=false)
Reference-counted warning suppression.
Definition: GlobalFunctions.php:2387
MediaWikiTestCase\$useTemporaryTables
static $useTemporaryTables
Definition: MediaWikiTestCase.php:38
NS_FILE
const NS_FILE
Definition: Defines.php:85
MediaWikiTestCase\checkDbIsSupported
checkDbIsSupported()
Definition: MediaWikiTestCase.php:649
MediaWikiTestCase\getCliArg
getCliArg( $offset)
Definition: MediaWikiTestCase.php:658
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:388
MediaWikiTestCase\testMediaWikiTestCaseParentSetupCalled
testMediaWikiTestCaseParentSetupCalled()
Make sure MediaWikiTestCase extending classes have called their parent setUp method.
Definition: MediaWikiTestCase.php:264
fail
as a message key or array as accepted by ApiBase::dieUsageMsg after processing request parameters Return false to let the request fail
Definition: hooks.txt:375
MediaWikiTestCase\assertValidHtmlSnippet
assertValidHtmlSnippet( $html)
Asserts that the given string is a valid HTML snippet.
Definition: MediaWikiTestCase.php:1055
MediaWikiTestCase\isNotUnittest
static isNotUnittest( $table)
Definition: MediaWikiTestCase.php:607
CONTENT_MODEL_WIKITEXT
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:283
MediaWikiTestCase\__construct
__construct( $name=null, array $data=array(), $dataName='')
Definition: MediaWikiTestCase.php:79
MWNamespace\getContentNamespaces
static getContentNamespaces()
Get a list of all namespace indices which are considered to contain content.
Definition: Namespace.php:334
MediaWikiTestCase\teardownTestDB
static teardownTestDB()
Restores MediaWiki to using the table set (table prefix) it was using before setupTestDB() was called...
Definition: MediaWikiTestCase.php:481
MediaWikiTestCase\$users
static $users
Definition: MediaWikiTestCase.php:26
MediaWikiTestCase\__call
__call( $func, $args)
Definition: MediaWikiTestCase.php:581
MediaWikiTestCase\$called
$called
$called tracks whether the setUp and tearDown method has been called.
Definition: MediaWikiTestCase.php:20
NS_MAIN
const NS_MAIN
Definition: Defines.php:79
MediaWikiTestCase\checkHasDiff3
checkHasDiff3()
Check, if $wgDiff3 is set and ready to merge Will mark the calling test as skipped,...
Definition: MediaWikiTestCase.php:959
MediaWikiTestCase\resetDB
resetDB()
Empty all tables so they can be repopulated for tests.
Definition: MediaWikiTestCase.php:547
MWException
MediaWiki exception.
Definition: MWException.php:26
WikiPage\factory
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:103
NS_PROJECT
const NS_PROJECT
Definition: Defines.php:83
MediaWikiPHPUnitCommand\$additionalOptions
static $additionalOptions
Definition: MediaWikiPHPUnitCommand.php:5
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Definition: GlobalFunctions.php:1127
MediaWikiTestCase\$phpErrorLevel
int $phpErrorLevel
Original value of PHP's error_reporting setting.
Definition: MediaWikiTestCase.php:47
DatabaseBase\select
select( $table, $vars, $conds='', $fname=__METHOD__, $options=array(), $join_conds=array())
Execute a SELECT query constructed using the various parameters provided.
Definition: Database.php:1575
wfRestoreWarnings
wfRestoreWarnings()
Restore error level to previous value.
Definition: GlobalFunctions.php:2417
MediaWikiTestCase\assertSelect
assertSelect( $table, $fields, $condition, array $expectedRows)
Asserts that the given database query yields the rows given by $expectedRows.
Definition: MediaWikiTestCase.php:703
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Definition: MediaWikiTestCase.php:302
MediaWikiTestCase\getNewTempFile
getNewTempFile()
Obtains a new temporary file name.
Definition: MediaWikiTestCase.php:156
MediaWikiTestCase\addCoreDBData
addCoreDBData()
Definition: MediaWikiTestCase.php:423
MediaWikiTestCase\run
run(PHPUnit_Framework_TestResult $result=null)
Definition: MediaWikiTestCase.php:86
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
MediaWikiTestCase\$oldTablePrefix
static $oldTablePrefix
Definition: MediaWikiTestCase.php:41
ObjectCache\$instances
static $instances
Definition: ObjectCache.php:30
MediaWikiTestCase\hideDeprecated
hideDeprecated( $function)
Don't throw a warning if $function is deprecated and called later.
Definition: MediaWikiTestCase.php:679
wfProfileOut
wfProfileOut( $functionname='missing')
Stop profiling of a function.
Definition: Profiler.php:46
DatabaseBase\listTables
listTables( $prefix=null, $fname=__METHOD__)
List all tables on the database.
Definition: Database.php:3558
MediaWikiTestCase\assertException
assertException( $code, $expected='Exception', $message='')
Asserts that an exception of the specified type occurs when running the provided code.
Definition: MediaWikiTestCase.php:1025
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
MediaWikiTestCase\assertEmpty2
assertEmpty2( $value, $msg)
Used as a compatibility method for phpunit < 3.7.32.
Definition: MediaWikiTestCase.php:597
MediaWikiTestCase\getDefaultWikitextNS
getDefaultWikitextNS()
Returns the ID of a namespace that defaults to Wikitext.
Definition: MediaWikiTestCase.php:903
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:93
WikitextContent
Content object for wiki text pages.
Definition: WikitextContent.php:33
MediaWikiTestCase\arrayWrap
arrayWrap(array $elements)
Utility method taking an array of elements and wrapping each element in it's own array.
Definition: MediaWikiTestCase.php:743
DatabaseType\getType
getType()
Get the type of the DBMS, as it appears in $wgDBtype.
MediaWikiTestCase\checkHasGzip
checkHasGzip()
Check whether we have the 'gzip' commandline utility, will skip the test whenever "gzip -V" fails.
Definition: MediaWikiTestCase.php:983
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
MediaWikiTestCase\assertHTMLEquals
assertHTMLEquals( $expected, $actual, $msg='')
Put each HTML element on its own line and then equals() the results.
Definition: MediaWikiTestCase.php:793
$value
$value
Definition: styleTest.css.php:45
MediaWikiTestCase\assertTypeOrValue
assertTypeOrValue( $type, $actual, $value=false, $message='')
Asserts that the provided variable is of the specified internal type or equals the $value argument.
Definition: MediaWikiTestCase.php:850
MediaWikiTestCase\$db
DatabaseBase $db
Definition: MediaWikiTestCase.php:31
MediaWikiTestCase\dbPrefix
dbPrefix()
Definition: MediaWikiTestCase.php:391
DatabaseBase
Database abstraction object.
Definition: Database.php:219
MediaWikiTestCase\setupTestDB
static setupTestDB(DatabaseBase $db, $prefix)
Creates an empty skeleton of the wiki database by cloning its structure to equivalent tables using th...
Definition: MediaWikiTestCase.php:513
MediaWikiTestCase\listTables
static listTables( $db)
Definition: MediaWikiTestCase.php:618
DatabaseType\lastError
lastError()
Get a description of the last error.
MediaWikiTestCase\addDBData
addDBData()
Stub.
Definition: MediaWikiTestCase.php:420
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:237
MediaWikiTestCase\setUp
setUp()
Definition: MediaWikiTestCase.php:187
MediaWikiTestCase\objectAssociativeSort
objectAssociativeSort(array &$array)
Does an associative sort that works for objects.
Definition: MediaWikiTestCase.php:807
EDIT_NEW
const EDIT_NEW
Definition: Defines.php:189
MediaWikiTestCase\DB_PREFIX
const DB_PREFIX
Table name prefixes.
Definition: MediaWikiTestCase.php:66
$args
if( $line===false) $args
Definition: cdb.php:62
DB_SLAVE
const DB_SLAVE
Definition: Defines.php:55
$namespaces
namespace and then decline to actually register it & $namespaces
Definition: hooks.txt:815
wfTempDir
wfTempDir()
Tries to get the system directory for temporary files.
Definition: GlobalFunctions.php:2564
MediaWikiTestCase\$supportedDBs
array $supportedDBs
Definition: MediaWikiTestCase.php:72
CloneDatabase
Definition: CloneDatabase.php:27
DatabaseBase\listViews
listViews( $prefix=null, $fname=__METHOD__)
Lists all the VIEWs in the database.
Definition: Database.php:3581
MediaWikiTestCase\ORA_DB_PREFIX
const ORA_DB_PREFIX
Definition: MediaWikiTestCase.php:67
CloneDatabase\changePrefix
static changePrefix( $prefix)
Change the table prefix on all open DB connections/.
Definition: CloneDatabase.php:114
User\resetIdByNameCache
static resetIdByNameCache()
Reset the cache used in idFromName().
Definition: User.php:534
wfRecursiveRemoveDir
wfRecursiveRemoveDir( $dir)
Remove a directory and all its content.
Definition: GlobalFunctions.php:2632
MediaWikiTestCase\$tablesUsed
array $tablesUsed
Definition: MediaWikiTestCase.php:36
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
NS_USER
const NS_USER
Definition: Defines.php:81
MediaWikiTestCase\checkPHPExtension
checkPHPExtension( $extName)
Check if $extName is a loaded PHP extension, will skip the test whenever it is not loaded.
Definition: MediaWikiTestCase.php:1005
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:87
MediaWikiTestCase\$mwGlobals
array $mwGlobals
Holds original values of MediaWiki configuration settings to be restored in tearDown().
Definition: MediaWikiTestCase.php:61
MWTidy\checkErrors
static checkErrors( $text, &$errorStr=null)
Check HTML for errors, used if $wgValidateAllHtml = true.
Definition: Tidy.php:159
MediaWikiTestCase\usesTemporaryTables
usesTemporaryTables()
Definition: MediaWikiTestCase.php:143
$e
if( $useReadline) $e
Definition: eval.php:66
MediaWikiTestCase\assertType
assertType( $type, $actual, $message='')
Asserts the type of the provided value.
Definition: MediaWikiTestCase.php:869
MediaWikiTestCase\setCliArg
setCliArg( $offset, $value)
Definition: MediaWikiTestCase.php:667
$res
$res
Definition: database.txt:21
$retval
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account incomplete not yet checked for validity & $retval
Definition: hooks.txt:237
wfGetCaller
wfGetCaller( $level=2)
Get the name of the function which called this function wfGetCaller( 1 ) is the function with the wfG...
Definition: GlobalFunctions.php:1941
$GLOBALS
$GLOBALS['IP']
Definition: ComposerHookHandler.php:6
CACHE_DB
const CACHE_DB
Definition: Defines.php:113
MediaWikiTestCase\tearDown
tearDown()
Definition: MediaWikiTestCase.php:216
MediaWikiTestCase\$dbSetup
static $dbSetup
Definition: MediaWikiTestCase.php:40
$type
$type
Definition: testCompression.php:46
MediaWikiTestCase\getNewTempDirectory
getNewTempDirectory()
obtains a new temporary directory
Definition: MediaWikiTestCase.php:173