MediaWiki  1.27.4
MediaWikiTestCase Class Reference

Inherits PHPUnit_Framework_TestCase.

Inherited by ActionTest, ApiContinuationManagerTest, ApiDocumentationTest, ApiFormatTestBase, ApiMessageTest, ApiModuleManagerTest, ApiResultTest, ArrayDiffFormatterTest, ArticleTest, AutoLoaderTest, BadTitleErrorTest, BagOStuffTest, BaseDumpTest, BatchRowUpdateTest, BitmapMetadataHandlerTest, BitmapScalingTest, BotPasswordTest, CachingSiteStoreTest, CategoryMembershipChangeJobTest, CdnCacheUpdateTest, CentralIdLookupTest, ComposerJsonTest, ComposerLockTest, ConfigFactoryTest, ContentHandlerTest, CSSMinTest, DatabaseMysqlBaseTest, DatabaseSqliteTest, DatabaseSQLTest, DatabaseTest, DatabaseUpdaterTest, DBSiteStoreTest, DeferredUpdatesTest, DifferenceEngineTest, DiffHistoryBlobTest, DiffOpTest, DiffTest, DummyExtensionsTest, ErrorPageErrorTest, ExifTest, ExtensionProcessorTest, ExtensionRegistryTest, ExternalStoreTest, ExtraParserTest, FauxRequestTest, FauxResponseTest, FetchTextTest, FileBackendDBRepoWrapperTest, FileBackendTest, FileContentsHasherTest, FileRepoTest, ForeignTitleTest, FormatJsonTest, FormOptionsInitializationTest, FormOptionsTest, GIFMetadataExtractorTest, GitInfoTest, GlobalTest, GlobalVarConfigTest, GlobalWithDBTest, HashConfigTest, HashSiteStoreTest, HooksTest, HtmlAutoCompleteSelectFieldTest, HtmlCheckMatrixTest, HTMLFormTest, HtmlTest, HttpErrorTest, HttpTest, ImageListPagerTest, ImportLinkCacheIntegrationTest, InstallDocFormatterTest, InterwikiTest, IPTCTest, JobQueueTest, JobTest, JpegMetadataExtractorTest, LanguageClassesTestCase, LBFactoryTest, LicensesTest, LocalFileTest, LocalIdLookupTest, LocalisationCacheTest, MagicVariableTest, MailAddressTest, MaintenanceTest, MediaHandlerTest, MediaWiki\Auth\AbstractAuthenticationProviderTest, MediaWiki\Auth\AbstractPasswordPrimaryAuthenticationProviderTest, MediaWiki\Auth\AbstractPreAuthenticationProviderTest, MediaWiki\Auth\AbstractPrimaryAuthenticationProviderTest, MediaWiki\Auth\AbstractSecondaryAuthenticationProviderTest, MediaWiki\Auth\AuthenticationRequestTest, MediaWiki\Auth\AuthenticationRequestTestCase, MediaWiki\Auth\AuthenticationResponseTest, MediaWiki\Auth\AuthManagerTest, MediaWiki\Auth\AuthPluginPrimaryAuthenticationProviderTest, MediaWiki\Auth\CheckBlocksSecondaryAuthenticationProviderTest, MediaWiki\Auth\ConfirmLinkSecondaryAuthenticationProviderTest, MediaWiki\Auth\LegacyHookPreAuthenticationProviderTest, MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProviderTest, MediaWiki\Auth\ResetPasswordSecondaryAuthenticationProviderTest, MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProviderTest, MediaWiki\Auth\ThrottlePreAuthenticationProviderTest, MediaWiki\Auth\ThrottlerTest, MediaWiki\Logger\LegacyLoggerTest, MediaWiki\Logger\Monolog\AvroFormatterTest, MediaWiki\Logger\Monolog\KafkaHandlerTest, MediaWiki\Logger\Monolog\LineFormatterTest, MediaWiki\Logger\MonologSpiTest, MediaWiki\Session\BotPasswordSessionProviderTest, MediaWiki\Session\CookieSessionProviderTest, MediaWiki\Session\ImmutableSessionProviderWithCookieTest, MediaWiki\Session\MetadataMergeExceptionTest, MediaWiki\Session\PHPSessionHandlerTest, MediaWiki\Session\SessionBackendTest, MediaWiki\Session\SessionIdTest, MediaWiki\Session\SessionInfoTest, MediaWiki\Session\SessionManagerTest, MediaWiki\Session\SessionProviderTest, MediaWiki\Session\SessionTest, MediaWiki\Session\TokenTest, MediaWiki\Session\UserInfoTest, MediaWikiLangTestCase, MediaWikiMediaTestCase, MediaWikiPageLinkRendererTest, MediaWikiTest, MediaWikiTestCaseTest, MediaWikiTitleCodecTest, MemcachedBagOStuffTest, MergeHistoryTest, MigrateFileRepoLayoutTest, MovePageTest, MultiConfigTest, MultiWriteBagOStuffTest, MWCryptHashTest, MWCryptHKDFTest, MWDebugTest, MWExceptionHandlerTest, MWExceptionTest, MWGrantsTest, MWNamespaceTest, NaiveForeignTitleFactoryTest, NaiveImportTitleFactoryTest, NamespaceAwareForeignTitleFactoryTest, NamespaceImportTitleFactoryTest, NewParserTest, OracleInstallerTest, OutputPageTest, ParserOutputTest, ParserPreloadTest, PasswordPolicyChecksTest, PasswordTest, PasswordTestCase, PathRouterTest, PNGMetadataExtractorTest, PoolCounterTest, PreferencesTest, PrefixUniquenessTest, PreprocessorTest, QueryAllSpecialPagesTest, ReadOnlyErrorTest, RecentChangeTest, RefreshLinksPartitionTest, ReplicatedBagOStuffTest, RepoGroupTest, RequestContextTest, ResourceLoaderTestCase, ResourcesTest, RevisionStorageTest, RevisionTest, SanitizerTest, SearchUpdateTest, SiteConfigurationTest, SiteListTest, SiteTest, SkinFactoryTest, SkinTemplateTest, SpecialBooksourcesTest, SpecialMIMESearchTest, SpecialMyLanguageTest, SpecialPageAliasTest, SpecialPageFactoryTest, SpecialPageTest, SpecialPageTestBase, SpecialPreferencesTest, SpecialRecentchangesTest, SpecialSearchTest, StoreBatchTest, StructureTest, SubpageImportTitleFactoryTest, SVGMetadataExtractorTest, SwiftFileBackendTest, TagHookTest, TemplateParserTest, TestingAccessWrapperTest, ThrottledErrorTest, TidyTest, TiffTest, TitleTest, TitleValueTest, UploadBaseTest, UploadStashTest, UserArrayFromResultTest, UserNotLoggedInTest, UserPasswordPolicyTest, UserTest, WANObjectCacheTest, WatchedItemIntegrationTest, WatchedItemStoreIntegrationTest, WebPHandlerTest, WebRequestTest, WfAppendQueryTest, WfArrayPlus2dTest, WfAssembleUrlTest, WfBaseNameTest, WfBCP47Test, WfEscapeShellArgTest, WfExpandUrlTest, WfGetCallerTest, WfParseUrlTest, WfRemoveDotSegmentsTest, WfShellExecTest, WfShorthandToIntegerTest, WfThumbIsStandardTest, WfTimestampTest, WfUrlencodeTest, XmlSelectTest, XmlTest, XMPTest, and XMPValidateTest.

Collaboration diagram for MediaWikiTestCase:

Public Member Functions

 __call ($func, $args)
 
 __construct ($name=null, array $data=[], $dataName= '')
 
 __destruct ()
 
 addDBData ()
 Stub. More...
 
 addDBDataOnce ()
 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)
 
 setContentLang ($lang)
 
 setupAllTestDBs ()
 Set up all test DBs. More...
 
 setUserLang ($lang)
 
 testMediaWikiTestCaseParentSetupCalled ()
 Make sure MediaWikiTestCase extending classes have called their parent setUp method. More...
 
 usesTemporaryTables ()
 

Static Public Member Functions

static assertNotTag ($matcher, $actual, $message= '', $isHtml=true)
 
static assertTag ($matcher, $actual, $message= '', $isHtml=true)
 Note: we are overriding this method to remove the deprecated error. More...
 
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...
 
static wfResetOutputBuffersBarrier ($buffer)
 Used as a marker to prevent wfResetOutputBuffers from breaking PHPUnit. More...
 

Public Attributes

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

Static Public Attributes

static TestUser[] $users
 

Protected Member Functions

 addTmpFiles ($files)
 
 arrayWrap (array $elements)
 Utility method taking an array of elements and wrapping each element in its own array. More...
 
 assertArrayEquals (array $expected, array $actual, $ordered=false, $named=false)
 Assert that two arrays are equal. 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 ()
 
 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...
 
 insertPage ($pageName, $text= 'Sample page for unit test.')
 Insert a new page. More...
 
 isWikitextNS ($ns)
 Returns true if the given namespace defaults to Wikitext according to $wgNamespaceContentModels. More...
 
 markTestSkippedIfNoDiff3 ()
 Check, if $wgDiff3 is set and ready to merge Will mark the calling test as skipped, if not ready. 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...
 
 setLogger ($channel, LoggerInterface $logger)
 Sets the logger for a specified channel, for the duration of the test. More...
 
 setMwGlobals ($pairs, $value=null)
 
 setUp ()
 
 stashMwGlobals ($globalKeys)
 Stashes the global, will be restored in tearDown() More...
 
 tearDown ()
 

Static Protected Member Functions

static getExternalStoreDatabaseConnections ()
 Gets master database connections for all of the ExternalStoreDB stores configured in $wgDefaultExternalStore. More...
 
static isUsingExternalStoreDB ()
 Check whether ExternalStoreDB is being used. More...
 
