3 abstract class ApiTestCase
extends MediaWikiLangTestCase
{
7 global $wgContLang, $wgAuth, $wgMemc, $wgRequest, $wgUser;
10 $wgMemc = new EmptyBagOStuff();
11 $wgContLang = Language
::factory( 'en' );
12 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
13 $wgRequest = new FauxRequest( array() );
16 'sysop' => new ApiTestUser(
19 'api_test_sysop@sample.com',
22 'uploader' => new ApiTestUser(
25 'api_test_user@sample.com',
30 $wgUser = self
::$users['sysop']->user
;
34 protected function doApiRequest( $params, $session = null, $appendModule = false ) {
35 if ( is_null( $session ) ) {
39 $request = new FauxRequest( $params, true, $session );
40 $module = new ApiMain( $request, true );
43 return array( $module->getResultData(), $request, $request->getSessionArray() );
47 * Add an edit token to the API request
48 * This is cheating a bit -- we grab a token in the correct format and then add it to the pseudo-session and to the
49 * request, without actually requesting a "real" edit token
50 * @param $params: key-value API params
51 * @param $session: session array
53 protected function doApiRequestWithToken( $params, $session ) {
54 if ( $session['wsToken'] ) {
55 // add edit token to fake session
56 $session['wsEditToken'] = $session['wsToken'];
57 // add token to request parameters
58 $params['token'] = md5( $session['wsToken'] ) . User
::EDIT_TOKEN_SUFFIX
;
59 return $this->doApiRequest( $params, $session );
61 throw new Exception( "request data not in right format" );