3 abstract class ApiTestSetup
extends MediaWikiLangTestCase
{
6 protected static $apiUrl;
9 global $wgServer, $wgContLang, $wgAuth, $wgMemc, $wgRequest;
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() );
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 );
28 $data[0] = $module->getResultData();
32 if( $appendModule ) $data[3] = $module;
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
;
47 $data = $this->doApiRequest( array(
49 'lgname' => $this->sysopUser
->userName
,
50 'lgpassword' => $this->sysopUser
->password
) );
52 $token = $data[0]['login']['token'];
54 $data = $this->doApiRequest( array(
57 "lgname" => $this->sysopUser
->userName
,
58 "lgpassword" => $this->sysopUser
->password
), $data );
63 function getTokenList( $user ) {
64 $GLOBALS['wgUser'] = $user->user
;
65 $data = $this->doApiRequest( array(
67 'titles' => 'Main Page',
68 'intoken' => 'edit|delete|protect|move|block|unblock',
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();