MediaWiki REL1_31
ApiStructureTest Class Reference

Checks that all API modules, core and extensions, conform to the conventions: More...

Inheritance diagram for ApiStructureTest:
Collaboration diagram for ApiStructureTest:

Public Member Functions

 testDocumentationExists ( $path, array $globals)
 provideDocumentationExists
 
 testParameterConsistency ( $path)
 provideParameterConsistency
 
- Public Member Functions inherited from MediaWikiTestCase
 __construct ( $name=null, array $data=[], $dataName='')
 
 __destruct ()
 
 addDBData ()
 Stub.
 
 addDBDataOnce ()
 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)
 
 setContentLang ( $lang)
 
 setGroupPermissions ( $newPerms, $newKey=null, $newValue=null)
 Alters $wgGroupPermissions for the duration of the test.
 
 setupAllTestDBs ()
 Set up all test DBs.
 
 setUserLang ( $lang)
 
 testMediaWikiTestCaseParentSetupCalled ()
 Make sure MediaWikiTestCase extending classes have called their parent setUp method.
 
 usesTemporaryTables ()
 

Static Public Member Functions

static provideDocumentationExists ()
 
static provideParameterConsistency ()
 
- Static Public Member Functions inherited from MediaWikiTestCase
static getMutableTestUser ( $groups=[])
 Convenience method for getting a mutable test user.
 
static getTestSysop ()
 Convenience method for getting an immutable admin test user.
 
static getTestUser ( $groups=[])
 Convenience method for getting an immutable test user.
 
static listTables (IMaintainableDatabase $db)
 
static prepareServices (Config $bootstrapConfig)
 Prepare service configuration for unit testing.
 
static setUpBeforeClass ()
 