static setupDatabaseWithTestPrefix (DatabaseBase $db, $prefix)
 Setups a database with the given prefix. More...
 
static setupExternalStoreTestDBs ($testPrefix)
 Clones the External Store database(s) for testing. More...
 
static stripStringKeys (&$r)
 Utility function for eliminating all string keys from an array. More...
 

Protected Attributes

DatabaseBase $db
 Primary database. More...
 
array $supportedDBs
 
array $tablesUsed = []
 

Private Member Functions

 addCoreDBData ()
 
 assertEmpty2 ($value, $msg)
 Used as a compatibility method for phpunit < 3.7.32. More...
 
 oncePerClass ()
 
 resetDB ($db, $tablesUsed)
 Empty all tables so they can be repopulated for tests. More...
 
 restoreLoggers ()
 Restores loggers replaced by setLogger(). More...
 

Static Private Member Functions

static isNotUnittest ($table)
 
static tagMatch ($matcher, $actual, $isHtml=true)
 
static unprefixTable (&$tableName, $ind, $prefix)
 

Private Attributes

 $called = []
 $called tracks whether the setUp and tearDown method has been called. More...
 
LoggerInterface[] $loggers = []
 Holds original loggers which have been replaced by setLogger() More...
 
array $mwGlobals = []
 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 = []
 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

Definition at line 10 of file MediaWikiTestCase.php.

Constructor & Destructor Documentation

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

Definition at line 96 of file MediaWikiTestCase.php.

References $name.

MediaWikiTestCase::__destruct ( )

Definition at line 103 of file MediaWikiTestCase.php.

References class.

Member Function Documentation

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

Definition at line 902 of file MediaWikiTestCase.php.

References $args.

MediaWikiTestCase::addCoreDBData ( )
private
MediaWikiTestCase::addDBData ( )

Stub.

Subclasses may override this to prepare the database. Called before every test run (test function or data set).

See also
addDBDataOnce()
resetDB()
Since
1.18

Definition at line 606 of file MediaWikiTestCase.php.

Referenced by run().

MediaWikiTestCase::addDBDataOnce ( )

Stub.

If a test suite needs to add additional data to the database, it should implement this method and do so. This method is called once per test suite (i.e. once per class).

Note data added by this method may be removed by resetDB() depending on the contents of $tablesUsed.

To add additional data between test function runs, override prepareDB().

See also
addDBData()
resetDB()
Since
1.27

Definition at line 594 of file MediaWikiTestCase.php.

Referenced by run().

MediaWikiTestCase::addTmpFiles (   $files)
protected

Definition at line 255 of file MediaWikiTestCase.php.

References $files, and array().

Referenced by FileBackendTest\doTestDoOperationsPipeline(), and FileBackendTest\testStore().

MediaWikiTestCase::arrayWrap ( array  $elements)
protected

Utility method taking an array of elements and wrapping each element in its own array.

Useful for data providers that only return a single argument.

Since
1.20
Parameters
array$elements
Returns
array

Definition at line 1066 of file MediaWikiTestCase.php.

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

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

Used as a compatibility method for phpunit < 3.7.32.

Parameters
string$value
string$msg

Definition at line 920 of file MediaWikiTestCase.php.

References $value.

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

Definition at line 1118 of file MediaWikiTestCase.php.

static MediaWikiTestCase::assertNotTag (   $matcher,
  $actual,
  $message = '',
  $isHtml = true 
)
static
See also
MediaWikiTestCase::assertTag
Deprecated:
Parameters
array$matcher
string$actual
string$message
bool$isHtml

Definition at line 1435 of file MediaWikiTestCase.php.

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 " Database" to enable database test support, or list the tables under testing in $this->tablesUsed, or override the needsDB() method.

Definition at line 1026 of file MediaWikiTestCase.php.

References $res, as, DB_SLAVE, IDatabase\lastError(), needsDB(), DatabaseBase\select(), wfGetCaller(), and wfGetDB().

Referenced by LinksUpdateTest\assertLinksUpdate(), and LinksUpdateTest\assertRecentChangeByCategorization().

static MediaWikiTestCase::assertTag (   $matcher,
  $actual,
  $message = '',
  $isHtml = true 
)
static
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

Definition at line 1194 of file MediaWikiTestCase.php.

References $type.

Referenced by assertTypeOrValue(), MediaWiki\Auth\AbstractAuthenticationProviderTest\testAbstractAuthenticationProvider(), ActionTest\testActionFactory(), MediaWiki\Auth\AuthenticationRequestTest\testBasics(), JobQueueTest\testDeduplicationWhileClaimed(), MediaWiki\Auth\AuthenticationRequestTestCase\testGetFieldInfo(), and BagOStuffTest\testGetScopedLock().

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

Definition at line 1175 of file MediaWikiTestCase.php.

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

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

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

Definition at line 1371 of file MediaWikiTestCase.php.

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

Referenced by 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).

