MediaWiki  1.23.2
MediaWikiTestCase Class Reference

Inherits PHPUnit_Framework_TestCase.

Inherited by ArrayDiffFormatterTest, ArrayUtilsTest, ArticleTest, AutoLoaderTest, BadTitleErrorTest, BagOStuffTest, BaseDumpTest, BitmapMetadataHandlerTest, BitmapScalingTest, CdbTest, CLDRPluralRuleEvaluatorTest, CleanUpTest, ConfigFactoryTest, ContentHandlerTest, CssContentTest, CSSJanusTest, CSSMinTest, DatabaseMysqlBaseTest, DatabaseSqliteTest, DatabaseSQLTest, DatabaseTest, DifferenceEngineTest, DiffHistoryBlobTest, DiffOpTest, DiffTest, DjVuTest, DummyExtensionsTest, ErrorPageErrorTest, ExifBitmapTest, ExifRotationTest, ExifTest, ExternalStoreTest, ExtraParserTest, FallbackTest, FauxRequestTest, FauxResponseTest, FetchTextTest, FileBackendTest, FileRepoTest, FormatJsonTest, FormatMetadataTest, FormOptionsInitializationTest, FormOptionsTest, GenericArrayObjectTest, GetSlaveServerTest, GIFHandlerTest, GlobalTest, GlobalVarConfigTest, GlobalWithDBTest, HashRingTest, HooksTest, HtmlCheckMatrixTest, HtmlFormatterTest, HttpTest, IEUrlExtensionTest, InstallDocFormatterTest, IPTCTest, IPTest, JavaScriptMinifierTest, JobQueueTest, JpegMetadataExtractorTest, JpegTest, LanguageClassesTestCase, LBFactoryTest, LessFileCompilationTest, LicensesTest, LinksUpdateTest, LocalFileTest, LocalisationCacheTest, MagicVariableTest, MaintenanceTest, MediaHandlerTest, MediaWikiLangTestCase, MediaWikiTestCaseTest, MediaWikiTitleCodecTest, MWDebugTest, MWExceptionHandlerTest, MWExceptionTest, MWFunctionTest, MWMessagePackTest, MWNamespaceTest, OracleInstallerTest, ORMRowTest, ORMTableTest, OutputPageTest, ParserOutputTest, ParserPreloadTest, PathRouterTest, PNGHandlerTest, PNGMetadataExtractorTest, PreferencesTest, PrefixUniquenessTest, PreprocessorTest, ProcessCacheLRUTest, QueryAllSpecialPagesTest, ReadOnlyErrorTest, RecentChangeTest, RefreshLinksPartitionTest, RequestContextTest, ResourceLoaderLESSTest, ResourceLoaderTestCase, ResourcesTest, RevisionStorageTest, RevisionTest, RunningStatTest, SanitizerTest, SanitizerValidateEmailTest, SearchUpdateTest, SiteConfigurationTest, SiteListTest, SiteSQLStoreTest, SiteTest, SkinTemplateTest, SpecialListFilesTest, SpecialPageAliasTest, SpecialPageTest, SpecialPreferencesTest, SpecialRecentchangesTest, SpecialSearchTest, StoreBatchTest, StringUtilsTest, StructureTest, SVGMetadataExtractorTest, SvgTest, TagHookTest, ThrottledErrorTest, TidyTest, TiffTest, TitleArrayFromResultTest, TitleMethodsTest, TitleTest, TitleValueTest, UIDGeneratorTest, UploadBaseTest, UploadStashTest, UserArrayFromResultTest, UserNotLoggedInTest, UserTest, WebRequestTest, WfAssembleUrlTest, WfBaseConvertTest, WfBaseNameTest, WfBCP47Test, WfExpandUrlTest, WfGetCallerTest, WfParseUrlTest, WfRemoveDotSegmentsTest, WfShorthandToIntegerTest, WfTimestampTest, WfUrlencodeTest, XmlJs, XmlSelectTest, XmlTest, XmlTypeCheckTest, XMPTest, XMPValidateTest, and ZipDirectoryReaderTest.

Collaboration diagram for MediaWikiTestCase:

