MediaWiki  1.33.1
ApiContinuationManagerTest.php
Go to the documentation of this file.
1 <?php
2 
8 
9  private static function getManager( $continue, $allModules, $generatedModules ) {
11  $context->setRequest( new FauxRequest( [ 'continue' => $continue ] ) );
12  $main = new ApiMain( $context );
13  return new ApiContinuationManager( $main, $allModules, $generatedModules );
14  }
15 
16  public function testContinuation() {
17  $allModules = [
18  new MockApiQueryBase( 'mock1' ),
19  new MockApiQueryBase( 'mock2' ),
20  new MockApiQueryBase( 'mocklist' ),
21  ];
22  $generator = new MockApiQueryBase( 'generator' );
23 
24  $manager = self::getManager( '', $allModules, [ 'mock1', 'mock2' ] );
25  $this->assertSame( ApiMain::class, $manager->getSource() );
26  $this->assertSame( false, $manager->isGeneratorDone() );
27  $this->assertSame( $allModules, $manager->getRunModules() );
28  $manager->addContinueParam( $allModules[0], 'm1continue', [ 1, 2 ] );
29  $manager->addContinueParam( $allModules[2], 'mlcontinue', 2 );
30  $manager->addGeneratorContinueParam( $generator, 'gcontinue', 3 );
31  $this->assertSame( [ [
32  'mlcontinue' => 2,
33  'm1continue' => '1|2',
34  'continue' => '||mock2',
35  ], false ], $manager->getContinuation() );
36  $this->assertSame( [
37  'mock1' => [ 'm1continue' => '1|2' ],
38  'mocklist' => [ 'mlcontinue' => 2 ],
39  'generator' => [ 'gcontinue' => 3 ],
40  ], $manager->getRawContinuation() );
41 
42  $result = new ApiResult( 0 );
43  $manager->setContinuationIntoResult( $result );
44  $this->assertSame( [
45  'mlcontinue' => 2,
46  'm1continue' => '1|2',
47  'continue' => '||mock2',
48  ], $result->getResultData( 'continue' ) );
49  $this->assertSame( null, $result->getResultData( 'batchcomplete' ) );
50 
51  $manager = self::getManager( '', $allModules, [ 'mock1', 'mock2' ] );
52  $this->assertSame( false, $manager->isGeneratorDone() );
53  $this->assertSame( $allModules, $manager->getRunModules() );
54  $manager->addContinueParam( $allModules[0], 'm1continue', [ 1, 2 ] );
55  $manager->addGeneratorContinueParam( $generator, 'gcontinue', [ 3, 4 ] );
56  $this->assertSame( [ [
57  'm1continue' => '1|2',
58  'continue' => '||mock2|mocklist',
59  ], false ], $manager->getContinuation() );
60  $this->assertSame( [
61  'mock1' => [ 'm1continue' => '1|2' ],
62  'generator' => [ 'gcontinue' => '3|4' ],
63  ], $manager->getRawContinuation() );
64 
65  $manager = self::getManager( '', $allModules, [ 'mock1', 'mock2' ] );
66  $this->assertSame( false, $manager->isGeneratorDone() );
67  $this->assertSame( $allModules, $manager->getRunModules() );
68  $manager->addContinueParam( $allModules[2], 'mlcontinue', 2 );
69  $manager->addGeneratorContinueParam( $generator, 'gcontinue', 3 );
70  $this->assertSame( [ [
71  'mlcontinue' => 2,
72  'gcontinue' => 3,
73  'continue' => 'gcontinue||',
74  ], true ], $manager->getContinuation() );
75  $this->assertSame( [
76  'mocklist' => [ 'mlcontinue' => 2 ],
77  'generator' => [ 'gcontinue' => 3 ],
78  ], $manager->getRawContinuation() );
79 
80  $result = new ApiResult( 0 );
81  $manager->setContinuationIntoResult( $result );
82  $this->assertSame( [
83  'mlcontinue' => 2,
84  'gcontinue' => 3,
85  'continue' => 'gcontinue||',
86  ], $result->getResultData( 'continue' ) );
87  $this->assertSame( true, $result->getResultData( 'batchcomplete' ) );
88 
89  $manager = self::getManager( '', $allModules, [ 'mock1', 'mock2' ] );
90  $this->assertSame( false, $manager->isGeneratorDone() );
91  $this->assertSame( $allModules, $manager->getRunModules() );
92  $manager->addGeneratorContinueParam( $generator, 'gcontinue', 3 );
93  $this->assertSame( [ [
94  'gcontinue' => 3,
95  'continue' => 'gcontinue||mocklist',
96  ], true ], $manager->getContinuation() );
97  $this->assertSame( [
98  'generator' => [ 'gcontinue' => 3 ],
99  ], $manager->getRawContinuation() );
100 
101  $manager = self::getManager( '', $allModules, [ 'mock1', 'mock2' ] );
102  $this->assertSame( false, $manager->isGeneratorDone() );
103  $this->assertSame( $allModules, $manager->getRunModules() );
104  $manager->addContinueParam( $allModules[0], 'm1continue', [ 1, 2 ] );
105  $manager->addContinueParam( $allModules[2], 'mlcontinue', 2 );
106  $this->assertSame( [ [
107  'mlcontinue' => 2,
108  'm1continue' => '1|2',
109  'continue' => '||mock2',
110  ], false ], $manager->getContinuation() );
111  $this->assertSame( [
112  'mock1' => [ 'm1continue' => '1|2' ],
113  'mocklist' => [ 'mlcontinue' => 2 ],
114  ], $manager->getRawContinuation() );
115 
116  $manager = self::getManager( '', $allModules, [ 'mock1', 'mock2' ] );
117  $this->assertSame( false, $manager->isGeneratorDone() );
118  $this->assertSame( $allModules, $manager->getRunModules() );
119  $manager->addContinueParam( $allModules[0], 'm1continue', [ 1, 2 ] );
120  $this->assertSame( [ [
121  'm1continue' => '1|2',
122  'continue' => '||mock2|mocklist',
123  ], false ], $manager->getContinuation() );
124  $this->assertSame( [
125  'mock1' => [ 'm1continue' => '1|2' ],
126  ], $manager->getRawContinuation() );
127 
128  $manager = self::getManager( '', $allModules, [ 'mock1', 'mock2' ] );
129  $this->assertSame( false, $manager->isGeneratorDone() );
130  $this->assertSame( $allModules, $manager->getRunModules() );
131  $manager->addContinueParam( $allModules[2], 'mlcontinue', 2 );
132  $this->assertSame( [ [
133  'mlcontinue' => 2,
134  'continue' => '-||mock1|mock2',
135  ], true ], $manager->getContinuation() );
136  $this->assertSame( [
137  'mocklist' => [ 'mlcontinue' => 2 ],
138  ], $manager->getRawContinuation() );
139 
140  $manager = self::getManager( '', $allModules, [ 'mock1', 'mock2' ] );
141  $this->assertSame( false, $manager->isGeneratorDone() );
142  $this->assertSame( $allModules, $manager->getRunModules() );
143  $this->assertSame( [ [], true ], $manager->getContinuation() );
144  $this->assertSame( [], $manager->getRawContinuation() );
145 
146  $manager = self::getManager( '||mock2', $allModules, [ 'mock1', 'mock2' ] );
147  $this->assertSame( false, $manager->isGeneratorDone() );
148  $this->assertSame(
149  array_values( array_diff_key( $allModules, [ 1 => 1 ] ) ),
150  $manager->getRunModules()
151  );
152 
153  $manager = self::getManager( '-||', $allModules, [ 'mock1', 'mock2' ] );
154  $this->assertSame( true, $manager->isGeneratorDone() );
155  $this->assertSame(
156  array_values( array_diff_key( $allModules, [ 0 => 0, 1 => 1 ] ) ),
157  $manager->getRunModules()
158  );
159 
160  try {
161  self::getManager( 'foo', $allModules, [ 'mock1', 'mock2' ] );
162  $this->fail( 'Expected exception not thrown' );
163  } catch ( ApiUsageException $ex ) {
164  $this->assertTrue( ApiTestCase::apiExceptionHasCode( $ex, 'badcontinue' ),
165  'Expected exception'
166  );
167  }
168 
169  $manager = self::getManager(
170  '||mock2',
171  array_slice( $allModules, 0, 2 ),
172  [ 'mock1', 'mock2' ]
173  );
174  try {
175  $manager->addContinueParam( $allModules[1], 'm2continue', 1 );
176  $this->fail( 'Expected exception not thrown' );
177  } catch ( UnexpectedValueException $ex ) {
178  $this->assertSame(
179  'Module \'mock2\' was not supposed to have been executed, ' .
180  'but it was executed anyway',
181  $ex->getMessage(),
182  'Expected exception'
183  );
184  }
185  try {
186  $manager->addContinueParam( $allModules[2], 'mlcontinue', 1 );
187  $this->fail( 'Expected exception not thrown' );
188  } catch ( UnexpectedValueException $ex ) {
189  $this->assertSame(
190  'Module \'mocklist\' called ApiContinuationManager::addContinueParam ' .
191  'but was not passed to ApiContinuationManager::__construct',
192  $ex->getMessage(),
193  'Expected exception'
194  );
195  }
196  }
197 
198 }
ApiMain
This is the main API class, used for both external and internal processing.
Definition: ApiMain.php:41
FauxRequest
WebRequest clone which takes values from a provided array.
Definition: FauxRequest.php:33
ApiUsageException
Exception used to abort API execution with an error.
Definition: ApiUsageException.php:28
$context
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition: hooks.txt:2644
ApiContinuationManager
This manages continuation state.
Definition: ApiContinuationManager.php:26
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImgAuthModifyHeaders':Executed just before a file is streamed to a user via img_auth.php, allowing headers to be modified beforehand. $title:LinkTarget object & $headers:HTTP headers(name=> value, names are case insensitive). Two headers get special handling:If-Modified-Since(value must be a valid HTTP date) and Range(must be of the form "bytes=(\d*-\d*)") will be honored when streaming the file. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED since 1.28! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1991
ApiContinuationManagerTest\testContinuation
testContinuation()
Definition: ApiContinuationManagerTest.php:16
php
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
Definition: injection.txt:35
DerivativeContext
An IContextSource implementation which will inherit context from another source but allow individual ...
Definition: DerivativeContext.php:30
ApiContinuationManagerTest\getManager
static getManager( $continue, $allModules, $generatedModules)
Definition: ApiContinuationManagerTest.php:9
ApiResult
This class represents the result of the API operations.
Definition: ApiResult.php:35
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
ApiContinuationManagerTest
ApiContinuationManager API.
Definition: ApiContinuationManagerTest.php:7
$generator
$generator
Definition: generateLocalAutoload.php:13
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:430
ApiTestCase\apiExceptionHasCode
static apiExceptionHasCode(ApiUsageException $ex, $code)
Definition: ApiTestCase.php:187
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
MockApiQueryBase
Definition: MockApiQueryBase.php:2