Definition at line 1355 of file MediaWikiTestCase.php.

References $html, and assertValidHtmlDocument().

MediaWikiTestCase::checkDbIsSupported ( )
protected
Exceptions
MWException
Since
1.18

Definition at line 969 of file MediaWikiTestCase.php.

References $supportedDBs.

Referenced by run().

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

Definition at line 1308 of file MediaWikiTestCase.php.

References $retval, and wfShellExec().

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

MediaWikiTestCase::dbPrefix ( )
Returns
string
Since
1.18

Definition at line 531 of file MediaWikiTestCase.php.

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

static MediaWikiTestCase::getExternalStoreDatabaseConnections ( )
staticprotected

Gets master database connections for all of the ExternalStoreDB stores configured in $wgDefaultExternalStore.

Returns
array Array of DatabaseBase master connections

Definition at line 807 of file MediaWikiTestCase.php.

References $wgDefaultExternalStore, array(), as, ExternalStore\getStoreObject(), global, and list.

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

Definition at line 214 of file MediaWikiTestCase.php.

References getNewTempFile(), and wfMkdirParents().

Referenced by TextPassDumperDatabaseTest\checkpointHelper(), NewParserTest\getUploadDir(), MigrateFileRepoLayoutTest\setUp(), MediaWikiMediaTestCase\setUp(), StoreBatchTest\setUp(), FileBackendTest\setUp(), ApiUploadTest\testUpload(), ApiUploadTest\testUploadChunks(), ApiUploadTest\testUploadSameContent(), ApiUploadTest\testUploadSameFileName(), and ApiUploadTest\testUploadStash().

MediaWikiTestCase::insertPage (   $pageName,
  $text = 'Sample page for unit test.' 
)
protected
static MediaWikiTestCase::isNotUnittest (   $table)
staticprivate

Definition at line 928 of file MediaWikiTestCase.php.

static MediaWikiTestCase::isUsingExternalStoreDB ( )
staticprotected

Check whether ExternalStoreDB is being used.

Returns
bool True if it's being used

Definition at line 829 of file MediaWikiTestCase.php.

References $wgDefaultExternalStore, array(), as, and global.

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

Definition at line 1211 of file MediaWikiTestCase.php.

References CONTENT_MODEL_WIKITEXT, and global.

Referenced by PrefixSearchTest\addDBDataOnce(), SearchEnginePrefixTest\addDBDataOnce(), SearchEngineTest\addDBDataOnce(), SearchEngineTest\fetchIds(), PrefixSearchTest\setUp(), SearchEnginePrefixTest\setUp(), NewParserTest\testParserTest(), and TitlePermissionTest\testQuickPermissions().

static MediaWikiTestCase::listTables (   $db)
static
Since
1.18
Parameters
DatabaseBase$db
Returns
array

Definition at line 939 of file MediaWikiTestCase.php.

References $tables, IDatabase\getType(), DatabaseBase\listTables(), DatabaseBase\listViews(), and DatabaseBase\tablePrefix().

MediaWikiTestCase::markTestSkippedIfNoDiff3 ( )
protected

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

Since
1.21

Definition at line 1284 of file MediaWikiTestCase.php.

References global.

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

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

Definition at line 427 of file MediaWikiTestCase.php.

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

Referenced by TextPassDumperDatabaseTest\addDBData(), GenderCacheTest\addDBDataOnce(), MediaWiki\Auth\LegacyHookPreAuthenticationProviderTest\hook(), AutoLoaderTest\setUp(), PageLangLogFormatterTest\setUp(), RevisionTest\setUp(), NewUsersLogFormatterTest\setUp(), BotPasswordTest\setUp(), TitleMethodsTest\setUp(), ApiRevisionDeleteTest\setUp(), ApiOptionsTest\setUp(), TitleTest\testCreateFragmentTitle(), MediaWiki\Session\SessionBackendTest\testDelaySave(), SpecialMyLanguageTest\testFindTitle(), SpecialPageFactoryTest\testGetAliasListRecursion(), UserTest\testGetCanonicalName(), SpecialPageFactoryTest\testGetNames(), MediaWiki\Auth\AbstractPasswordPrimaryAuthenticationProviderTest\testGetNewPasswordExpiry(), SpecialPageFactoryTest\testGetPage(), SpecialPageFactoryTest\testHookNotCalledTwice(), ApiMainTest\testLacksSameOriginSecurity(), MediaWiki\Session\SessionManagerTest\testLoadSessionInfoFromStore(), MediaWiki\Session\CookieSessionProviderTest\testPersistSession(), MediaWiki\Session\CookieSessionProviderTest\testPersistSessionWithHook(), MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProviderTest\testProviderChangeAuthenticationData(), MediaWiki\Auth\AbstractPrimaryAuthenticationProviderTest\testProviderNormalizeUsername(), LocalisationCacheTest\testRecacheFallbacksWithHooks(), MediaWiki\Session\SessionBackendTest\testRenew(), MediaWiki\Session\SessionBackendTest\testSave(), MediaWiki\Session\PHPSessionHandlerTest\testSessionHandling(), MediaWiki\Auth\ThrottlePreAuthenticationProviderTest\testTestForAccountCreation(), UserTest\testUserGetRightsHooks(), and MediaWiki\Auth\LegacyHookPreAuthenticationProviderTest\unhook().