Public Member Functions

 __call ( $func, $args)
 
 __construct ( $name=null, array $data=array(), $dataName='')
 
 addDBData ()
 Stub. More...
 
 dbPrefix ()
 
 getCliArg ( $offset)
 
 hideDeprecated ( $function)
 Don't throw a warning if $function is deprecated and called later. More...
 
 needsDB ()
 
 run (PHPUnit_Framework_TestResult $result=null)
 
 setCliArg ( $offset, $value)
 
 testMediaWikiTestCaseParentSetupCalled ()
 Make sure MediaWikiTestCase extending classes have called their parent setUp method. More...
 
 usesTemporaryTables ()
 

Static Public Member Functions

static listTables ( $db)
 
static setupTestDB (DatabaseBase $db, $prefix)
 Creates an empty skeleton of the wiki database by cloning its structure to equivalent tables using the given $prefix. More...
 
static teardownTestDB ()
 Restores MediaWiki to using the table set (table prefix) it was using before setupTestDB() was called. More...
 

Public Attributes

const DB_PREFIX = 'unittest_'
 Table name prefixes. More...
 
const ORA_DB_PREFIX = 'ut_'
 

Static Public Attributes

static $users
 

Protected Member Functions

 arrayWrap (array $elements)
 Utility method taking an array of elements and wrapping each element in it's own array. More...
 
 assertArrayEquals (array $expected, array $actual, $ordered=false, $named=false)
 Assert that two arrays are equal. More...
 
 assertException ( $code, $expected='Exception', $message='')
 Asserts that an exception of the specified type occurs when running the provided code. More...
 
 assertHTMLEquals ( $expected, $actual, $msg='')
 Put each HTML element on its own line and then equals() the results. More...
 
 assertSelect ( $table, $fields, $condition, array $expectedRows)
 Asserts that the given database query yields the rows given by $expectedRows. More...
 
 assertType ( $type, $actual, $message='')
 Asserts the type of the provided value. More...
 
 assertTypeOrValue ( $type, $actual, $value=false, $message='')
 Asserts that the provided variable is of the specified internal type or equals the $value argument. More...
 
 assertValidHtmlDocument ( $html)
 Asserts that the given string is valid HTML document. More...
 
 assertValidHtmlSnippet ( $html)
 Asserts that the given string is a valid HTML snippet. More...
 
 checkDbIsSupported ()
 
 checkHasDiff3 ()
 Check, if $wgDiff3 is set and ready to merge Will mark the calling test as skipped, if not ready. More...
 
 checkHasGzip ()
 Check whether we have the 'gzip' commandline utility, will skip the test whenever "gzip -V" fails. More...
 
 checkPHPExtension ( $extName)
 Check if $extName is a loaded PHP extension, will skip the test whenever it is not loaded. More...
 
 getDefaultWikitextNS ()
 Returns the ID of a namespace that defaults to Wikitext. More...
 
 getNewTempDirectory ()
 obtains a new temporary directory More...
 
 getNewTempFile ()
 Obtains a new temporary file name. More...
 
 isWikitextNS ( $ns)
 Returns true if the given namespace defaults to Wikitext according to $wgNamespaceContentModels. More...
 
 mergeMwGlobalArrayValue ( $name, $values)
 Merges the given values into a MW global array variable. More...
 
 objectAssociativeSort (array &$array)
 Does an associative sort that works for objects. More...
 
 setMwGlobals ( $pairs, $value=null)
 
 setUp ()
 
 stashMwGlobals ( $globalKeys)
 Stashes the global, will be restored in tearDown() More...
 
 tearDown ()
 

Static Protected Member Functions

static stripStringKeys (&$r)
 Utility function for eliminating all string keys from an array. More...
 

Protected Attributes

DatabaseBase $db
 
array $supportedDBs
 
array $tablesUsed = array()
 

Private Member Functions

 addCoreDBData ()
 
 assertEmpty2 ( $value, $msg)
 Used as a compatibility method for phpunit < 3.7.32. More...
 
 resetDB ()
 Empty all tables so they can be repopulated for tests. More...
 

Static Private Member Functions

static isNotUnittest ( $table)
 
static unprefixTable ( $tableName)
 

Private Attributes

 $called = array()
 $called tracks whether the setUp and tearDown method has been called. More...
 
array $mwGlobals = array()
 Holds original values of MediaWiki configuration settings to be restored in tearDown(). More...
 
int $phpErrorLevel
 Original value of PHP's error_reporting setting. More...
 
