* upgrade patches for oracle 1.17->1.19
[mediawiki.git] / tests / phpunit / includes / api / ApiSetup.php
blob7672faab9c6d9d96d47a20632e2487fc6ad9289b
1 <?php
3 abstract class ApiTestSetup extends MediaWikiLangTestCase {
4 protected $user;
5 protected $sysopUser;
6 protected static $apiUrl;
8 function setUp() {
9 global $wgServer, $wgContLang, $wgAuth, $wgMemc, $wgRequest;
11 parent::setUp();
12 self::$apiUrl = $wgServer . wfScript( 'api' );
14 $wgMemc = new EmptyBagOStuff;
15 $wgContLang = Language::factory( 'en' );
16 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
17 $wgRequest = new FauxRequest( array() );
18 $this->setupUser();
21 protected function doApiRequest( $params, $data = null, $appendModule = false ) {
22 $_SESSION = isset( $data[2] ) ? $data[2] : array();
24 $req = new FauxRequest( $params, true, $_SESSION );
25 $module = new ApiMain( $req, true );
26 $module->execute();
28 $data[0] = $module->getResultData();
29 $data[1] = $req;
30 $data[2] = $_SESSION;
32 if( $appendModule ) $data[3] = $module;
34 return $data;
37 function setupUser() {
38 if ( $this->user == null || $this->sysopUser == null ) {
39 $this->user = new UserWrapper( 'User for MediaWiki automated tests', User::randomPassword() );
40 $this->sysopUser = new UserWrapper( 'Sysop for MediaWiki automated tests', User::randomPassword(), 'sysop' );
43 $GLOBALS['wgUser'] = $this->sysopUser->user;
46 function doLogin() {
47 $data = $this->doApiRequest( array(
48 'action' => 'login',
49 'lgname' => $this->sysopUser->userName,
50 'lgpassword' => $this->sysopUser->password ) );
52 $token = $data[0]['login']['token'];
54 $data = $this->doApiRequest( array(
55 'action' => 'login',
56 "lgtoken" => $token,
57 "lgname" => $this->sysopUser->userName,
58 "lgpassword" => $this->sysopUser->password ), $data );
60 return $data;
63 function getTokenList( $user ) {
64 $GLOBALS['wgUser'] = $user->user;
65 $data = $this->doApiRequest( array(
66 'action' => 'query',
67 'titles' => 'Main Page',
68 'intoken' => 'edit|delete|protect|move|block|unblock',
69 'prop' => 'info' ) );
70 return $data;
75 class UserWrapper {
76 public $userName, $password, $user;
78 public function __construct( $userName, $password, $group = '' ) {
79 $this->userName = $userName;
80 $this->password = $password;
82 $this->user = User::newFromName( $this->userName );
83 if ( !$this->user->getID() ) {
84 $this->user = User::createNew( $this->userName, array(
85 "email" => "test@example.com",
86 "real_name" => "Test User" ) );
88 $this->user->setPassword( $this->password );
90 if ( $group !== '' ) {
91 $this->user->addGroup( $group );
93 $this->user->saveSettings();