MediaWikiTestCase::needsDB ( )
Returns
bool
Since
1.18

Definition at line 539 of file MediaWikiTestCase.php.

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

MediaWikiTestCase::objectAssociativeSort ( array $array)
protected

Does an associative sort that works for objects.

Since
1.20
Parameters
array$array

Definition at line 1132 of file MediaWikiTestCase.php.

References serialize().

Referenced by assertArrayEquals().

MediaWikiTestCase::oncePerClass ( )
private
Returns
bool

Definition at line 166 of file MediaWikiTestCase.php.

References class.

Referenced by run().

MediaWikiTestCase::resetDB (   $db,
  $tablesUsed 
)
private

Empty all tables so they can be repopulated for tests.

Parameters
DatabaseBase$db,|nullDatabase to reset
array$tablesUsedTables to reset

Definition at line 851 of file MediaWikiTestCase.php.

References addCoreDBData(), as, DatabaseBase\delete(), IDatabase\getType(), TestingAccessWrapper\newFromClass(), DatabaseBase\query(), LinkCache\singleton(), and DatabaseBase\tableName().

Referenced by run().

MediaWikiTestCase::restoreLoggers ( )
private

Restores loggers replaced by setLogger().

Since
1.27

Definition at line 504 of file MediaWikiTestCase.php.

References as, and TestingAccessWrapper\newFromObject().

Referenced by tearDown().

MediaWikiTestCase::run ( PHPUnit_Framework_TestResult  $result = null)
MediaWikiTestCase::setCliArg (   $offset,
  $value 
)
Since
1.18
Parameters
string$offset
mixed$value

Definition at line 991 of file MediaWikiTestCase.php.

References PHPUnitMaintClass\$additionalOptions, and $value.

MediaWikiTestCase::setLogger (   $channel,
LoggerInterface  $logger 
)
protected

Sets the logger for a specified channel, for the duration of the test.

Since
1.27
Parameters
string$channel
LoggerInterface$logger

Definition at line 478 of file MediaWikiTestCase.php.

References TestingAccessWrapper\newFromObject().

Referenced by MediaWikiTestCaseTest\testLoggersAreRestoredOnTearDown().

MediaWikiTestCase::setMwGlobals (   $pairs,
  $value = null 
)
protected

Definition at line 360 of file MediaWikiTestCase.php.

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