array $tmpFiles = array()
 Holds the paths of temporary files/directories created through getNewTempFile, and getNewTempDirectory. More...
 

Static Private Attributes

static $dbSetup = false
 
static $oldTablePrefix = false
 
static $reuseDB = false
 
static $useTemporaryTables = true
 

Detailed Description

Since
1.18
Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 6 of file MediaWikiTestCase.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWikiTestCase::__construct (   $name = null,
array  $data = array(),
  $dataName = '' 
)

Member Function Documentation

◆ __call()

MediaWikiTestCase::__call (   $func,
  $args 
)
Since
1.18
Parameters
string$func
array$args
Returns
mixed
Exceptions
MWException

Reimplemented in MWNamespaceTest.

Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 581 of file MediaWikiTestCase.php.

References $args, and array().

◆ addCoreDBData()

MediaWikiTestCase::addCoreDBData ( )
private

◆ addDBData()

MediaWikiTestCase::addDBData ( )

Stub.

If a test needs to add additional data to the database, it should implement this method and do so

Since
1.18

Reimplemented in FetchTextTest, BackupDumperLoggerTest, ApiQueryBasicTest, ApiQueryContinueTest, ApiQueryContinue2Test, MessageCacheTest, TextPassDumperTest, BlockTest, BackupDumperPageTest, ApiBlockTest, and GenderCacheTest.

Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 420 of file MediaWikiTestCase.php.

Referenced by run().

◆ arrayWrap()

MediaWikiTestCase::arrayWrap ( array  $elements)
protected

Utility method taking an array of elements and wrapping each element in it's own array.

Useful for data providers that only return a single argument.

Since
1.20
Parameters
array$elements
Returns
array
Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 743 of file MediaWikiTestCase.php.

References array().

Referenced by SiteTest\instanceProvider(), GenericArrayObjectTest\instanceProvider(), SiteListTest\siteArrayProvider(), and SiteListTest\siteListProvider().

◆ assertArrayEquals()

MediaWikiTestCase::assertArrayEquals ( array  $expected,
array  $actual,
  $ordered = false,
  $named = false 
)
protected

Assert that two arrays are equal.

By default this means that both arrays need to hold the same set of values. Using additional arguments, order and associated key can also be set as relevant.

Since
1.20
Parameters
array$expected
array$actual
bool$orderedIf the order of the values should match
bool$namedIf the keys should match
Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 764 of file MediaWikiTestCase.php.

References array(), and objectAssociativeSort().

Referenced by SiteListTest\testGetGlobalIdentifiers(), DjVuTest\testGetImageSize(), DjVuTest\testGetPageDimensions(), TextContentTest\testGetParserOutput(), SiteListTest\testSerialization(), GenericArrayObjectTest\testSerialization(), UIDGeneratorTest\testTimestampedUID(), and LinksUpdateTest\testUpdate_pagelinks().

◆ assertEmpty2()

MediaWikiTestCase::assertEmpty2 (   $value,
  $msg 
)
private

Used as a compatibility method for phpunit < 3.7.32.

Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 597 of file MediaWikiTestCase.php.

References $value.

◆ assertException()

MediaWikiTestCase::assertException (   $code,
  $expected = 'Exception',
  $message = '' 
)
protected

Asserts that an exception of the specified type occurs when running the provided code.

Since
1.21
Deprecated:
since 1.22 Use setExpectedException
Parameters
callable$code
string$expected
string$message
Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 1025 of file MediaWikiTestCase.php.

◆ assertHTMLEquals()

MediaWikiTestCase::assertHTMLEquals (   $expected,
  $actual,
  $msg = '' 
)
protected

Put each HTML element on its own line and then equals() the results.

Use for nicely formatting of PHPUnit diff output when comparing very simple HTML

Since
1.20
Parameters
string$expectedHTML on oneline
string$actualHTML on oneline
string$msgOptional message
Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 793 of file MediaWikiTestCase.php.

◆ assertSelect()

MediaWikiTestCase::assertSelect (   $table,
  $fields,
  $condition,
array  $expectedRows 
)
protected

Asserts that the given database query yields the rows given by $expectedRows.

The expected rows should be given as indexed (not associative) arrays, with the values given in the order of the columns in the $fields parameter. Note that the rows are sorted by the columns given in $fields.

