-<?php
+<?php
abstract class ApiTestCase extends MediaWikiLangTestCase {
protected static $apiUrl;
protected $apiContext;
protected function setUp() {
- global $wgContLang, $wgAuth, $wgMemc, $wgRequest, $wgUser, $wgServer;
+ global $wgServer;
parent::setUp();
self::$apiUrl = $wgServer . wfScript( 'api' );
- $wgMemc = new EmptyBagOStuff();
- $wgContLang = Language::factory( 'en' );
- $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
- $wgRequest = new FauxRequest( array() );
ApiQueryInfo::resetTokenCache(); // tokens are invalid because we cleared the session
)
);
- $wgUser = self::$users['sysop']->user;
+ $this->setMwGlobals( array(
+ 'wgMemc' => new EmptyBagOStuff(),
+ 'wgAuth' => new StubObject( 'wgAuth', 'AuthPlugin' ),
+ 'wgRequest' => new FauxRequest( array() ),
+ 'wgUser' => self::$users['sysop']->user,
+ ) );
$this->apiContext = new ApiTestContext();
+ }
+ /**
+ * Edits or creates a page/revision
+ * @param $pageName string page title
+ * @param $text string content of the page
+ * @param $summary string optional summary string for the revision
+ * @param $defaultNs int optional namespace id
+ * @return array as returned by WikiPage::doEditContent()
+ */
+ protected function editPage( $pageName, $text, $summary = '', $defaultNs = NS_MAIN ) {
+ $title = Title::newFromText( $pageName, $defaultNs );
+ $page = WikiPage::factory( $title );
+ return $page->doEditContent( ContentHandler::makeContent( $text, $title ), $summary );
}
/**
* @param $params Array: key-value API params
* @param $session Array|null: session array
* @param $user User|null A User object for the context
+ * @return result of the API call
+ * @throws Exception in case wsToken is not set in the session
*/
protected function doApiRequestWithToken( array $params, array $session = null, User $user = null ) {
global $wgRequest;
$token = $data[0]['login']['token'];
- $data = $this->doApiRequest( array(
- 'action' => 'login',
- 'lgtoken' => $token,
- 'lgname' => self::$users['sysop']->username,
- 'lgpassword' => self::$users['sysop']->password
- ), $data[2] );
+ $data = $this->doApiRequest(
+ array(
+ 'action' => 'login',
+ 'lgtoken' => $token,
+ 'lgname' => self::$users['sysop']->username,
+ 'lgpassword' => self::$users['sysop']->password,
+ ),
+ $data[2]
+ );
return $data;
}
}
class UserWrapper {
- public $userName, $password, $user;
+ public $userName;
+ public $password;
+ public $user;
public function __construct( $userName, $password, $group = '' ) {
$this->userName = $userName;
}
class MockApi extends ApiBase {
- public function execute() { }
- public function getVersion() { }
+ public function execute() {}
+
+ public function getVersion() {}
- public function __construct() { }
+ public function __construct() {}
public function getAllowedParams() {
return array(