* upgrade patches for oracle 1.17->1.19
[mediawiki.git] / tests / phpunit / includes / api / ApiTestCase.php
blob54da6904b11dcca97d138f65f360a958149c8067
1 <?php
3 abstract class ApiTestCase extends MediaWikiLangTestCase {
4 public static $users;
6 function setUp() {
7 global $wgContLang, $wgAuth, $wgMemc, $wgRequest, $wgUser;
9 parent::setUp();
10 $wgMemc = new EmptyBagOStuff();
11 $wgContLang = Language::factory( 'en' );
12 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
13 $wgRequest = new FauxRequest( array() );
15 self::$users = array(
16 'sysop' => new ApiTestUser(
17 'Apitestsysop',
18 'Api Test Sysop',
19 'api_test_sysop@sample.com',
20 array( 'sysop' )
22 'uploader' => new ApiTestUser(
23 'Apitestuser',
24 'Api Test User',
25 'api_test_user@sample.com',
26 array()
30 $wgUser = self::$users['sysop']->user;
34 protected function doApiRequest( $params, $session = null, $appendModule = false ) {
35 if ( is_null( $session ) ) {
36 $session = array();
39 $request = new FauxRequest( $params, true, $session );
40 $module = new ApiMain( $request, true );
41 $module->execute();
43 return array( $module->getResultData(), $request, $request->getSessionArray() );
46 /**
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 );
60 } else {
61 throw new Exception( "request data not in right format" );