15 self::$apiUrl = $wgServer .
wfScript(
'api' );
20 'sysop' => static::getTestSysop(),
21 'uploader' => static::getTestUser(),
25 'wgAuth' =>
new MediaWiki\Auth\AuthManagerAuthPlugin,
27 'wgUser' => self::$users[
'sysop']->getUser(),
76 if ( is_null( $session ) ) {
78 $session = $wgRequest->getSessionArray();
86 $wgRequest =
new FauxRequest( $params,
true, $session );
92 $context = $this->apiContext->newTestContext( $wgRequest, $wgUser );
101 $module->getResult()->getResultData( null, [
'Strip' =>
'all' ] ),
103 $context->getRequest()->getSessionArray()
106 if ( $appendModule ) {
107 $results[] = $module;
130 if ( $session === null ) {
131 $session = $wgRequest->getSessionArray();
134 if ( isset( $session[
'wsToken'] ) && $session[
'wsToken'] ) {
137 $session[
'wsTokenSecrets'][
'default'] = $session[
'wsToken'];
140 $params[
'token'] = hash_hmac(
'md5',
$timestamp, $session[
'wsToken'] ) .
146 throw new Exception(
"Session token not available" );
150 protected function doLogin( $testUser =
'sysop' ) {
151 if ( $testUser === null ) {
152 $testUser = static::getTestSysop();
153 } elseif ( is_string( $testUser ) && array_key_exists( $testUser, self::$users ) ) {
154 $testUser = self::$users[ $testUser ];
155 } elseif ( !$testUser instanceof
TestUser ) {
156 throw new MWException(
"Can not log in to undefined user $testUser" );
161 'lgname' => $testUser->getUser()->getName(),
162 'lgpassword' => $testUser->getPassword() ] );
164 $token = $data[0][
'login'][
'token'];
170 'lgname' => $testUser->getUser()->getName(),
171 'lgpassword' => $testUser->getPassword(),
176 if ( $data[0][
'login'][
'result'] ===
'Success' ) {
179 $wgUser = $testUser->getUser();
188 'action' =>
'tokens',
189 'type' =>
'edit|delete|protect|move|block|unblock|watch'
190 ], $session,
false, $user->
getUser() );
192 if ( !array_key_exists(
'tokens', $data[0] ) ) {
193 throw new MWException(
'Api failed to return a token list' );
196 return $data[0][
'tokens'];
200 $groups = PHPUnit_Util_Test::getGroups( get_class( $this ) );
201 $constraint = PHPUnit_Framework_Assert::logicalOr(
202 $this->contains(
'medium' ),
203 $this->contains(
'large' )
205 $this->assertThat( $groups, $constraint,
206 'ApiTestCase::setUp can be slow, tests must be "medium" or "large"'
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
the array() calling protocol came about after MediaWiki 1.4rc1.
wfScript($script= 'index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
if(!$wgDBerrorLogTZ) $wgRequest
static newFromText($text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
when a variable name is used in a it is silently declared as a new local masking the global
wfTimestamp($outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
getTokenList(TestUser $user, $session=null)
static getMain()
Static methods.
doLogin($testUser= 'sysop')
This is the main API class, used for both external and internal processing.
namespace and then decline to actually register it file or subcat img or subcat $title
static makeContent($text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
ApiTestContext $apiContext
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
doApiRequest(array $params, array $session=null, $appendModule=false, User $user=null)
Does the API request and returns the result.
Wraps the user object, so we can also retain full access to properties like password if we log in via...
editPage($pageName, $text, $summary= '', $defaultNs=NS_MAIN)
Edits or creates a page/revision.
$wgServer
URL of the server.
doApiRequestWithToken(array $params, array $session=null, User $user=null)
Add an edit token to the API request This is cheating a bit – we grab a token in the correct format ...
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached $page