3 abstract class ApiTestSetup
extends PHPUnit_Framework_TestCase
{
4 protected static $user;
5 protected static $sysopUser;
6 protected static $apiUrl;
9 global $wgServer, $wgContLang, $wgAuth, $wgMemc, $wgRequest;
11 self
::$apiUrl = $wgServer . wfScript( 'api' );
13 $wgMemc = new FakeMemCachedClient
;
14 $wgContLang = Language
::factory( 'en' );
15 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
16 $wgRequest = new FauxRequest( array() );
20 protected function doApiRequest( $params, $data = null ) {
21 $_SESSION = isset( $data[2] ) ?
$data[2] : array();
23 $req = new FauxRequest( $params, true, $_SESSION );
24 $module = new ApiMain( $req, true );
27 $data[0] = $module->getResultData();
34 static function setupUser() {
35 if ( self
::$user == null || self
::$sysopUser == null ) {
36 self
::$user = new UserWrapper( 'User for MediaWiki automated tests', User
::randomPassword() );
37 self
::$sysopUser = new UserWrapper( 'Sysop for MediaWiki automated tests', User
::randomPassword(), 'sysop' );
40 $GLOBALS['wgUser'] = self
::$sysopUser->user
;
45 public $userName, $password, $user;
47 public function __construct( $userName, $password, $group = '' ) {
48 $this->userName
= $userName;
49 $this->password
= $password;
51 $this->user
= User
::newFromName( $this->userName
);
52 if ( !$this->user
->getID() ) {
53 $this->user
= User
::createNew( $this->userName
, array(
54 "email" => "test@example.com",
55 "real_name" => "Test User" ) );
57 $this->user
->setPassword( $this->password
);
59 if ( $group !== '' ) {
60 $this->user
->addGroup( $group );
62 $this->user
->saveSettings();