MediaWiki  master
ApiQueryTestBase Class Reference

This class has some common functionality for testing query module. More...

Inheritance diagram for ApiQueryTestBase:
Collaboration diagram for ApiQueryTestBase:

Public Attributes

const PARAM_ASSERT
 

Protected Member Functions

 assertResult ( $exp, $result, $message='')
 
 check ( $values, array $session=null, $appendModule=false, User $user=null)
 Checks that the request's result matches the expected results. More...
 
 merge (... $arrays)
 Merges all requests parameter + expected values into one. More...
 
- Protected Member Functions inherited from ApiTestCase
 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 ()
 

Private Member Functions

 mergeExpected (&$all, $item)
 Recursively merges the expected values in the $item into the $all. More...
 
 validateRequestExpectedPair ( $v)
 Check that the parameter is a valid two element array, with the first element being API request and the second - expected result. More...
 

Static Private Member Functions

static sanitizeResultArray ( $result)
 Recursively ksorts a result array and removes any 'pageid' keys. More...
 

Additional Inherited Members

- Public Member Functions inherited from ApiTestCase
 testApiTestGroup ()
 
- Static Public Member Functions inherited from ApiTestCase
static apiExceptionHasCode (ApiUsageException $ex, $code)
 
- Static Protected Member Functions inherited from ApiTestCase
static getErrorFormatter ()
 
- Protected Attributes inherited from ApiTestCase
ApiTestContext $apiContext
 
- Static Protected Attributes inherited from ApiTestCase
static $apiUrl
 
static $errorFormatter = null
 

Detailed Description

This class has some common functionality for testing query module.

Definition at line 25 of file ApiQueryTestBase.php.

Member Function Documentation

◆ assertResult()

ApiQueryTestBase::assertResult (   $exp,
  $result,
  $message = '' 
)
protected

Definition at line 110 of file ApiQueryTestBase.php.

References $e.

Referenced by check(), and ApiQueryContinueTestBase\checkC().

◆ check()

ApiQueryTestBase::check (   $values,
array  $session = null,
  $appendModule = false,
User  $user = null 
)
protected

Checks that the request's result matches the expected results.

Assumes no rawcontinue and a complete batch.

Parameters
array$valuesArray is a two element [ request, expected_results ]
array | null$session
bool$appendModule
User | null$user

Definition at line 94 of file ApiQueryTestBase.php.

References $req, $user, as, assertResult(), ApiTestCase\doApiRequest(), list, and validateRequestExpectedPair().

Referenced by ApiQueryBasicTest\testAllTogether(), ApiQueryBasicTest\testGenerator(), ApiQueryBasicTest\testGeneratorRedirects(), ApiQueryBasicTest\testLists(), and ApiQueryBasicTest\testProps().

◆ merge()

ApiQueryTestBase::merge (   $arrays)
protected

Merges all requests parameter + expected values into one.

Parameters
array...$arrays List of arrays, each of which contains exactly two
Returns
array

Definition at line 38 of file ApiQueryTestBase.php.

References $req, $request, as, list, mergeExpected(), and validateRequestExpectedPair().

Referenced by ApiQueryBasicTest\testAllTogether(), and ApiQueryBasicTest\testGenerator().

◆ mergeExpected()

ApiQueryTestBase::mergeExpected ( $all,
  $item 
)
private

Recursively merges the expected values in the $item into the $all.

Parameters
array&$all
array$item

Definition at line 72 of file ApiQueryTestBase.php.

References as.

Referenced by merge().

◆ sanitizeResultArray()

static ApiQueryTestBase::sanitizeResultArray (   $result)
staticprivate

Recursively ksorts a result array and removes any 'pageid' keys.

Parameters
array$result
Returns
array

Definition at line 145 of file ApiQueryTestBase.php.

References $value, and as.

◆ validateRequestExpectedPair()

ApiQueryTestBase::validateRequestExpectedPair (   $v)
private

Check that the parameter is a valid two element array, with the first element being API request and the second - expected result.

Parameters
array$v
Returns
array

Definition at line 56 of file ApiQueryTestBase.php.

Referenced by check(), and merge().

Member Data Documentation

◆ PARAM_ASSERT

const ApiQueryTestBase::PARAM_ASSERT
Initial value:
= <<<STR
Each parameter must be an array of two elements,
first - an array of params to the API call,
and the second array - expected results as returned by the API
STR

Definition at line 27 of file ApiQueryTestBase.php.


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