Referenced by BackupDumperPageTest\addDBData(), EditPageTest\assertEdit(), OutputPageTest\assertTransformCssMediaCase(), mergeMwGlobalArrayValue(), PrefixSearchTest\searchProvision(), SearchEnginePrefixTest\searchProvision(), TitleTest\secureAndSplitGlobals(), setContentLang(), ImagePageTest\setUp(), MediaWikiTest\setUp(), MWGrantsTest\setUp(), ResourceLoaderTest\setUp(), PageLangLogFormatterTest\setUp(), HtmlTest\setUp(), MessageTest\setUp(), RevisionTest\setUp(), GitInfoTest\setUp(), GlobalTest\setUp(), MWTimestampTest\setUp(), TestSample\setUp(), TitleTest\setUp(), ContentHandlerTest\setUp(), XmlTest\setUp(), LinkFilterTest\setUp(), BitmapMetadataHandlerTest\setUp(), BitmapScalingTest\setUp(), SvgTest\setUp(), FormatMetadataTest\setUp(), WfThumbIsStandardTest\setUp(), MWCryptHKDFTest\setUp(), LanguageConverterTest\setUp(), LocalisationCacheTest\setUp(), JpegTest\setUp(), WikiPageTestContentHandlerUseDB\setUp(), RevisionTestContentHandlerUseDB\setUp(), ApiTestCaseUpload\setUp(), ApiQueryTest\setUp(), LocalFileTest\setUp(), TemplateParserTest\setUp(), BotPasswordTest\setUp(), CSSMinTest\setUp(), WikiMapTest\setUp(), ImagePage404Test\setUp(), TextContentTest\setUp(), UploadBaseTest\setUp(), UploadFromUrlTest\setUp(), CssContentTest\setUp(), ExportTest\setUp(), SpecialPageTest\setUp(), ExifRotationTest\setUp(), ExifTest\setUp(), ActionTest\setUp(), ExifBitmapTest\setUp(), TiffTest\setUp(), SpecialRecentchangesTest\setUp(), EditPageTest\setUp(), ExtraParserTest\setUp(), MediaWiki\Auth\UserDataAuthenticationRequestTest\setUp(), UserTest\setUp(), MWNamespaceTest\setUp(), ApiTestCase\setUp(), ApiEditPageTest\setUp(), SearchEngineTest\setUp(), CategoryMembershipChangeJobTest\setUp(), RCCacheEntryFactoryTest\setUp(), TitlePermissionTest\setUp(), OldChangesListTest\setUp(), WfParseUrlTest\setUp(), SearchUpdateTest\setUp(), NaiveImportTitleFactoryTest\setUp(), NamespaceImportTitleFactoryTest\setUp(), SubpageImportTitleFactoryTest\setUp(), MediaWikiPageLinkRendererTest\setUp(), LinksUpdateTest\setUp(), MediaWikiTitleCodecTest\setUp(), MediaWiki\Auth\AuthManagerTest\setUp(), LogFormatterTest\setUp(), PreferencesTest\setUp(), MagicVariableTest\setUp(), PrefixSearchTest\setUp(), SearchEnginePrefixTest\setUp(), ResourceLoaderTestCase\setUp(), NewParserTest\setUp(), MediaWiki\Session\BotPasswordSessionProviderTest\setUp(), DumpTestCase\setUp(), RepoGroupTest\setUpForeignRepo(), setUserLang(), InterwikiTest\testArrayStorage(), FileBackendTest\testAsyncWrites(), MediaWiki\Auth\AuthManagerTest\testAutoAccountCreation(), BotPasswordTest\testBasics(), MediaWiki\Auth\AuthManagerTest\testBeginAccountCreation(), ApiLoginTest\testBotPassword(), UploadStashTest\testBug29408(), SpecialPreferencesTest\testBug41337(), FileTest\testCanAnimateThumbIfAppropriate(), InterwikiTest\testCDBStorage(), MediaWiki\Auth\AuthManagerTest\testCheckAccountCreatePermissions(), MediaWiki\Auth\AbstractPasswordPrimaryAuthenticationProviderTest\testCheckPasswordValidity(), UserTest\testCheckPasswordValidity(), ExtraParserTest\testCleanSigDisabled(), RevisionTest\testCompressRevisionTextUtf8Gzip(), SpecialPageFactoryTest\testConflictResolution(), MediaWiki\Auth\ThrottlerTest\testConstructor(), MediaWiki\Auth\AuthManagerTest\testContinueAccountCreation(), MediaWiki\Session\CookieSessionProviderTest\testCookieData(), EditPageTest\testCreatePage(), EditPageTest\testCreatePageTrx(), ResourceLoaderTest\testCreatingNewResourceLoaderCallsRegistrationHook(), InterwikiTest\testDatabaseStorage(), GlobalTest\testDebugFunctionTest(), ApiDocumentationTest\testDocumentationExists(), DeferredUpdatesTest\testDoUpdatesCLI(), DeferredUpdatesTest\testDoUpdatesWeb(), BadTitleErrorTest\testExceptionSetsStatusCode(), ThrottledErrorTest\testExceptionSetsStatusCode(), ExtensionRegistryTest\testExportExtractedDataGlobals(), ExternalStoreTest\testExternalFetchFromURL(), SideBarTest\testExternalUrlsRequireADescription(), CentralIdLookupTest\testFactory(), SpecialMyLanguageTest\testFindTitle(), RepoGroupTest\testForEachForeignRepoNone(), LinkerTest\testFormatComment(), LinkerTest\testFormatLinksInComment(), FileTest\testGenerateBucketsIfNeeded(), ContentHandlerTest\testGetAutosummary(), ContentHandlerTest\testGetContentText_NonTextContent_fail(), ContentHandlerTest\testGetContentText_NonTextContent_ignore(), ContentHandlerTest\testGetContentText_NonTextContent_serialize(), ContentHandlerTest\testGetContentText_Null(), ContentHandlerTest\testGetContentText_TextContent(), WebRequestTest\testGetIP(), WebRequestTest\testGetIpLackOfRemoteAddrThrowAnException(), ResourceLoaderTest\testGetLoadScript(), SpecialPageFactoryTest\testGetLocalNameFor(), ResourceLoaderStartUpModuleTest\testGetModuleRegistrations(), TitleTest\testGetPageViewLanguage(), HttpTest\testGetProxy(), CssContentTest\testGetRedirectTarget(), JavaScriptContentTest\testGetRedirectTarget(), WikiPageTest\testGetRedirectTarget(), MediaWiki\Session\ImmutableSessionProviderWithCookieTest\testGetSessionIdFromCookie(), FileTest\testGetThumbnailBucket(), SpecialPageFactoryTest\testGetTitleForAlias(), WikiMapTest\testGetWiki(), RepoGroupTest\testHasForeignRepoNegative(), RequestContextTest\testImportScopedSession(), MessageTest\testInContentLanguageOverride(), ImportLogFormatterTest\testInterwikiLogDatabaseRows(), LocalIdLookupTest\testIsAttachedShared(), MWExceptionTest\testisCommandLine(), TextContentTest\testIsCountable(), WikiPageTest\testIsCountable(), RecentChangeTest\testIsInRCLifespan(), MergeHistoryTest\testIsValidMerge(), MovePageTest\testIsValidMove(), TitleTest\testIsValidMoveOperation(), MWExceptionTest\testJsonserializeexceptionBacktracingDisabled(), MWExceptionTest\testJsonserializeexceptionBacktracingEnabled(), MWExceptionTest\testJsonserializeexceptionKeys(), LBFactoryTest\testLBFactorySimpleServer(), LBFactoryTest\testLBFactorySimpleServers(), MediaWiki\Auth\UserDataAuthenticationRequestTest\testLoadFromSubmission(), BotPasswordTest\testLogin(), CssContentHandlerTest\testMakeRedirectContent(), JavaScriptContentHandlerTest\testMakeRedirectContent(), OutputPageTest\testMakeResourceLoaderLink(), UploadBaseTest\testMaxUploadSize(), ExifRotationTest\testMetadataAutoRotate(), ExifRotationTest\testMetadataAutoRotateUnsupported(), ExifRotationTest\testMetadataNoAutoRotate(), BitmapMetadataHandlerTest\testMultilingualCascade(), MailAddressTest\testNewFromUser(), MediaWikiSiteTest\testNormalizePageTitle(), LinksUpdateTest\testOnAddingAndRemovingCategory_recentChangesRowIsAdded(), LinksUpdateTest\testOnAddingAndRemovingCategoryToTemplates_embeddingPagesAreIgnored(), MediaWiki\Session\ImmutableSessionProviderWithCookieTest\testPersistSession(), JpegPixelFormatTest\testPixelFormatRendering(), ResourceLoaderModuleTest\testPlaceholderize(), CdnCacheUpdateTest\testPurgeMergeWeb(), MediaWiki\Auth\CheckBlocksSecondaryAuthenticationProviderTest\testRangeBlock(), MessageTest\testRawHtmlInMsg(), ResourceLoaderStartUpModuleTest\testRegistrationsMinified(), ErrorPageErrorTest\testReport(), SpecialPageFactoryTest\testResolveAlias(), SideBarTest\testRespectExternallinktarget(), SideBarTest\testRespectWgnofollowlinks(), ExifRotationTest\testRotationRenderingNoAutoRotate(), MWExceptionTest\testRunHooks(), SpecialSearchTest\testSearchTermIsNotExpanded(), MediaWiki\Session\PHPSessionHandlerTest\testSessionHandling(), MediaWiki\Auth\AuthManagerTest\testSetDefaultUserOptions(), MediaWikiTestCaseTest\testSetGlobalsAreRestoredOnTearDown(), MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProviderTest\testSetPasswordResetFlag(), MediaWiki\Logger\LegacyLoggerTest\testShouldEmit(), ExifBitmapTest\testSwappingICCProfile(), SideBarTest\testTestAttributesAssertionHelper(), ApiQueryTest\testTitlePartToKey(), ApiQueryTest\testTitlesGetNormalized(), MailAddressTest\testToString(), LinksUpdateTest\testUpdate_categorylinks(), LinksUpdateTest\testUpdate_langlinks(), LinksUpdateTest\testUpdate_page_props_without_sortkey(), EditPageTest\testUpdatePage(), EditPageTest\testUpdatePageTrx(), JavaScriptContentTest\testUpdateRedirect(), ApiUploadTest\testUploadChunks(), ApiUploadTest\testUploadStash(), MWExceptionTest\testUseMessageCache(), MWExceptionTest\testUseOutputPage(), TimeAdjustTest\testUserAdjust(), LinkerTest\testUserLink(), ResourceLoaderModuleTest\testValidateScriptFile(), WfExpandUrlTest\testWfExpandUrl(), TitleTest\testWgWhitelistReadRegexp(), AutoLoaderTest\testWrongCaseClass(), AutoLoaderTest\testWrongCaseSerializedClass(), and GlobalTest\wfWikiID().

