MediaWiki  master
MediaWikiTestCase Class Reference

Inherited by ApiGeneratorTest, ArticleTest, BaseDumpTest, BitmapMetadataHandlerTest, BitmapScalingTest, CdbTest, CLDRPluralRuleEvaluatorTest, CleanUpTest, ContentHandlerTest, CssContentTest, CSSJanusTest, CSSMinTest, DatabaseSqliteTest, DatabaseSQLTest, DatabaseTest, DeviceDetectionTest, DiffHistoryBlobTest, DummyExtensionsTest, EditPageTest, ExifBitmapTest, ExifRotationTest, ExifTest, ExternalStoreTest, ExtraParserTest, FauxResponseTest, FetchTextTest, FileBackendTest, FileRepoTest, FormatMetadataTest, FormOptionsInitializationTest, FormOptionsTest, GenericArrayObjectTest, GetSlaveServerTest, GIFHandlerTest, GIFMetadataExtractorTest, GlobalTest, GlobalWithDBTest, HooksTest, HtmlTest, HttpTest, IEUrlExtensionTest, InstallDocFormatterTest, IPTCTest, IPTest, JavaScriptMinifierTest, JpegMetadataExtractorTest, JpegTest, JsonTest, LanguageClassesTestCase, LicensesTest, LinksUpdateTest, LocalFileTest, LocalisationCacheTest, MagicVariableTest, MaintenanceTest, MediaHandlerTest, MediaWikiLangTestCase, MWDebugTest, MWFunctionTest, MWNamespaceTest, NewParserTest, ORMRowTest, ORMTableTest, ParserOptionsTest, ParserOutputTest, ParserPreloadTest, PathRouterTest, PNGHandlerTest, PNGMetadataExtractorTest, PreferencesTest, PrefixUniquenessTest, PreprocessorTest, ProcessCacheLRUTest, QueryAllSpecialPagesTest, RecentChangeTest, RequestContextTest, ResourceLoaderTest, ResourcesTest, RevisionStorageTest, RevisionTest, SanitizerTest, SanitizerValidateEmailTest, SearchEngineTest, SearchUpdateTest, SeleniumConfigurationTest, ServicesJsonTest, SiteConfigurationTest, SiteListTest, SitesTest, SpecialRecentchangesTest, SpecialSearchTest, StoreBatchTest, StructureTest, SVGMetadataExtractorTest, TagHookTest, TextContentTest, TiffTest, TimestampTest, TitleMethodsTest, TitleTest, UploadStashTest, UploadTest, UserTest, WebRequestTest, wfAssembleUrl, wfBaseName, wfBCP47, wfExpandUrl, wfGetCaller, wfRemoveDotSegments, wfShorthandToIntegerTest, wfTimestamp, wfUrlencodeTest, XmlJs, XmlSelectTest, XmlTest, 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)

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.
 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 ()
 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 iff the given namespace defaults to Wikitext according to $wgNamespaceContentModels.
 listTables ()
 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
 $oldTablePrefix
 $reuseDB = false
 $supportedDBs
 $tablesUsed = array()
 $useTemporaryTables = true

Private Member Functions

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

Static Private Member Functions

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

Private Attributes

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

Detailed Description

Definition at line 3 of file MediaWikiTestCase.php.


Constructor & Destructor Documentation

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

Member Function Documentation

MediaWikiTestCase::__call ( func,
args 
)

Reimplemented in MWNamespaceTest.

Definition at line 396 of file MediaWikiTestCase.php.

Definition at line 292 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 FetchTextTest, NewParserTest, BackupDumperLoggerTest, SearchEngineTest, TextPassDumperTest, BlockTest, BackupDumperPageTest, ApiBlockTest, and GenderCacheTest.

Definition at line 290 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 537 of file MediaWikiTestCase.php.

Referenced by SiteArrayTest\elementInstancesProvider(), 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 558 of file MediaWikiTestCase.php.

Referenced by SiteListTest\testGetGlobalIdentifiers(), and TextContentTest\testGetParserOutput().

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

Definition at line 414 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 587 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 497 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 664 of file MediaWikiTestCase.php.

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

Definition at line 447 of file MediaWikiTestCase.php.

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

Referenced by TextPassDumperTest\addDBData(), RevisionStorageTest\createPage(), and WikiPageTest\newPage().

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

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

Definition at line 349 of file MediaWikiTestCase.php.

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

Definition at line 423 of file MediaWikiTestCase.php.

MediaWikiTestCase::isWikitextNS ( ns) [protected]

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

Parameters:
int$nsThe namespace ID to check
Returns:
bool
Since:
1.21

Definition at line 682 of file MediaWikiTestCase.php.

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

Definition at line 427 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 249 of file MediaWikiTestCase.php.

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

Definition at line 271 of file MediaWikiTestCase.php.

Does an associative sort that works for objects.

Since:
1.20
Parameters:
array$array

Definition at line 601 of file MediaWikiTestCase.php.

Empty all tables so they can be repopulated for tests.

Definition at line 375 of file MediaWikiTestCase.php.

MediaWikiTestCase::run ( PHPUnit_Framework_TestResult $  result = NULL)
MediaWikiTestCase::setCliArg ( offset,
value 
)

Definition at line 461 of file MediaWikiTestCase.php.

MediaWikiTestCase::setUp ( ) [protected]

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

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

Definition at line 130 of file MediaWikiTestCase.php.

Referenced by TitleMethodsTest\setup().

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

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

Definition at line 418 of file MediaWikiTestCase.php.


Member Data Documentation

DatabaseBase MediaWikiTestCase::$db [protected]

Reimplemented in DatabaseSqliteTest, and DatabaseTest.

Definition at line 15 of file MediaWikiTestCase.php.

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

Definition at line 21 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 35 of file MediaWikiTestCase.php.

MediaWikiTestCase::$oldTablePrefix [protected]

Definition at line 16 of file MediaWikiTestCase.php.

MediaWikiTestCase::$regex = ''

Reimplemented in NewParserTest.

Definition at line 5 of file MediaWikiTestCase.php.

MediaWikiTestCase::$reuseDB = false [protected]

Definition at line 18 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 43 of file MediaWikiTestCase.php.

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

Definition at line 19 of file MediaWikiTestCase.php.

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

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

Definition at line 28 of file MediaWikiTestCase.php.

MediaWikiTestCase::$users [static]

Reimplemented in UploadStashTest.

Definition at line 11 of file MediaWikiTestCase.php.

MediaWikiTestCase::$useTemporaryTables = true [protected]

Definition at line 17 of file MediaWikiTestCase.php.

const MediaWikiTestCase::DB_PREFIX = 'unittest_'

Table name prefixes.

Oracle likes it shorter.

Definition at line 40 of file MediaWikiTestCase.php.

Definition at line 41 of file MediaWikiTestCase.php.


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