static setupTestDB (Database $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.
 
static wfResetOutputBuffersBarrier ( $buffer)
 Used as a marker to prevent wfResetOutputBuffers from breaking PHPUnit.
 

Static Protected Member Functions

static getSubModulePaths (ApiModuleManager $manager)
 Return paths of all submodules in an ApiModuleManager, recursively.
 
- Static Protected Member Functions inherited from MediaWikiTestCase
static getExternalStoreDatabaseConnections ()
 Gets master database connections for all of the ExternalStoreDB stores configured in $wgDefaultExternalStore.
 
static isUsingExternalStoreDB ()
 Check whether ExternalStoreDB is being used.
 
static resetGlobalServices (Config $bootstrapConfig=null)
 Reset global services, and install testing environment.
 
static setupDatabaseWithTestPrefix (IMaintainableDatabase $db, $prefix)
 Setups a database with the given prefix.
 
static setupExternalStoreTestDBs ( $testPrefix)
 Clones the External Store database(s) for testing.
 
static stripStringKeys (&$r)
 Utility function for eliminating all string keys from an array.
 

Private Member Functions

 checkMessage ( $msg, $what)
 Test a message.
 
 validateDefault ( $param, $config)
 Asserts that $default is a valid default for $type.
 
 validateType ( $types, $value, $param, $desc)
 Throws if $value does not match one of the types specified in $types.
 

Static Private Member Functions

static getMain ()
 Initialize/fetch the ApiMain instance for testing.
 

Static Private Attributes

static $constantNames = null
 
static ApiMain $main
 
static $paramAllowedTypes
 
static $paramProhibitedTypes
 
static $paramRequirements
 
static $paramTypes
 Values are an array, where each array value is a permitted type.
 
static array $testGlobals
 Sets of globals to test.
 

Additional Inherited Members

- Public Attributes inherited from MediaWikiTestCase
const DB_PREFIX = 'unittest_'
 Table name prefixes.
 
const ORA_DB_PREFIX = 'ut_'
 
- Static Public Attributes inherited from MediaWikiTestCase
static TestUser[] $users
 
- Protected Member Functions inherited from MediaWikiTestCase
 addTmpFiles ( $files)
 
 arrayWrap (array $elements)
 Utility method taking an array of elements and wrapping each element in its own array.
 
 assertArrayEquals (array $expected, array $actual, $ordered=false, $named=false)
 Assert that two arrays are equal.
 
 assertFileContains ( $fileName, $actualData, $createIfMissing=true, $msg='')
 Check whether file contains given data.
 
 assertHTMLEquals ( $expected, $actual, $msg='')
 Put each HTML element on its own line and then equals() the results.
 
 assertSelect ( $table, $fields, $condition, array $expectedRows, array $options=[], array $join_conds=[])
 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 ()
 
 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.
 
 getSchemaOverrides (IMaintainableDatabase $db)
 Stub.
 
 insertPage ( $pageName, $text='Sample page for unit test.', $namespace=null)
 Insert a new page.
 
 isWikitextNS ( $ns)
 Returns true if the given namespace defaults to Wikitext according to $wgNamespaceContentModels.
 
 markTestSkippedIfNoDiff3 ()
 Check, if $wgDiff3 is set and ready to merge Will mark the calling test as skipped, if not ready.
 
 mergeMwGlobalArrayValue ( $name, $values)
 Merges the given values into a MW global array variable.
 
 objectAssociativeSort (array &$array)
 Does an associative sort that works for objects.
 
 overrideMwServices (Config $configOverrides=null, array $services=[])
 Stashes the global instance of MediaWikiServices, and installs a new one, allowing test cases to override settings and services.
 
 setLogger ( $channel, LoggerInterface $logger)
 Sets the logger for a specified channel, for the duration of the test.
 
 setMwGlobals ( $pairs, $value=null)
 Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
 
 setService ( $name, $object)
 Sets a service, maintaining a stashed version of the previous service to be restored in tearDown.
 
 setTemporaryHook ( $hookName, $handler)
 Create a temporary hook handler which will be reset by tearDown.
 
 setUp ()
 
 stashMwGlobals ( $globalKeys)
 Stashes the global, will be restored in tearDown()
 
 tearDown ()
 
- Protected Attributes inherited from MediaWikiTestCase
Database $db
 Primary database.
 
array $supportedDBs
 
array $tablesUsed = []
 

Detailed Description

Checks that all API modules, core and extensions, conform to the conventions:

  • have documentation i18n messages (the test won't catch everything since i18n messages can vary based on the wiki configuration, but it should catch many cases for forgotten i18n)
  • do not have inconsistencies in the parameter definitions

    API

Definition at line 14 of file ApiStructureTest.php.

Member Function Documentation

◆ checkMessage()

ApiStructureTest::checkMessage (   $msg,
  $what 
)
private

Test a message.

Parameters
Message$msg
string$whatWhich message is being checked

Definition at line 124 of file ApiStructureTest.php.

References getContext(), and ApiBase\makeMessage().

Referenced by testDocumentationExists().

◆ getMain()

static ApiStructureTest::getMain ( )
staticprivate

Initialize/fetch the ApiMain instance for testing.

Returns
ApiMain

Definition at line 108 of file ApiStructureTest.php.

References $main, RequestContext\getMain(), and NS_SPECIAL.

Referenced by provideDocumentationExists(), provideParameterConsistency(), testDocumentationExists(), and testParameterConsistency().

◆ getSubModulePaths()

static ApiStructureTest::getSubModulePaths ( ApiModuleManager  $manager)
staticprotected

Return paths of all submodules in an ApiModuleManager, recursively.

Parameters
ApiModuleManager$manager
Returns
string[]

Definition at line 600 of file ApiStructureTest.php.

References $name, as, ApiModuleManager\getModule(), and ApiModuleManager\getNames().

Referenced by provideDocumentationExists(), and provideParameterConsistency().

◆ provideDocumentationExists()

static ApiStructureTest::provideDocumentationExists ( )
static

◆ provideParameterConsistency()

static ApiStructureTest::provideParameterConsistency ( )
static
Returns
array List of API module paths to test

Definition at line 583 of file ApiStructureTest.php.

References $main, $path, $ret, as, getMain(), ApiMain\getModuleManager(), ApiBase\getModulePath(), and getSubModulePaths().

◆ testDocumentationExists()

ApiStructureTest::testDocumentationExists (   $path,
array  $globals 
)

◆ testParameterConsistency()

◆ validateDefault()

ApiStructureTest::validateDefault (   $param,
  $config 
)
private

Asserts that $default is a valid default for $type.

Parameters
string$paramName of param, for error messages
array$configArray of configuration options for this parameter

Definition at line 483 of file ApiStructureTest.php.

References $e, $type, as, ApiBase\PARAM_DFLT, ApiBase\PARAM_EXTRA_NAMESPACES, ApiBase\PARAM_ISMULTI, ApiBase\PARAM_TYPE, validateDefault(), and wfTimestamp().

Referenced by testParameterConsistency(), and validateDefault().

◆ validateType()

ApiStructureTest::validateType (   $types,
  $value,
  $param,
  $desc 
)
private

Throws if $value does not match one of the types specified in $types.

Parameters
array$typesFrom self::$paramTypes array
mixed$valueValue to check
string$paramName of param we're checking, for error messages
string$descDescription for error messages

Definition at line 437 of file ApiStructureTest.php.

References $type, $value, as, MediaWikiTestCase\assertType(), and validateType().

Referenced by testParameterConsistency(), and validateType().

Member Data Documentation

◆ $constantNames

ApiStructureTest::$constantNames = null
staticprivate

Definition at line 102 of file ApiStructureTest.php.

◆ $main

ApiMain ApiStructureTest::$main
staticprivate

◆ $paramAllowedTypes

ApiStructureTest::$paramAllowedTypes
staticprivate
Initial value:
= [
ApiBase::PARAM_MAX => [ 'integer', 'limit' ],
ApiBase::PARAM_MAX2 => 'limit',
ApiBase::PARAM_MIN => [ 'integer', 'limit' ],
ApiBase::PARAM_ALL => 'array',
ApiBase::PARAM_MAX_BYTES => [ 'NULL', 'string', 'text', 'password' ],
ApiBase::PARAM_MAX_CHARS => [ 'NULL', 'string', 'text', 'password' ],
]
const PARAM_MAX2
(integer) Max value allowed for the parameter for users with the apihighlimits right,...
Definition ApiBase.php:96
const PARAM_SUBMODULE_MAP
(string[]) When PARAM_TYPE is 'submodule', map parameter values to submodule paths.
Definition ApiBase.php:165
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
Definition ApiBase.php:90
const PARAM_DEPRECATED_VALUES
(array) When PARAM_TYPE is an array, this indicates which of the values are deprecated.
Definition ApiBase.php:202
const PARAM_VALUE_LINKS
(string[]) When PARAM_TYPE is an array, this may be an array mapping those values to page titles whic...
Definition ApiBase.php:148
const PARAM_MAX_CHARS
(integer) Maximum length of a string in characters (unicode codepoints).
Definition ApiBase.php:227
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
Definition ApiBase.php:157
const PARAM_SUBMODULE_PARAM_PREFIX
(string) When PARAM_TYPE is 'submodule', used to indicate the 'g' prefix added by ApiQueryGeneratorBa...
Definition ApiBase.php:172
const PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
Definition ApiBase.php:99
const PARAM_MAX_BYTES
(integer) Maximum length of a string in bytes (in UTF-8 encoding).
Definition ApiBase.php:221
const PARAM_RANGE_ENFORCE
(boolean) For PARAM_TYPE 'integer', enforce PARAM_MIN and PARAM_MAX?
Definition ApiBase.php:117
const PARAM_EXTRA_NAMESPACES
(int[]) When PARAM_TYPE is 'namespace', include these as additional possible values.
Definition ApiBase.php:186
const PARAM_ALL
(boolean|string) When PARAM_TYPE has a defined set of values and PARAM_ISMULTI is true,...
Definition ApiBase.php:180

Definition at line 80 of file ApiStructureTest.php.

◆ $paramProhibitedTypes

ApiStructureTest::$paramProhibitedTypes
staticprivate
Initial value:
= [
ApiBase::PARAM_ISMULTI => [ 'boolean', 'limit', 'upload' ],
ApiBase::PARAM_ALL => 'namespace',
ApiBase::PARAM_SENSITIVE => 'password',
]
const PARAM_SENSITIVE
(boolean) Is the parameter sensitive? Note 'password'-type fields are always sensitive regardless of ...
Definition ApiBase.php:193
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition ApiBase.php:51

Definition at line 96 of file ApiStructureTest.php.

◆ $paramRequirements

ApiStructureTest::$paramRequirements
staticprivate
Initial value:
= [
],
],
]
const PARAM_ISMULTI_LIMIT1
(integer) Maximum number of values, for normal users.
Definition ApiBase.php:208
const PARAM_ALLOW_DUPLICATES
(boolean) Allow the same value to be set more than once when PARAM_ISMULTI is true?
Definition ApiBase.php:102
const PARAM_ISMULTI_LIMIT2
(integer) Maximum number of values, for users with the apihighimits right.
Definition ApiBase.php:215
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition hooks.txt:2006