MediaWikiTestCase::setUp ( )
protected
MediaWikiTestCase::setupAllTestDBs ( )

Set up all test DBs.

Definition at line 721 of file MediaWikiTestCase.php.

References $wgDBprefix, dbPrefix(), and global.

Referenced by run().

static MediaWikiTestCase::setupDatabaseWithTestPrefix ( DatabaseBase  $db,
  $prefix 
)
staticprotected

Setups a database with the given prefix.

If reuseDB is true and certain conditions apply, it will just change the prefix. Otherwise, it will clone the tables and change the prefix.

Clones all tables in the given database (whatever database that connection has open), to versions with the test prefix.

Parameters
DatabaseBase$dbDatabase to use
string$prefixPrefix to use for test tables
Returns
bool True if tables were cloned, false if only the prefix was changed

Definition at line 703 of file MediaWikiTestCase.php.

References CloneDatabase\changePrefix(), and IDatabase\getType().

static MediaWikiTestCase::setupExternalStoreTestDBs (   $testPrefix)
staticprotected

Clones the External Store database(s) for testing.

Parameters
string$testPrefixPrefix for test tables

Definition at line 785 of file MediaWikiTestCase.php.

References as.

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

Definition at line 757 of file MediaWikiTestCase.php.

References IDatabase\getType(), DatabaseBase\query(), and DatabaseBase\tablePrefix().

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