Since
1.20
Parameters
string | array$tableThe table(s) to query
string | array$fieldsThe columns to include in the result (and to sort by)
string | array$condition"where" condition(s)
array$expectedRowsAn array of arrays giving the expected rows.
Exceptions
MWExceptionIf this test cases's needsDB() method doesn't return true. Test cases can use "@group Database" to enable database test support, or list the tables under testing in $this->tablesUsed, or override the needsDB() method.
Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 703 of file MediaWikiTestCase.php.

References $db, $res, array(), as, DB_SLAVE, DatabaseType\lastError(), needsDB(), DatabaseBase\select(), stripStringKeys(), wfGetCaller(), and wfGetDB().

Referenced by LinksUpdateTest\assertLinksUpdate().

◆ assertType()

MediaWikiTestCase::assertType (   $type,
  $actual,
  $message = '' 
)
protected

Asserts the type of the provided value.

This can be either in internal type such as boolean or integer, or a class or interface the value extends or implements.

Since
1.20
Parameters
string$type
mixed$actual
string$message
Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 869 of file MediaWikiTestCase.php.

References $type.

Referenced by assertTypeOrValue(), FileBackendTest\doTestLockCalls(), UIDGeneratorTest\testNewSequentialID(), UIDGeneratorTest\testNewSequentialIDs(), and ApiQueryTestBase\validateRequestExpectedPair().

◆ assertTypeOrValue()

MediaWikiTestCase::assertTypeOrValue (   $type,
  $actual,
  $value = false,
  $message = '' 
)
protected

Asserts that the provided variable is of the specified internal type or equals the $value argument.

This is useful for testing return types of functions that return a certain type or value when not set or on error.

Since
1.20
Parameters
string$type
mixed$actual
mixed$value
string$message
Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 850 of file MediaWikiTestCase.php.

References $type, $value, and assertType().

Referenced by SiteTest\testGetGlobalId(), SiteTest\testGetLanguageCode(), and SiteTest\testGetPath().

◆ assertValidHtmlDocument()

MediaWikiTestCase::assertValidHtmlDocument (   $html)
protected

Asserts that the given string is valid HTML document.

Since
1.23
Note
Will mark the test as skipped if the "tidy" module is not installed.
This ignores $wgUseTidy, so we can check for valid HTML even (and especially) when automatic tidying is disabled.
Parameters
string$htmlA complete HTML document
Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 1071 of file MediaWikiTestCase.php.

References $GLOBALS, $html, and MWTidy\checkErrors().

Referenced by assertValidHtmlSnippet().

◆ assertValidHtmlSnippet()

MediaWikiTestCase::assertValidHtmlSnippet (   $html)
protected

Asserts that the given string is a valid HTML snippet.

Wraps the given string in the required top level tags and then calls assertValidHtmlDocument(). The snippet is expected to be HTML 5.

Since
1.23
Note
Will mark the test as skipped if the "tidy" module is not installed.
This ignores $wgUseTidy, so we can check for valid HTML even (and especially) when automatic tidying is disabled.
Parameters
string$htmlAn HTML snippet (treated as the contents of the body tag).
Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 1055 of file MediaWikiTestCase.php.

References $html, and assertValidHtmlDocument().

Referenced by HtmlFormatterTest\testTransform().

◆ checkDbIsSupported()

MediaWikiTestCase::checkDbIsSupported ( )
protected
Exceptions
MWException
Since
1.18
Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 649 of file MediaWikiTestCase.php.

References $supportedDBs.

Referenced by run().

◆ checkHasDiff3()

MediaWikiTestCase::checkHasDiff3 ( )
protected

Check, if $wgDiff3 is set and ready to merge Will mark the calling test as skipped, if not ready.

Since
1.21
Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 959 of file MediaWikiTestCase.php.

References global, wfRestoreWarnings(), and wfSuppressWarnings().

Referenced by EditPageTest\testAutoMerge(), GlobalTest\testMerge(), and WikitextContentHandlerTest\testMerge3().

◆ checkHasGzip()

MediaWikiTestCase::checkHasGzip ( )
protected

Check whether we have the 'gzip' commandline utility, will skip the test whenever "gzip -V" fails.

Result is cached at the process level.

Returns
bool
Since
1.21
Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 983 of file MediaWikiTestCase.php.

References $retval, and wfShellExec().

