MediaWiki REL1_31
ApiTestCase Class Reference
Inheritance diagram for ApiTestCase:
Collaboration diagram for ApiTestCase:

Public Member Functions

 testApiTestGroup ()
 @coversNothing
 
- 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 apiExceptionHasCode (ApiUsageException $ex, $code)
 
- 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.
 

Protected Member Functions

 doApiRequest (array $params, array $session=null, $appendModule=false, User $user=null, $tokenType=null)
 Does the API request and returns the result.
 
 doApiRequestWithToken (array $params, array $session=null, User $user=null, $tokenType='auto')
 Convenience function to access the token parameter of doApiRequest() more succinctly.
 
 doLogin ( $testUser=null)
 Previously this would do API requests to log in, as well as setting $wgUser and the request context's user.
 
 editPage ( $pageName, $text, $summary='', $defaultNs=NS_MAIN)
 Edits or creates a page/revision.
 
 getTokenList (TestUser $user, $session=null)
 
 revisionDelete ( $rev, array $value=[Revision::DELETED_TEXT=> 1], $comment='')
 Revision-deletes a revision.
 
 setExpectedApiException ( $msg, $code=null, array $data=null, $httpCode=0)
 Expect an ApiUsageException to be thrown with the given parameters, which are the same as ApiUsageException::newWithMessage()'s parameters.
 
 setUp ()
 
 tearDown ()
 
- 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.
 
 stashMwGlobals ( $globalKeys)
 Stashes the global, will be restored in tearDown()
 

Static Protected Member Functions

static getErrorFormatter ()
 
- 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.
 

Protected Attributes

ApiTestContext $apiContext
 
- Protected Attributes inherited from MediaWikiTestCase
Database $db
 Primary database.
 
array $supportedDBs
 
array $tablesUsed = []
 

Static Protected Attributes

static $apiUrl
 
static $errorFormatter = null
 

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
 

Detailed Description

Definition at line 5 of file ApiTestCase.php.

Member Function Documentation

◆ apiExceptionHasCode()

◆ doApiRequest()

ApiTestCase::doApiRequest ( array $params,
array $session = null,
$appendModule = false,
User $user = null,
$tokenType = null )
protected

Does the API request and returns the result.

The returned value is an array containing

  • the result data (array)
  • the request (WebRequest)
  • the session data of the request (array)
  • if $appendModule is true, the Api module $module
Parameters
array$params
array | null$session
bool$appendModule
User | null$user
string | null$tokenTypeSet to a string like 'csrf' to send an appropriate token
Exceptions
ApiUsageException
Returns
array

Reimplemented in UploadFromUrlTest.

Definition at line 100 of file ApiTestCase.php.

References $context, $params, $user, $value, $wgRequest, $wgUser, RequestContext\getMain(), ApiQueryTokens\getToken(), and ApiQueryTokens\getTokenTypeSalts().

