summaryrefslogtreecommitdiff
path: root/maintenance/tests/ApiSetup.php
blob: 549d8aefb7b90f3a651d1d2c4d177eb9dc5a79b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php

abstract class ApiSetup extends PHPUnit_Framework_TestCase {
	protected static $userName;
	protected static $passWord;
	protected static $user;
	protected static $apiUrl;

	function setup() {
		global $wgServerName, $wgServer, $wgContLang, $wgAuth, $wgScriptPath,
			$wgScriptExtension, $wgMemc, $wgRequest;

		self::$apiUrl = $wgServer.$wgScriptPath."/api".$wgScriptExtension;

		$wgMemc = new FakeMemCachedClient;
		$wgContLang = Language::factory( 'en' );
		$wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
		$wgRequest = new FauxRequest(array());
		self::setupUser();
	}

	static function setupUser() {
		if ( self::$user == NULL ) {
			self::$userName = "Useruser";
			self::$passWord = User::randomPassword();

			self::$user = User::newFromName(self::$userName);
			if ( !self::$user->getID() ) {
				self::$user = User::createNew(self::$userName, array(
					"password" => self::$passWord,
					"email" => "test@example.com",
					"real_name" => "Test User"));
			} else {
				self::$user->setPassword(self::$passWord);
			}
			self::$user->saveSettings();
		}
	}
}