Definition at line 387 of file MediaWikiTestCase.php.

References $e, $GLOBALS, as, serialize(), and unserialize().

Referenced by GlobalVarConfigTest\maybeStashGlobal(), setMwGlobals(), LocalIdLookupTest\setUp(), MediaWiki\Auth\AuthManagerTest\setUp(), MediaWiki\Auth\AuthManagerTest\testAutoAccountCreation(), MediaWiki\Auth\AuthManagerTest\testCheckAccountCreatePermissions(), MediaWikiTestCaseTest\testExceptionThrownWhenStashingNonExistentGlobals(), MediaWiki\Auth\TemporaryPasswordAuthenticationRequestTest\testNewRandom(), and MediaWikiTestCaseTest\testStashedGlobalsAreRestoredOnTearDown().

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.

Definition at line 1150 of file MediaWikiTestCase.php.

References as.

static MediaWikiTestCase::tagMatch (   $matcher,
  $actual,
  $isHtml = true 
)
staticprivate
Parameters
array$matcher
string$actual
bool$isHtml
Returns
bool

Definition at line 1403 of file MediaWikiTestCase.php.

References load.

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

Definition at line 672 of file MediaWikiTestCase.php.

References $type, as, CloneDatabase\changePrefix(), global, and JobQueueGroup\singleton().

Referenced by MediaWikiPHPUnitBootstrap\__destruct().

MediaWikiTestCase::testMediaWikiTestCaseParentSetupCalled ( )
final

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

Definition at line 322 of file MediaWikiTestCase.php.

References class.

static MediaWikiTestCase::unprefixTable ( $tableName,
  $ind,
  $prefix 
)
staticprivate

Definition at line 924 of file MediaWikiTestCase.php.

MediaWikiTestCase::usesTemporaryTables ( )
Since
1.21
Returns
bool

Definition at line 184 of file MediaWikiTestCase.php.

static MediaWikiTestCase::wfResetOutputBuffersBarrier (   $buffer)
static

Used as a marker to prevent wfResetOutputBuffers from breaking PHPUnit.

Returns
string

Definition at line 1445 of file MediaWikiTestCase.php.

References $buffer.

Member Data Documentation

MediaWikiTestCase::$called = []
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.

Definition at line 23 of file MediaWikiTestCase.php.

Referenced by SpecialPageFactoryTest\testGetAliasListRecursion(), MediaWiki\Session\SessionManagerTest\testLoadSessionInfoFromStore(), and HtmlCheckMatrixTest\testValidateCallsUserDefinedValidationCallback().

MediaWikiTestCase::$dbSetup = false
staticprivate

Definition at line 47 of file MediaWikiTestCase.php.

LoggerInterface [] MediaWikiTestCase::$loggers = []
private

Holds original loggers which have been replaced by setLogger()

Definition at line 77 of file MediaWikiTestCase.php.

array MediaWikiTestCase::$mwGlobals = []
private

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

See also setMwGlobals().

Definition at line 71 of file MediaWikiTestCase.php.

MediaWikiTestCase::$oldTablePrefix = false
staticprivate

Definition at line 48 of file MediaWikiTestCase.php.

int MediaWikiTestCase::$phpErrorLevel
private

Original value of PHP's error_reporting setting.

Definition at line 55 of file MediaWikiTestCase.php.

MediaWikiTestCase::$reuseDB = false
staticprivate

Definition at line 46 of file MediaWikiTestCase.php.

array MediaWikiTestCase::$supportedDBs
protected
Initial value:
= [
'mysql',
'sqlite',
'postgres',
'oracle'
]
Since
1.18

Definition at line 89 of file MediaWikiTestCase.php.

Referenced by checkDbIsSupported().

array MediaWikiTestCase::$tablesUsed = []
protected
Since
1.19

Definition at line 43 of file MediaWikiTestCase.php.

array MediaWikiTestCase::$tmpFiles = []
private

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

Definition at line 63 of file MediaWikiTestCase.php.

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

TestUser [] MediaWikiTestCase::$users
static
Since
1.20

Definition at line 29 of file MediaWikiTestCase.php.

MediaWikiTestCase::$useTemporaryTables = true
staticprivate

Definition at line 45 of file MediaWikiTestCase.php.

const MediaWikiTestCase::DB_PREFIX = 'unittest_'

Table name prefixes.

Oracle likes it shorter.

Definition at line 82 of file MediaWikiTestCase.php.

Referenced by TestUser\assertNotReal().

const MediaWikiTestCase::ORA_DB_PREFIX = 'ut_'

Definition at line 83 of file MediaWikiTestCase.php.

Referenced by TestUser\assertNotReal().


The documentation for this class was generated from the following file: