MediaWiki  REL1_22
MediaWikiTestCase Class Reference

Inherited by ArticleTest, AutoLoaderTest, BagOStuffTest, BaseDumpTest, BitmapMetadataHandlerTest, BitmapScalingTest, CdbTest, CLDRPluralRuleEvaluatorTest, CleanUpTest, ContentHandlerTest, CssContentTest, CSSJanusTest, CSSMinTest, DatabaseMysqlBaseTest, DatabaseSqliteTest, DatabaseSQLTest, DatabaseTest, DiffHistoryBlobTest, DummyExtensionsTest, ExifBitmapTest, ExifRotationTest, ExifTest, ExternalStoreTest, ExtraParserTest, FallbackTest, FauxRequestTest, FauxResponseTest, FetchTextTest, FileBackendTest, FileRepoTest, FormatJsonTest, FormatMetadataTest, FormOptionsInitializationTest, FormOptionsTest, GenericArrayObjectTest, GetSlaveServerTest, GIFHandlerTest, GIFMetadataExtractorTest, GlobalTest, GlobalWithDBTest, HashRingTest, HooksTest, HtmlCheckMatrixTest, HtmlFormatterTest, HtmlTest, HttpTest, IEUrlExtensionTest, InstallDocFormatterTest, IPTCTest, IPTest, JavaScriptMinifierTest, JobQueueTest, JpegMetadataExtractorTest, JpegTest, LanguageClassesTestCase, LicensesTest, LinksUpdateTest, LocalFileTest, LocalisationCacheTest, MagicVariableTest, MaintenanceTest, MediaHandlerTest, MediaWikiLangTestCase, MWDebugTest, MWExceptionHandlerTest, MWFunctionTest, MWNamespaceTest, NewParserTest, OracleInstallerTest, ORMRowTest, ORMTableTest, OutputPageTest, ParserOutputTest, ParserPreloadTest, PathRouterTest, PNGHandlerTest, PNGMetadataExtractorTest, PreferencesTest, PrefixUniquenessTest, PreprocessorTest, ProcessCacheLRUTest, QueryAllSpecialPagesTest, RecentChangeTest, RequestContextTest, ResourceLoaderTest, ResourcesTest, RevisionStorageTest, RevisionTest, SanitizerTest, SanitizerValidateEmailTest, SearchUpdateTest, SiteConfigurationTest, SiteListTest, SiteSQLStoreTest, SiteTest, SpecialPreferencesTest, SpecialRecentchangesTest, SpecialSearchTest, StoreBatchTest, StringUtilsTest, StructureTest, SVGMetadataExtractorTest, TagHookTest, TidyTest, TiffTest, TitleMethodsTest, TitleTest, UIDGeneratorTest, UploadBaseTest, UploadStashTest, 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:

List of all members.

Public Member Functions

 __call ($func, $args)
 __construct ($name=null, array $data=array(), $dataName= '')
 addDBData ()
 Stub.
 dbPrefix ()
 getCliArg ($offset)
 hideDeprecated ($function)
 Don't throw a warning if $function is deprecated and called later.
 needsDB ()
 run (PHPUnit_Framework_TestResult $result=null)
 setCliArg ($offset, $value)
 testMediaWikiTestCaseParentSetupCalled ()
 Make sure MediaWikiTestCase extending classes have called their parent setUp method.
 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.
static teardownTestDB ()
 Restores MediaWiki to using the table set (table prefix) it was using before setupTestDB() was called.

Public Attributes

 $regex = ''
 $runDisabled = false
 $suite
const DB_PREFIX = 'unittest_'
 Table name prefixes.
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.
 assertArrayEquals (array $expected, array $actual, $ordered=false, $named=false)
 Assert that two arrays are equal.
 assertException ($code, $expected= 'Exception', $message= '')
 Asserts that an exception of the specified type occurs when running the provided code.
 assertHTMLEquals ($expected, $actual, $msg= '')
 Put each HTML element on its own line and then equals() the results.
 assertSelect ($table, $fields, $condition, array $expectedRows)
 Asserts that the given database query yields the rows given by $expectedRows.
 assertType ($type, $actual, $message= '')
 Asserts the type of the provided value.
 assertTypeOrValue ($type, $actual, $value=false, $message= '')
 Asserts that the provided variable is of the specified internal type or equals the $value argument.
 checkDbIsSupported ()
 checkHasDiff3 ()
 Check, if $wgDiff3 is set and ready to merge Will mark the calling test as skipped, if not ready.
 checkHasGzip ()
 Check whether we have the 'gzip' commandline utility, will skip the test whenever "gzip -V" fails.
 checkPHPExtension ($extName)
 Check if $extName is a loaded PHP extension, will skip the test whenever it is not loaded.
 getDefaultWikitextNS ()
 Returns the ID of a namespace that defaults to Wikitext.
 getNewTempDirectory ()
 obtains a new temporary directory
 getNewTempFile ()
 obtains a new temporary file name
 isWikitextNS ($ns)
 Returns true if the given namespace defaults to Wikitext according to $wgNamespaceContentModels.
 mergeMwGlobalArrayValue ($name, $values)
 Merges the given values into a MW global array variable.
 objectAssociativeSort (array &$array)
 Does an associative sort that works for objects.
 setMwGlobals ($pairs, $value=null)
 setUp ()
 setUp and tearDown should (where significant) happen in reverse order.
 tearDown ()

Static Protected Member Functions

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

Protected Attributes

DatabaseBase $db
 $supportedDBs
 $tablesUsed = array()

Private Member Functions

 addCoreDBData ()
 assertEmpty2 ($value, $msg)
 resetDB ()
 Empty all tables so they can be repopulated for tests.

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.
array $mwGlobals = array()
 Holds original values of MediaWiki configuration settings to be restored in tearDown().
array $tmpfiles = array()
 Holds the paths of temporary files/directories created through getNewTempFile, and getNewTempDirectory.

Static Private Attributes

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

Detailed Description

Definition at line 3 of file MediaWikiTestCase.php.


Constructor & Destructor Documentation


Member Function Documentation

MediaWikiTestCase::__call ( func,
args 
)

Reimplemented in MWNamespaceTest.

Definition at line 501 of file MediaWikiTestCase.php.

Definition at line 353 of file MediaWikiTestCase.php.

Stub.

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

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

Definition at line 350 of file MediaWikiTestCase.php.

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

Definition at line 648 of file MediaWikiTestCase.php.

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

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
boolean$orderedIf the order of the values should match
boolean$namedIf the keys should match

Definition at line 669 of file MediaWikiTestCase.php.

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

MediaWikiTestCase::assertEmpty2 ( value,
msg 
) [private]

Definition at line 519 of file MediaWikiTestCase.php.

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

Definition at line 930 of file MediaWikiTestCase.php.

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 698 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:
$tableString|Array the table(s) to query
$fieldsString|Array the columns to include in the result (and to sort by)
$conditionString|Array "where" condition(s)
$expectedRowsArray - an 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.

Definition at line 608 of file MediaWikiTestCase.php.

Referenced by LinksUpdateTest\assertLinksUpdate().

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 774 of file MediaWikiTestCase.php.

Referenced by ApiQueryTestBase\validateRequestExpectedPair().

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 755 of file MediaWikiTestCase.php.

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

Definition at line 560 of file MediaWikiTestCase.php.

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 864 of file MediaWikiTestCase.php.

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

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 888 of file MediaWikiTestCase.php.

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

Returns the ID of a namespace that defaults to Wikitext.

Throws an MWException if there is none.

Returns:
int the ID of the wikitext Namespace
Since:
1.21

Definition at line 808 of file MediaWikiTestCase.php.

Referenced by TextPassDumperTest\addDBData(), EditPageTest\assertEdit(), RevisionStorageTest\createPage(), WikiPageTest\newPage(), EditPageTest\testAutoMerge(), TextContentTest\testDeletionUpdates(), and WikitextContentTest\testGetSecondaryDataUpdates().

obtains a new temporary directory

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

Returns:
string: absolute name of the temporary directory

Definition at line 149 of file MediaWikiTestCase.php.

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

static MediaWikiTestCase::isNotUnittest ( table) [static, private]

Definition at line 529 of file MediaWikiTestCase.php.

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 791 of file MediaWikiTestCase.php.

Referenced by SearchEngineTest\addDBData(), SearchEngineTest\fetchIds(), and NewParserTest\testParserTest().

static MediaWikiTestCase::listTables ( db) [static]

Definition at line 533 of file MediaWikiTestCase.php.

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.

Definition at line 309 of file MediaWikiTestCase.php.

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

Definition at line 331 of file MediaWikiTestCase.php.

Does an associative sort that works for objects.

Since:
1.20
Parameters:
array$array

Definition at line 712 of file MediaWikiTestCase.php.

Empty all tables so they can be repopulated for tests.

Definition at line 476 of file MediaWikiTestCase.php.

MediaWikiTestCase::setCliArg ( offset,
value 
)

Definition at line 573 of file MediaWikiTestCase.php.

MediaWikiTestCase::setMwGlobals ( pairs,
value = null 
) [protected]

Definition at line 279 of file MediaWikiTestCase.php.