Referenced by ApiQueryTestBase\check(), doApiRequestWithToken(), ApiBlockTest\doBlock(), ApiQueryRecentChangesIntegrationTest\doGeneratorRecentChangesRequest(), ApiQueryWatchlistRawIntegrationTest\doGeneratorWatchlistRawRequest(), ApiQueryWatchlistIntegrationTest\doGeneratorWatchlistRequest(), ApiQueryRecentChangesIntegrationTest\doListRecentChangesRequest(), ApiQueryWatchlistRawIntegrationTest\doListWatchlistRawRequest(), ApiQueryWatchlistIntegrationTest\doListWatchlistRequest(), ApiParseTest\doTestLangLinks(), ApiLogoutTest\doUserLogout(), getTokenList(), ApiLogoutTest\getUserCsrfTokenFromApi(), ApiQueryContinueTestBase\query(), ApiQueryTitleBlacklistTest\testAntiSpoofIntegration(), ApiLoginTest\testApiLoginBadPass(), ApiLoginTest\testApiLoginGoodPass(), ApiLoginTest\testApiLoginNoName(), ApiMainTest\testAssert(), ApiMainTest\testAssertUser(), ApiBlockTest\testBlockingActionWithNoToken(), ApiLoginTest\testBotPassword(), ApiParseTest\testCategoriesHtml(), ApiQueryTitleBlacklistTest\testCheckingBlackListedTitle(), ApiQueryTitleBlacklistTest\testCheckingUnlistedTitle(), ApiCheckTokenTest\testCheckTokenExpired(), ApiCheckTokenTest\testCheckTokenInvalid(), ApiCheckTokenTest\testCheckTokenSuffixWarning(), ApiCheckTokenTest\testCheckTokenValid(), ApiClearHasMsgTest\testClearFlag(), ApiQueryRevisionsTest\testContentComesWithContentModelAndFormat(), ApiDeleteTest\testDeletionWithoutPermission(), ApiComparePagesTest\testDiff(), ApiDisabledTest\testDisabled(), ApiParseTest\testDisableTidy(), ApiParseTest\testEffectiveLangLinks(), ApiParseTest\testExistingSection(), ApiParseTest\testFollowedRedirect(), ApiParseTest\testFollowedRedirectById(), ApiParseTest\testFormatCategories(), ApiWatchTest\testGetRollbackToken(), ApiParseTest\testHeadHtml(), ApiParseTest\testHeadItems(), ApiParseTest\testHeadItemsWithSkin(), ApiRevisionDeleteTest\testHidingRevisions(), ApiParseTest\testIndicators(), ApiParseTest\testIndicatorsWithSkin(), ApiQueryContributionsTest\testInterwikiUser(), ApiParseTest\testInvalidSection(), ApiParseTest\testInvalidTitle(), ApiParseTest\testIwlinks(), ApiParseTest\testLimitReports(), ApiUploadTest\testLogin(), ApiLoginTest\testLoginWithNoSameOriginSecurity(), ApiParseTest\testModules(), ApiParseTest\testModulesWithSkin(), ApiParseTest\testNewSection(), ApiParseTest\testNewSectionWithPage(), ApiParseTest\testNonexistentOldId(), ApiParseTest\testNonexistentPage(), ApiParseTest\testNoPst(), ApiParseTest\testOnlyPst(), ApiParseTest\testParseById(), ApiParseTest\testParseByName(), ApiParseTest\testParseByOldId(), ApiParseTest\testParseTree(), ApiParseTest\testParseTreeNonWikitext(), ApiQueryAllPagesTest\testPrefixNormalizationSearchBug(), ApiParseTest\testPst(), ApiPurgeTest\testPurgeMainPage(), ApiParseTest\testRevDel(), ApiParseTest\testRevDelNoPermission(), ApiParseTest\testRevId(), ApiParseTest\testRevidNoText(), ApiLoginTest\testRunLogin(), ApiParseTest\testSection(), ApiParseTest\testSectionNoContent(), ApiParseTest\testSerializationError(), ApiQueryContributionsTest\testSorting(), ApiParseTest\testSuppressed(), ApiQueryTitleBlacklistTest\testTboverride(), ApiParseTest\testTextNoContentModel(), ApiParseTest\testTitleNoText(), ApiParseTest\testTitleProvided(), ApiQueryTest\testTitlesAreRejectedIfInvalid(), ApiQueryTest\testTitlesGetNormalized(), ApiQueryTest\testTitlesWithWhitespaces(), ApiParseTest\testTitleWithNonexistentRevId(), ApiParseTest\testTitleWithNonMatchingRevId(), ApiParseTest\testUnfollowedRedirect(), ApiRevisionDeleteTest\testUnhidingOutput(), ApiUploadTest\testUploadRequiresToken(), ApiWatchTest\testWatchClear(), ApiWatchTest\testWatchEdit(), ApiWatchTest\testWatchProtect(), ApiWatchTest\testWatchRollback(), ApiUserrightsTest\testWebToken(), and ApiUnblockTest\testWithNoToken().

◆ doApiRequestWithToken()

ApiTestCase::doApiRequestWithToken ( array $params,
array $session = null,
User $user = null,
$tokenType = 'auto' )
protected

Convenience function to access the token parameter of doApiRequest() more succinctly.

Parameters
array$paramsKey-value API params
array | null$sessionSession array
User | null$userA User object for the context
string$tokenTypeWhich token type to pass
Returns
array Result of the API call

Definition at line 170 of file ApiTestCase.php.

References doApiRequest().