Referenced by TextPassDumperTest\testCheckpointGzip(), BackupDumperPageTest\testCurrentStubGzip(), BackupDumperPageTest\testXmlDumpsBackupUseCase(), and BackupDumperLoggerTest\testXmlDumpsBackupUseCaseLogging().

◆ checkPHPExtension()

◆ dbPrefix()

MediaWikiTestCase::dbPrefix ( )
Returns
string
Since
1.18
Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 391 of file MediaWikiTestCase.php.

References DB_PREFIX, and ORA_DB_PREFIX.

Referenced by DatabaseTest\prefixAndQuote(), and run().

◆ getCliArg()

◆ getDefaultWikitextNS()

◆ getNewTempDirectory()

MediaWikiTestCase::getNewTempDirectory ( )
protected

obtains a new temporary directory

The obtained directory is enlisted to be removed (recursively with all its contained files) upon tearDown.

Since
1.20
Returns
string Absolute name of the temporary directory
Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 173 of file MediaWikiTestCase.php.

References getNewTempFile(), and wfMkdirParents().

Referenced by TextPassDumperTest\checkpointHelper(), and ExifRotationTest\setUp().

◆ getNewTempFile()

◆ hideDeprecated()

◆ isNotUnittest()

static MediaWikiTestCase::isNotUnittest (   $table)
staticprivate

◆ isWikitextNS()

MediaWikiTestCase::isWikitextNS (   $ns)
protected

Returns true if the given namespace defaults to Wikitext according to $wgNamespaceContentModels.

Parameters
int$nsThe namespace ID to check
Returns
bool
Since
1.21
Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 886 of file MediaWikiTestCase.php.

References CONTENT_MODEL_WIKITEXT, and global.

Referenced by SearchEngineTest\addPages(), SearchEngineTest\fetchIds(), and TitlePermissionTest\testQuickPermissions().

◆ listTables()

static MediaWikiTestCase::listTables (   $db)
static
Since
1.18
Parameters
DataBaseBase$db
Returns
array
Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 618 of file MediaWikiTestCase.php.

References $db, $tables, array(), DatabaseType\getType(), global, DatabaseBase\listTables(), and DatabaseBase\listViews().

Referenced by setupTestDB().

◆ mergeMwGlobalArrayValue()

MediaWikiTestCase::mergeMwGlobalArrayValue (   $name,
  $values 
)
protected

Merges the given values into a MW global array variable.

Useful for setting some entries in a configuration array, instead of setting the entire array.

Parameters
string$nameThe name of the global, as in wgFooBar
array$valuesThe array containing the entries to set in that global
Exceptions
MWExceptionif the designated global is not an array.
Since
1.21
Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 369 of file MediaWikiTestCase.php.

References $GLOBALS, $name, as, and setMwGlobals().

Referenced by RevisionTest\setUp(), and TitleMethodsTest\setUp().

◆ needsDB()

MediaWikiTestCase::needsDB ( )
Returns
bool
Since
1.18
Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 399 of file MediaWikiTestCase.php.

Referenced by assertSelect(), run(), setUp(), and tearDown().

◆ objectAssociativeSort()

MediaWikiTestCase::objectAssociativeSort ( array $array)
protected

Does an associative sort that works for objects.

Since
1.20
Parameters
array$array
Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 807 of file MediaWikiTestCase.php.

Referenced by assertArrayEquals().

◆ resetDB()

MediaWikiTestCase::resetDB ( )
private

Empty all tables so they can be repopulated for tests.

Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 547 of file MediaWikiTestCase.php.

References as, DB_MASTER, wfGetDB(), and wfGetLB().

Referenced by run().

◆ run()

◆ setCliArg()

MediaWikiTestCase::setCliArg (   $offset,
  $value 
)

◆ setMwGlobals()

MediaWikiTestCase::setMwGlobals (   $pairs,
  $value = null 
)
protected
Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 302 of file MediaWikiTestCase.php.

References $GLOBALS, $value, array(), as, and stashMwGlobals().