Referenced by BackupDumperPageTest\addDBData(), EditPageTest\assertEdit(), MessageCacheTest\configureLanguages(), BitmapMetadataHandlerTest\setUp(), GlobalTest\setUp(), MessageTest\setUp(), BitmapScalingTest\setUp(), ExifTest\setUp(), HtmlTest\setUp(), JpegTest\setUp(), TiffTest\setUp(), LanguageConverterTest\setUp(), ResourceLoaderTest\setUp(), RevisionTest\setUp(), XmlTest\setUp(), ExtraParserTest\setUp(), MediaWikiLangTestCase\setUp(), TestSample\setUp(), TitleTest\setUp(), ExifBitmapTest\setUp(), ApiCreateAccountTest\setUp(), UploadFromUrlTest\setUp(), WikiPageTest_ContentHandlerUseDB\setUp(), CSSMinTest\setUp(), ApiTestCase\setUp(), RevisionTest_ContentHandlerUseDB\setUp(), CssContentTest\setUp(), LocalFileTest\setUp(), ExifRotationTest\setUp(), FormatMetadataTest\setUp(), ApiTestCaseUpload\setUp(), TextContentTest\setUp(), XmlSelectTest\setUp(), ContentHandlerTest\setUp(), MWNamespaceTest\setUp(), BlockTest\setUp(), UserTest\setUp(), TagHookTest\setUp(), JobQueueTest\setUp(), SearchUpdateTest\setUp(), WfParseUrlTest\setUp(), NewParserTest\setUp(), UploadStashTest\testBug29408(), SpecialPreferencesTest\testBug41337(), ExtraParserTest\testCleanSigDisabled(), RevisionTest\testCompressRevisionTextUtf8Gzip(), HtmlTest\testElementBasics(), ExternalStoreTest\testExternalFetchFromURL(), ContentHandlerTest\testGetContentText_NonTextContent_fail(), ContentHandlerTest\testGetContentText_NonTextContent_ignore(), ContentHandlerTest\testGetContentText_NonTextContent_serialize(), ContentHandlerTest\testGetContentText_Null(), ContentHandlerTest\testGetContentText_TextContent(), WebRequestTest\testGetIP(), MessageTest\testInContentLanguageDisabled(), MessageTest\testInContentLanguageEnabled(), TextContentTest\testIsCountable(), WikiPageTest\testIsCountable(), ExifRotationTest\testMetadataNoAutoRotate(), BitmapMetadataHandlerTest\testMultilingualCascade(), SanitizerTest\testRemovehtmltagsOnHtml5Tags(), ExifRotationTest\testRotationRenderingNoAutoRotate(), LinksUpdateTest\testUpdate_categorylinks(), ApiUploadTest\testUploadChunks(), ApiUploadTest\testUploadStash(), TimeAdjustTest\testUserAdjust(), LinkerTest\testUserLink(), and WfExpandUrlTest\testWfExpandUrl().

MediaWikiTestCase::setUp ( ) [protected]

setUp and tearDown should (where significant) happen in reverse order.

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

Definition at line 167 of file MediaWikiTestCase.php.

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.

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 443 of file MediaWikiTestCase.php.

static MediaWikiTestCase::stripStringKeys ( &$  r) [static, protected]

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:
$rmixed the array to remove string keys from.

Definition at line 730 of file MediaWikiTestCase.php.

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

Definition at line 413 of file MediaWikiTestCase.php.

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

Definition at line 241 of file MediaWikiTestCase.php.

static MediaWikiTestCase::unprefixTable ( tableName) [static, private]

Definition at line 523 of file MediaWikiTestCase.php.


Member Data Documentation

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.

Definition at line 20 of file MediaWikiTestCase.php.

Referenced by HtmlCheckMatrixTest\testValidateCallsUserDefinedValidationCallback().

MediaWikiTestCase::$dbSetup = false [static, private]

Definition at line 34 of file MediaWikiTestCase.php.

array MediaWikiTestCase::$mwGlobals = array() [private]

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

See also setMwGlobal().

Definition at line 49 of file MediaWikiTestCase.php.

MediaWikiTestCase::$oldTablePrefix = false [static, private]

Definition at line 35 of file MediaWikiTestCase.php.

MediaWikiTestCase::$regex = ''

Reimplemented in NewParserTest.

Definition at line 5 of file MediaWikiTestCase.php.

MediaWikiTestCase::$reuseDB = false [static, private]

Definition at line 33 of file MediaWikiTestCase.php.

MediaWikiTestCase::$runDisabled = false

Reimplemented in NewParserTest.

Definition at line 6 of file MediaWikiTestCase.php.

MediaWikiTestCase::$suite

Definition at line 4 of file MediaWikiTestCase.php.

MediaWikiTestCase::$supportedDBs [protected]
Initial value:
 array(
        'mysql',
        'sqlite',
        'postgres',
        'oracle'
    )

Definition at line 57 of file MediaWikiTestCase.php.

MediaWikiTestCase::$tablesUsed = array() [protected]

Definition at line 30 of file MediaWikiTestCase.php.

array MediaWikiTestCase::$tmpfiles = array() [private]

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

Definition at line 42 of file MediaWikiTestCase.php.

MediaWikiTestCase::$users [static]

Reimplemented in UploadStashTest.

Definition at line 25 of file MediaWikiTestCase.php.

MediaWikiTestCase::$useTemporaryTables = true [static, private]

Definition at line 32 of file MediaWikiTestCase.php.

const MediaWikiTestCase::DB_PREFIX = 'unittest_'

Table name prefixes.

Oracle likes it shorter.

Definition at line 54 of file MediaWikiTestCase.php.

Definition at line 55 of file MediaWikiTestCase.php.


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