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( 'Useruser', 'Passpass' );
37 self
::$sysopUser = new UserWrapper( 'Useruser1', 'Passpass1', 'sysop' );
40 $GLOBALS['wgUser'] = self
::$user->user
;
50 public $userName, $password, $user;
52 public function __construct( $userName, $password, $group = '' ) {
53 $this->userName
= $userName;
54 $this->password
= $password;
56 $this->user
= User
::newFromName( $this->userName
);
57 if ( !$this->user
->getID() ) {
58 $this->user
= User
::createNew( $this->userName
, array(
59 "email" => "test@example.com",
60 "real_name" => "Test User" ) );
62 $this->user
->setPassword( $this->password
);
64 if ( $group !== '' ) {
65 $this->user
->addGroup( $group );
67 $this->user
->saveSettings();