Fiuxp issues from r74213 CR
[lhc/web/wiklou.git] / maintenance / tests / phpunit / includes / api / ApiSetup.php
1 <?php
2
3 abstract class ApiTestSetup extends PHPUnit_Framework_TestCase {
4 protected static $user;
5 protected static $sysopUser;
6 protected static $apiUrl;
7
8 function setUp() {
9 global $wgServer, $wgContLang, $wgAuth, $wgMemc, $wgRequest;
10
11 self::$apiUrl = $wgServer . wfScript( 'api' );
12
13 $wgMemc = new FakeMemCachedClient;
14 $wgContLang = Language::factory( 'en' );
15 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
16 $wgRequest = new FauxRequest( array() );
17 self::setupUser();
18 }
19
20 protected function doApiRequest( $params, $data = null ) {
21 $_SESSION = isset( $data[2] ) ? $data[2] : array();
22
23 $req = new FauxRequest( $params, true, $_SESSION );
24 $module = new ApiMain( $req, true );
25 $module->execute();
26
27 $data[0] = $module->getResultData();
28 $data[1] = $req;
29 $data[2] = $_SESSION;
30
31 return $data;
32 }
33
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' );
38 }
39
40 $GLOBALS['wgUser'] = self::$user->user;
41 }
42
43 function tearDown() {
44 global $wgMemc;
45 $wgMemc = null;
46 }
47 }
48
49 class UserWrapper {
50 public $userName, $password, $user;
51
52 public function __construct( $userName, $password, $group = '' ) {
53 $this->userName = $userName;
54 $this->password = $password;
55
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" ) );
61 }
62 $this->user->setPassword( $this->password );
63
64 if ( $group !== '' ) {
65 $this->user->addGroup( $group );
66 }
67 $this->user->saveSettings();
68 }
69 }