Referenced by BackupDumperPageTest\addDBData(), EditPageTest\assertEdit(), MessageCacheTest\configureLanguages(), mergeMwGlobalArrayValue(), BitmapMetadataHandlerTest\setUp(), GlobalTest\setUp(), AutoLoaderTest\setUp(), BitmapScalingTest\setUp(), SvgTest\setUp(), MessageTest\setUp(), LanguageConverterTest\setUp(), RevisionTest\setUp(), TiffTest\setUp(), ResourceLoaderTest\setUp(), TestSample\setUp(), LinkFilterTest\setUp(), XmlTest\setUp(), MediaWikiLangTestCase\setUp(), FormatMetadataTest\setUp(), ExifBitmapTest\setUp(), JpegTest\setUp(), CssContentTest\setUp(), TitleTest\setUp(), CSSMinTest\setUp(), ApiTestCase\setUp(), WikiPageTest_ContentHandlerUseDB\setUp(), ExifTest\setUp(), RevisionTest_ContentHandlerUseDB\setUp(), ApiTestCaseUpload\setUp(), TextContentTest\setUp(), UploadFromUrlTest\setUp(), LocalFileTest\setUp(), ExifRotationTest\setUp(), ApiCreateAccountTest\setUp(), ExtraParserTest\setUp(), RCCacheEntryFactoryTest\setUp(), XmlSelectTest\setUp(), SpecialPageTest\setUp(), ContentHandlerTest\setUp(), UserTest\setUp(), BlockTest\setUp(), TagHookTest\setUp(), ApiEditPageTest\setUp(), MWNamespaceTest\setUp(), ResourceLoaderTestCase\setUp(), JobQueueTest\setUp(), LogFormatterTest\setUp(), SearchEngineTest\setUp(), TitlePermissionTest\setUp(), SearchUpdateTest\setUp(), WfParseUrlTest\setUp(), MediaWikiTitleCodecTest\setUp(), MagicVariableTest\setUp(), PreferencesTest\setUp(), DumpTestCase\setUp(), ArticleTablesTest\testbug14404(), UploadStashTest\testBug29408(), SpecialPreferencesTest\testBug41337(), UserTest\testCheckPasswordValidity(), ExtraParserTest\testCleanSigDisabled(), RevisionTest\testCompressRevisionTextUtf8Gzip(), ExternalStoreTest\testExternalFetchFromURL(), SideBarTest\testExternalUrlsRequireADescription(), ContentHandlerTest\testGetContentText_NonTextContent_fail(), ContentHandlerTest\testGetContentText_NonTextContent_ignore(), ContentHandlerTest\testGetContentText_NonTextContent_serialize(), ContentHandlerTest\testGetContentText_Null(), ContentHandlerTest\testGetContentText_TextContent(), WebRequestTest\testGetIP(), WebRequestTest\testGetIpLackOfRemoteAddrThrowAnException(), ResourceLoaderStartupModuleTest\testGetModuleRegistrations(), MessageTest\testInContentLanguageDisabled(), MessageTest\testInContentLanguageEnabled(), MWExceptionTest\testisCommandLine(), TextContentTest\testIsCountable(), WikiPageTest\testIsCountable(), MWExceptionTest\testJsonserializeexceptionBacktracingDisabled(), MWExceptionTest\testJsonserializeexceptionBacktracingEnabled(), MWExceptionTest\testJsonserializeexceptionKeys(), ExifRotationTest\testMetadataNoAutoRotate(), BitmapMetadataHandlerTest\testMultilingualCascade(), SanitizerTest\testRemovehtmltagsOnHtml5Tags(), SideBarTest\testRespectExternallinktarget(), SideBarTest\testRespectWgnofollowlinks(), ExifRotationTest\testRotationRenderingNoAutoRotate(), MWExceptionTest\testRunHooks(), TitleTest\testSecureAndSplit(), MediaWikiTestCaseTest\testSetGlobalsAreRestoredOnTearDown(), SideBarTest\testTestAttributesAssertionHelper(), LinksUpdateTest\testUpdate_categorylinks(), ApiUploadTest\testUploadChunks(), ApiUploadTest\testUploadStash(), MWExceptionTest\testUseMessageCache(), MWExceptionTest\testUseOutputPage(), TimeAdjustTest\testUserAdjust(), LinkerTest\testUserLink(), and WfExpandUrlTest\testWfExpandUrl().

◆ setUp()

MediaWikiTestCase::setUp ( )
protected

Reimplemented in FetchTextTest, MaintenanceTest, TextPassDumperTest, BackupDumperPageTest, DumpTestCase, TestORMRowTest, LanguageClassesTestCase, FormOptionsInitializationTest, SideBarTest, RevisionStorageTest, DatabaseSqliteTest, WikiPageTest, MagicVariableTest, PreferencesTest, MediaWikiTitleCodecTest, FormOptionsTest, FauxResponseTest, WfParseUrlTest, LinksUpdateTest, SearchUpdateTest, TitlePermissionTest, SearchEngineTest, ApiOptionsTest, DifferenceEngineTest, LogFormatterTest, DjVuTest, JobQueueTest, UploadStashTest, ResourceLoaderTestCase, ParserPreloadTest, ApiEditPageTest, FileBackendTest, MWNamespaceTest, BlockTest, JpegMetadataExtractorTest, TagHookTest, ApiQueryTest, PathRouterTest, UserTest, ArticleTest, ContentHandlerTest, DatabaseSQLTest, DatabaseTest, StoreBatchTest, PreprocessorTest, SpecialPageTest, ApiParseTest, ApiPurgeTest, RCCacheEntryFactoryTest, WikitextContentHandlerTest, TitleMethodsTest, XmlSelectTest, ApiBlockTest, ApiCreateAccountTest, ApiTestCaseUpload, ApiUnblockTest, CollationTest, TextContentTest, ErrorPageErrorTest, ThrottledErrorTest, ExtraParserTest, LocalFileTest, ExifRotationTest, UploadFromUrlTest, ZipDirectoryReaderTest, ApiQueryAllPagesTest, ApiTestCase, ApiWatchTest, MessageCacheTest, CssContentTest, BadTitleErrorTest, CSSMinTest, ExifTest, BagOStuffTest, RevisionTest_ContentHandlerUseDB, TitleTest, UploadBaseTest, CdbTest, WikiPageTest_ContentHandlerUseDB, GenderCacheTest, ExifBitmapTest, GIFHandlerTest, JpegTest, PNGHandlerTest, SanitizerTest, SiteConfigurationTest, WebRequestTest, LinkFilterTest, FormatMetadataTest, PNGMetadataExtractorTest, SVGMetadataExtractorTest, XMPTest, MWTimestampTest, TidyTest, TestSample, XmlTest, MediaWikiLangTestCase, LanguageConverterTest, TiffTest, ResourceLoaderTest, RevisionTest, MWDebugTest, DiffHistoryBlobTest, HooksTest, BitmapScalingTest, SvgTest, MessageTest, GlobalTest, BitmapMetadataHandlerTest, TimeAdjustTest, and AutoLoaderTest.

Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 187 of file MediaWikiTestCase.php.

References as, needsDB(), wfProfileIn(), wfProfileOut(), and wfRecursiveRemoveDir().

◆ setupTestDB()

static MediaWikiTestCase::setupTestDB ( DatabaseBase  $db,
  $prefix 
)
static

Creates an empty skeleton of the wiki database by cloning its structure to equivalent tables using the given $prefix.

Then sets MediaWiki to use the new set of tables (aka schema) instead of the original set.

This is used to generate a dummy table set, typically consisting of temporary tables, that will be used by tests instead of the original wiki database tables.

Since
1.21
Note
: the original table prefix is stored in self::$oldTablePrefix. This is used by teardownTestDB() to return the wiki to using the original table set.
: this method only works when first called. Subsequent calls have no effect, even if using different parameters.
Parameters
DatabaseBase$dbThe database connection
String$prefixThe prefix to use for the new table set (aka schema).
Exceptions
MWExceptionif the database table prefix is already $prefix
Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 513 of file MediaWikiTestCase.php.

References $db, $useTemporaryTables, CloneDatabase\changePrefix(), DatabaseType\getType(), global, listTables(), and DatabaseBase\query().

Referenced by run().

◆ stashMwGlobals()

MediaWikiTestCase::stashMwGlobals (   $globalKeys)
protected

Stashes the global, will be restored in tearDown()

Individual test functions may override globals through the setMwGlobals() function or directly. When directly overriding globals their keys should first be passed to this method in setUp to avoid breaking global state for other tests

That way all other tests are executed with the same settings (instead of using the unreliable local settings for most tests and fix it only for some tests).

Parameters
array | string$globalKeysKey to the global variable, or an array of keys.
Exceptions
Exceptionwhen trying to stash an unset global
Since
1.23
Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 329 of file MediaWikiTestCase.php.

References $e, $GLOBALS, array(), and as.

Referenced by setMwGlobals(), MediaWikiTestCaseTest\testExceptionThrownWhenStashingNonExistentGlobals(), and MediaWikiTestCaseTest\testStashedGlobalsAreRestoredOnTearDown().

◆ stripStringKeys()

static MediaWikiTestCase::stripStringKeys ( $r)
staticprotected

Utility function for eliminating all string keys from an array.

Useful to turn a database result row as returned by fetchRow() into a pure indexed array.

Since
1.20
Parameters
mixed$rThe array to remove string keys from.
Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 825 of file MediaWikiTestCase.php.

References as.

Referenced by assertSelect().

◆ tearDown()

◆ teardownTestDB()

static MediaWikiTestCase::teardownTestDB ( )
static

Restores MediaWiki to using the table set (table prefix) it was using before setupTestDB() was called.

Useful if we need to perform database operations after the test run has finished (such as saving logs or profiling info).

Since
1.21
Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 481 of file MediaWikiTestCase.php.

References CloneDatabase\changePrefix().

◆ testMediaWikiTestCaseParentSetupCalled()

MediaWikiTestCase::testMediaWikiTestCaseParentSetupCalled ( )
final

Make sure MediaWikiTestCase extending classes have called their parent setUp method.

Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 264 of file MediaWikiTestCase.php.

◆ unprefixTable()

static MediaWikiTestCase::unprefixTable (   $tableName)
staticprivate
Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 601 of file MediaWikiTestCase.php.

References global.

◆ usesTemporaryTables()

MediaWikiTestCase::usesTemporaryTables ( )
Since
1.21
Returns
bool
Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 143 of file MediaWikiTestCase.php.

References $useTemporaryTables.

Member Data Documentation

◆ $called

MediaWikiTestCase::$called = array()
private

$called tracks whether the setUp and tearDown method has been called.

class extending MediaWikiTestCase usually override setUp and tearDown but forget to call the parent.

The array format takes a method name as key and anything as a value. By asserting the key exist, we know the child class has called the parent.

This property must be private, we do not want child to override it, they should call the appropriate parent method instead.

Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 20 of file MediaWikiTestCase.php.

Referenced by HtmlCheckMatrixTest\testValidateCallsUserDefinedValidationCallback().

◆ $db

◆ $dbSetup

MediaWikiTestCase::$dbSetup = false
staticprivate

◆ $mwGlobals

array MediaWikiTestCase::$mwGlobals = array()
private

Holds original values of MediaWiki configuration settings to be restored in tearDown().

See also setMwGlobals().

Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 61 of file MediaWikiTestCase.php.

◆ $oldTablePrefix

MediaWikiTestCase::$oldTablePrefix = false
staticprivate

◆ $phpErrorLevel

int MediaWikiTestCase::$phpErrorLevel
private

Original value of PHP's error_reporting setting.

Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 47 of file MediaWikiTestCase.php.

Referenced by tearDown().

◆ $reuseDB

MediaWikiTestCase::$reuseDB = false
staticprivate

◆ $supportedDBs

array MediaWikiTestCase::$supportedDBs
protected
Initial value:
'mysql',
'sqlite',
'postgres',
'oracle'
)
Since
1.18
Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 72 of file MediaWikiTestCase.php.

Referenced by checkDbIsSupported().

◆ $tablesUsed

array MediaWikiTestCase::$tablesUsed = array()
protected
Since
1.19
Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 36 of file MediaWikiTestCase.php.

◆ $tmpFiles

array MediaWikiTestCase::$tmpFiles = array()
private

Holds the paths of temporary files/directories created through getNewTempFile, and getNewTempDirectory.

Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 54 of file MediaWikiTestCase.php.

Referenced by FileBackendTest\doTestGetLocalCopy(), and FileBackendTest\doTestGetLocalReference().

◆ $users

MediaWikiTestCase::$users
static

◆ $useTemporaryTables

MediaWikiTestCase::$useTemporaryTables = true
staticprivate

◆ DB_PREFIX

const MediaWikiTestCase::DB_PREFIX = 'unittest_'

Table name prefixes.

Oracle likes it shorter.

Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 66 of file MediaWikiTestCase.php.

Referenced by dbPrefix().

◆ ORA_DB_PREFIX

const MediaWikiTestCase::ORA_DB_PREFIX = 'ut_'
Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 67 of file MediaWikiTestCase.php.

Referenced by dbPrefix().


The documentation for this class was generated from the following file:
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.