MediaWiki  1.23.8
Go to the documentation of this file.
1 <?php
27 abstract class ApiQueryTestBase extends ApiTestCase {
29  const PARAM_ASSERT = <<<STR
30 Each parameter must be an array of two elements,
31 first - an array of params to the API call,
32 and the second array - expected results as returned by the API
33 STR;
40  protected function merge( /*...*/ ) {
41  $request = array();
42  $expected = array();
43  foreach ( func_get_args() as $v ) {
44  list( $req, $exp ) = $this->validateRequestExpectedPair( $v );
45  $request = array_merge_recursive( $request, $req );
46  $this->mergeExpected( $expected, $exp );
47  }
49  return array( $request, $expected );
50  }
56  private function validateRequestExpectedPair( $v ) {
57  $this->assertType( 'array', $v, self::PARAM_ASSERT );
58  $this->assertEquals( 2, count( $v ), self::PARAM_ASSERT );
59  $this->assertArrayHasKey( 0, $v, self::PARAM_ASSERT );
60  $this->assertArrayHasKey( 1, $v, self::PARAM_ASSERT );
61  $this->assertType( 'array', $v[0], self::PARAM_ASSERT );
62  $this->assertType( 'array', $v[1], self::PARAM_ASSERT );
64  return $v;
65  }
70  private function mergeExpected( &$all, $item ) {
71  foreach ( $item as $k => $v ) {
72  if ( array_key_exists( $k, $all ) ) {
73  if ( is_array( $all[$k] ) ) {
74  $this->mergeExpected( $all[$k], $v );
75  } else {
76  $this->assertEquals( $all[$k], $v );
77  }
78  } else {
79  $all[$k] = $v;
80  }
81  }
82  }
89  protected function check( $values ) {
90  list( $req, $exp ) = $this->validateRequestExpectedPair( $values );
91  if ( !array_key_exists( 'action', $req ) ) {
92  $req['action'] = 'query';
93  }
94  foreach ( $req as &$val ) {
95  if ( is_array( $val ) ) {
96  $val = implode( '|', array_unique( $val ) );
97  }
98  }
99  $result = $this->doApiRequest( $req );
100  $this->assertResult( array( 'query' => $exp ), $result[0], $req );
101  }
103  protected function assertResult( $exp, $result, $message = '' ) {
104  try {
105  $exp = self::sanitizeResultArray( $exp );
107  $this->assertEquals( $exp, $result );
108  } catch ( PHPUnit_Framework_ExpectationFailedException $e ) {
109  if ( is_array( $message ) ) {
110  $message = http_build_query( $message );
111  }
112  throw new PHPUnit_Framework_ExpectationFailedException(
113  $e->getMessage() . "\nRequest: $message",
114  new PHPUnit_Framework_ComparisonFailure(
115  $exp,
116  $result,
117  print_r( $exp, true ),
118  print_r( $result, true ),
119  false,
120  $e->getComparisonFailure()->getMessage() . "\nRequest: $message"
121  )
122  );
123  }
124  }
131  private static function sanitizeResultArray( $result ) {
132  unset( $result['pageid'] );
133  foreach ( $result as $key => $value ) {
134  if ( is_array( $value ) ) {
136  }
137  }
139  // Sort the result by keys, then take advantage of how array_merge will
140  // renumber numeric keys while leaving others alone.
141  ksort( $result );
142  return array_merge( $result );
143  }
144 }
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. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. $reader:XMLReader object $logInfo:Array of information Return false to stop further processing of the tag 'ImportHandlePageXMLTag':When parsing a XML tag in a page. $reader:XMLReader object $pageInfo:Array of information Return false to stop further processing of the tag 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information Return false to stop further processing of the tag 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. $reader:XMLReader object Return false to stop further processing of the tag 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. $reader:XMLReader object $revisionInfo:Array of information Return false to stop further processing of the tag '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 '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. '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 '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 '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 wfIsTrustedProxy() $ip:IP being check $result:Change this value to override the result of wfIsTrustedProxy() '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 User::isValidEmailAddr(), 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 'LanguageGetMagic':DEPRECATED, use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetSpecialPageAliases':DEPRECATED, use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language $specialPageAliases:associative array of magic words synonyms $lang:language code(string) '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:Associative array mapping language codes to prefixed links of the form "language:title". & $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. 'LinkBegin':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:1528
globals txt Globals are evil The original MediaWiki code relied on globals for processing context far too often MediaWiki development since then has been a story of slowly moving context out of global variables and into objects Storing processing context in object member variables allows those objects to be reused in a much more flexible way Consider the elegance of
Definition: globals.txt:10
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
Merges all requests parameter + expected values into one.
Definition: ApiQueryTestBase.php:40
validateRequestExpectedPair( $v)
Check that the parameter is a valid two element array, with the first element being API request and t...
Definition: ApiQueryTestBase.php:56
check( $values)
Checks that the request's result matches the expected results.
Definition: ApiQueryTestBase.php:89
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
mergeExpected(&$all, $item)
Recursively merges the expected values in the $item into the $all.
Definition: ApiQueryTestBase.php:70
assertResult( $exp, $result, $message='')
Definition: ApiQueryTestBase.php:103
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
Definition: ApiTestCase.php:3
Definition: styleTest.css.php:45
This class has some common functionality for testing query module.
Definition: ApiQueryTestBase.php:27
static sanitizeResultArray( $result)
Recursively ksorts a result array and removes any 'pageid' keys.
Definition: ApiQueryTestBase.php:131
doApiRequest(array $params, array $session=null, $appendModule=false, User $user=null)
Does the API request and returns the result.
Definition: ApiTestCase.php:74
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
if( $useReadline) $e
Definition: eval.php:66
assertType( $type, $actual, $message='')
Asserts the type of the provided value.
Definition: MediaWikiTestCase.php:869
Definition: ApiQueryTestBase.php:29