Referenced by ApiUserrightsTest\doFailedRightsChange(), ApiUserrightsTest\doSuccessfulRightsChange(), ApiStashEditTest\testBasicEdit(), ApiDeleteTest\testDelete(), ApiDeleteTest\testDeleteAbortedByHook(), ApiDeleteTest\testDeleteNonexistent(), ApiDeleteTest\testDeleteUnwatch(), ApiDeleteTest\testDeleteWatch(), ApiDeleteTest\testDeleteWithoutTagPermission(), ApiDeleteTest\testDeleteWithTag(), ApiMoveTest\testFromWithFromid(), ApiMoveTest\testMove(), ApiMoveTest\testMoveById(), ApiMoveTest\testMoveNonexistent(), ApiMoveTest\testMoveNonexistentId(), ApiMoveTest\testMoveNoPermission(), ApiMoveTest\testMoveSubpages(), ApiMoveTest\testMoveSubpagesError(), ApiMoveTest\testMoveTalk(), ApiMoveTest\testMoveTalkFailed(), ApiMoveTest\testMoveToInvalidPageName(), ApiMoveTest\testPingLimiter(), ApiMoveTest\testSelfMove(), ApiSetNotificationTimestampIntegrationTest\testStuff(), ApiMoveTest\testSuppressRedirect(), ApiMoveTest\testSuppressRedirectNoPermission(), ApiMoveTest\testTagsNoPermission(), ApiUploadTest\testUpload(), ApiUploadTest\testUploadChunks(), ApiUploadTest\testUploadMissingParams(), ApiUploadTest\testUploadSameContent(), ApiUploadTest\testUploadSameFileName(), ApiUploadTest\testUploadStash(), and ApiUploadTest\testUploadZeroLength().

◆ doLogin()

ApiTestCase::doLogin ( $testUser = null)
protected

Previously this would do API requests to log in, as well as setting $wgUser and the request context's user.

The API requests are unnecessary, and the global-setting is unwanted, so this method should not be called. Instead, pass appropriate User values directly to functions that need them. For functions that still rely on $wgUser, set that directly. If you just want to log in the test sysop user, don't do anything – that's the default.

Parameters
TestUser | string$testUserObject, or key to self::$users such as 'sysop' or 'uploader'
Deprecated
since 1.31

Definition at line 186 of file ApiTestCase.php.

References $wgUser, and RequestContext\getMain().

Referenced by ApiQueryTitleBlacklistTest\setUp().

◆ editPage()

◆ getErrorFormatter()

static ApiTestCase::getErrorFormatter ( )
staticprotected

Definition at line 214 of file ApiTestCase.php.

References $errorFormatter.

◆ getTokenList()

ApiTestCase::getTokenList ( TestUser $user,
$session = null )
protected

◆ revisionDelete()

ApiTestCase::revisionDelete ( $rev,
array $value = [ Revision::DELETED_TEXT => 1 ],
$comment = '' )
protected

Revision-deletes a revision.

Parameters
Revision | int$revRevision to delete
array$valueKeys are Revision::DELETED_* flags. Values are 1 to set the bit, 0 to clear, -1 to leave alone. (All other values also clear the bit.)
string$commentDeletion comment

Definition at line 67 of file ApiTestCase.php.

References $rev, $value, RevisionDeleter\createList(), and RequestContext\getMain().

Referenced by ApiParseTest\addDBDataOnce().

◆ setExpectedApiException()

ApiTestCase::setExpectedApiException ( $msg,
$code = null,
array $data = null,
$httpCode = 0 )
protected

Expect an ApiUsageException to be thrown with the given parameters, which are the same as ApiUsageException::newWithMessage()'s parameters.

This allows checking for an exception whose text is given by a message key instead of text, so as not to hard-code the message's text into test code.

Definition at line 254 of file ApiTestCase.php.

References $code, and ApiUsageException\newWithMessage().

Referenced by ApiLogoutTest\testUserLogoutBadToken().

◆ setUp()

◆ tearDown()

ApiTestCase::tearDown ( )
protected

Reimplemented from MediaWikiTestCase.

Reimplemented in ApiQueryTitleBlacklistTest, ApiBlockTest, and ApiEditPageTest.

Definition at line 37 of file ApiTestCase.php.

◆ testApiTestGroup()

ApiTestCase::testApiTestGroup ( )

@coversNothing

Definition at line 237 of file ApiTestCase.php.

References contains.

Member Data Documentation

◆ $apiContext

ApiTestContext ApiTestCase::$apiContext
protected

Definition at line 13 of file ApiTestCase.php.

◆ $apiUrl

ApiTestCase::$apiUrl
staticprotected

Definition at line 6 of file ApiTestCase.php.

◆ $errorFormatter

ApiTestCase::$errorFormatter = null
staticprotected

Definition at line 8 of file ApiTestCase.php.

Referenced by getErrorFormatter().


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