Definition at line 66 of file ApiStructureTest.php.

◆ $paramTypes

ApiStructureTest::$paramTypes
staticprivate
Initial value:
= [
ApiBase::PARAM_ISMULTI => [ 'boolean' ],
ApiBase::PARAM_TYPE => [ 'string', [ 'string' ] ],
ApiBase::PARAM_MAX => [ 'integer' ],
ApiBase::PARAM_MAX2 => [ 'integer' ],
ApiBase::PARAM_MIN => [ 'integer' ],
ApiBase::PARAM_DEPRECATED => [ 'boolean' ],
ApiBase::PARAM_REQUIRED => [ 'boolean' ],
ApiBase::PARAM_RANGE_ENFORCE => [ 'boolean' ],
ApiBase::PARAM_HELP_MSG => [ 'string', 'array', Message::class ],
ApiBase::PARAM_HELP_MSG_APPEND => [ [ 'string', 'array', Message::class ] ],
ApiBase::PARAM_HELP_MSG_INFO => [ [ 'array' ] ],
ApiBase::PARAM_VALUE_LINKS => [ [ 'string' ] ],
ApiBase::PARAM_HELP_MSG_PER_VALUE => [ [ 'string', 'array', Message::class ] ],
ApiBase::PARAM_SUBMODULE_MAP => [ [ 'string' ] ],
ApiBase::PARAM_ALL => [ 'boolean', 'string' ],
ApiBase::PARAM_EXTRA_NAMESPACES => [ [ 'integer' ] ],
ApiBase::PARAM_SENSITIVE => [ 'boolean' ],
ApiBase::PARAM_MAX_BYTES => [ 'integer' ],
ApiBase::PARAM_MAX_CHARS => [ 'integer' ],
]
const PARAM_REQUIRED
(boolean) Is the parameter required?
Definition ApiBase.php:111
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
Definition ApiBase.php:105
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
Definition ApiBase.php:87
const PARAM_HELP_MSG_INFO
(array) Specify additional information tags for the parameter.
Definition ApiBase.php:141
const PARAM_HELP_MSG_APPEND
((string|array|Message)[]) Specify additional i18n messages to append to the normal message for this ...
Definition ApiBase.php:131
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition ApiBase.php:124

Values are an array, where each array value is a permitted type.

A type can be a string, which is the name of an internal type or a class/interface. Or it can be an array, in which case the value must be an array whose elements are the types given in the array (e.g., [ 'string', integer' ] means an array whose entries are strings and/or integers).

Definition at line 37 of file ApiStructureTest.php.

◆ $testGlobals

array ApiStructureTest::$testGlobals
staticprivate
Initial value:
= [
[
'MiserMode' => false,
],
[
'MiserMode' => true,
],
]

Sets of globals to test.

Each array element is input to HashConfig

Definition at line 20 of file ApiStructureTest.php.


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