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

Public Member Functions

 testApiTestGroup ()
 

Static Public Member Functions

static apiExceptionHasCode (ApiUsageException $ex, $code)
 

Protected Member Functions

 doApiRequest (array $params, array $session=null, $appendModule=false, User $user=null, $tokenType=null)
 Does the API request and returns the result. More...
 
 doApiRequestWithToken (array $params, array $session=null, User $user=null, $tokenType='auto')
 Convenience function to access the token parameter of doApiRequest() more succinctly. More...
 
 doLogin ( $testUser=null)
 Previously this would do API requests to log in, as well as setting $wgUser and the request context's user. More...
 
 getTokenList (TestUser $user, $session=null)
 
 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. More...
 
 setUp ()
 
 tearDown ()
 
- Protected Member Functions inherited from MediaWikiLangTestCase
 setUp ()
 

Static Protected Member Functions

static getErrorFormatter ()
 

Protected Attributes

ApiTestContext $apiContext
 

Static Protected Attributes

static $apiUrl
 
static $errorFormatter = null
 

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

Definition at line 62 of file ApiTestCase.php.

References $context, $user, $value, $wgRequest, as, RequestContext\getMain(), ApiQueryTokens\getToken(), ApiQueryTokens\getTokenTypeSalts(), null, and MediaWiki\Auth\AuthManager\resetCache().

Referenced by ApiQueryTestBase\check(), doApiRequestWithToken(), ApiBlockTest\doBlock(), ApiQueryRecentChangesIntegrationTest\doGeneratorRecentChangesRequest(), ApiQueryWatchlistRawIntegrationTest\doGeneratorWatchlistRawRequest(), ApiQueryWatchlistIntegrationTest\doGeneratorWatchlistRequest(), ApiQueryRecentChangesIntegrationTest\doListRecentChangesRequest(), ApiQueryWatchlistRawIntegrationTest\doListWatchlistRawRequest(), ApiQueryWatchlistIntegrationTest\doListWatchlistRequest(), ApiQuerySiteinfoTest\doQuery(), ApiQueryLanguageinfoTest\doQuery(), ApiParseTest\doTestLangLinks(), ApiLoginTest\doUserLogin(), ApiLogoutTest\doUserLogout(), getTokenList(), ApiLogoutTest\getUserCsrfTokenFromApi(), ApiQueryContinueTestBase\query(), ApiMainTest\testAssert(), ApiMainTest\testAssertBeforeModule(), ApiMainTest\testAssertUser(), ApiBlockTest\testBlockingActionWithNoToken(), ApiBlockTest\testBlockingTooManyPageRestrictions(), ApiBlockTest\testBlockWithLargeRange(), ApiParseTest\testCategoriesHtml(), ApiCheckTokenTest\testCheckTokenExpired(), ApiCheckTokenTest\testCheckTokenInvalid(), ApiCheckTokenTest\testCheckTokenSuffixWarning(), ApiCheckTokenTest\testCheckTokenValid(), ApiClearHasMsgTest\testClearFlag(), ApiQueryRevisionsTest\testContentComesWithContentModelAndFormat(), ApiQueryAllRevisionsTest\testContentComesWithContentModelAndFormat(), ApiQuerySiteinfoTest\testContinuation(), ApiDeleteTest\testDeletionWithoutPermission(), ApiLoginTest\testDeprecatedUserLogin(), ApiComparePagesTest\testDiff(), ApiQueryDisabledTest\testDisabled(), ApiDisabledTest\testDisabled(), ApiParseTest\testDisableTidy(), ApiParseTest\testEffectiveLangLinks(), ApiQueryInfoTest\testExecute(), ApiQueryBlocksTest\testExecute(), ApiQueryBlocksTest\testExecuteBlock(), ApiQueryInfoTest\testExecuteEditActions(), ApiQueryInfoTest\testExecuteEditActionsFull(), ApiQueryInfoTest\testExecuteEditActionsFullBlock(), ApiQueryBlocksTest\testExecuteRestrictions(), ApiQueryBlocksTest\testExecuteSitewide(), ApiParseTest\testExistingSection(), ApiLoginTest\testExtendedDescription(), ApiParseTest\testFollowedRedirect(), ApiParseTest\testFollowedRedirectById(), ApiParseTest\testFormatCategories(), ApiWatchTest\testGetRollbackToken(), ApiParseTest\testHeadHtml(), ApiParseTest\testHeadItems(), ApiParseTest\testHeadItemsWithSkin(), ApiRevisionDeleteTest\testHidingRevisions(), ApiParseTest\testIndicators(), ApiParseTest\testIndicatorsWithSkin(), ApiQuerySearchTest\testInterwikiResults(), ApiQueryUserContribsTest\testInterwikiUser(), ApiParseTest\testInvalidSection(), ApiParseTest\testInvalidTitle(), ApiStashEditTest\testIsInternal(), ApiParseTest\testIwlinks(), ApiParseTest\testLimitReports(), ApiUploadTest\testLogin(), ApiParseTest\testModules(), ApiParseTest\testModulesWithSkin(), ApiParseTest\testNewSection(), ApiParseTest\testNewSectionWithPage(), ApiLoginTest\testNoName(), ApiParseTest\testNonexistentOldId(), ApiParseTest\testNonexistentPage(), ApiParseTest\testNoPst(), ApiLoginTest\testNoSameOriginSecurity(), ApiQueryPrefixSearchTest\testOffsetContinue(), 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(), ApiQuerySearchTest\testSearchResults(), ApiParseTest\testSection(), ApiParseTest\testSectionNoContent(), ApiParseTest\testSerializationError(), ApiQueryTest\testShouldNotExportPagesThatUserCanNotRead(), ApiQueryUserContribsTest\testSorting(), ApiParseTest\testSuppressed(), 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 132 of file ApiTestCase.php.

References $user, and doApiRequest().

Referenced by ApiUserrightsTest\doFailedRightsChange(), ApiStashEditTest\doStash(), ApiUserrightsTest\doSuccessfulRightsChange(), ApiUnblockTest\doUnblock(), ApiEditPageTest\testAppendInMediaWikiNamespace(), ApiEditPageTest\testAppendInMediaWikiNamespaceWithSerializationError(), ApiEditPageTest\testAppendNewSection(), ApiEditPageTest\testAppendNewSectionWithInvalidContentModel(), ApiEditPageTest\testAppendNewSectionWithSummary(), ApiEditPageTest\testAppendNewSectionWithTitle(), ApiEditPageTest\testAppendNewSectionWithTitleAndSummary(), ApiEditPageTest\testAppendToFirstSection(), ApiEditPageTest\testAppendToNonexistentSection(), ApiEditPageTest\testAppendToSection(), ApiEditPageTest\testAppendWithNonTextContentHandler(), ApiDeleteTest\testBatchedDelete(), ApiEditPageTest\testCheckDirectApiEditingDisallowed_forNonTextContent(), ApiEditPageTest\testCorrectContentFormat(), ApiEditPageTest\testCreateImageRedirectAnon(), ApiEditPageTest\testCreateImageRedirectLoggedIn(), ApiEditPageTest\testCreateOnly(), ApiDeleteTest\testDelete(), ApiDeleteTest\testDeleteAbortedByHook(), ApiDeleteTest\testDeleteNonexistent(), ApiDeleteTest\testDeleteUnwatch(), ApiDeleteTest\testDeleteWatch(), ApiDeleteTest\testDeleteWithoutTagPermission(), ApiDeleteTest\testDeleteWithTag(), ApiEditPageTest\testEdit(), ApiEditPageTest\testEdit_redirect(), ApiEditPageTest\testEdit_redirectText(), ApiEditPageTest\testEditAbortedByEditPageHookWithNoResult(), ApiEditPageTest\testEditAbortedByEditPageHookWithResult(), ApiEditPageTest\testEditAppend(), ApiEditPageTest\testEditConflict(), ApiEditPageTest\testEditConflict_newSection(), ApiEditPageTest\testEditConflict_T43990(), ApiEditPageTest\testEditMalformedSection(), ApiEditPageTest\testEditMinor(), ApiEditPageTest\testEditNewSection(), ApiEditPageTest\testEditRecreate(), ApiEditPageTest\testEditSection(), ApiEditPageTest\testEditUnwatch(), ApiEditPageTest\testEditWatch(), ApiEditPageTest\testEditWhileBlocked(), ApiEditPageTest\testEditWhileReadOnly(), ApiEditPageTest\testEditWithoutTagPermission(), ApiEditPageTest\testEditWithStartTimestamp(), ApiEditPageTest\testEditWithTag(), ApiMoveTest\testFromWithFromid(), ApiEditPageTest\testIncorrectMd5AppendText(), ApiEditPageTest\testIncorrectMd5PrependText(), ApiEditPageTest\testIncorrectMd5Text(), ApiEditPageTest\testMd5AppendText(), ApiEditPageTest\testMd5PrependAndAppendText(), ApiEditPageTest\testMd5PrependText(), ApiEditPageTest\testMd5Text(), ApiEditPageTest\testMismatchedContentFormat(), ApiMoveTest\testMove(), ApiMoveTest\testMoveById(), ApiMoveTest\testMoveNonexistent(), ApiMoveTest\testMoveNonexistentId(), ApiMoveTest\testMoveNoPermission(), ApiMoveTest\testMoveSubpages(), ApiMoveTest\testMoveSubpagesError(), ApiMoveTest\testMoveTalk(), ApiMoveTest\testMoveTalkFailed(), ApiMoveTest\testMoveToInvalidPageName(), ApiMoveTest\testMoveWhileBlocked(), ApiEditPageTest\testNoCreate(), ApiMoveTest\testPingLimiter(), ApiEditPageTest\testProhibitedAnonymousEdit(), ApiEditPageTest\testProhibitedChangeContentModel(), ApiEditPageTest\testReversedUndoAfter(), ApiMoveTest\testSelfMove(), ApiSetNotificationTimestampIntegrationTest\testStuff(), ApiEditPageTest\testSupportsDirectApiEditing_withContentHandlerOverride(), ApiMoveTest\testSuppressRedirect(), ApiMoveTest\testSuppressRedirectNoPermission(), ApiMoveTest\testTagsNoPermission(), ApiEditPageTest\testTooBigEdit(), ApiEditPageTest\testUndoAfterContentModelChange(), ApiEditPageTest\testUndoAfterToHiddenRev(), ApiEditPageTest\testUndoAfterToInvalidRev(), ApiEditPageTest\testUndoAfterToRevFromDifferentPage(), ApiEditPageTest\testUndoToInvalidRev(), ApiEditPageTest\testUndoToRevFromDifferentPage(), ApiEditPageTest\testUndoWithConflicts(), ApiEditPageTest\testUndoWithSwappedRevisions(), ApiEditPageTest\testUnsupportedContentFormat(), 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 148 of file ApiTestCase.php.

References RequestContext\getMain(), and null.

◆ getErrorFormatter()

static ApiTestCase::getErrorFormatter ( )
staticprotected

Definition at line 176 of file ApiTestCase.php.

References Language\factory(), and null.

◆ getTokenList()

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

◆ setExpectedApiException()

◆ setUp()

ApiTestCase::setUp ( )
protected

Definition at line 15 of file ApiTestCase.php.

References $wgServer, ApiQueryInfo\resetTokenCache(), and wfScript().

◆ tearDown()

ApiTestCase::tearDown ( )
protected

◆ testApiTestGroup()

ApiTestCase::testApiTestGroup ( )

Definition at line 199 of file ApiTestCase.php.

References class.

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.


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