Merge "(Bug 44192) Do not attempt to send a real e-mail in ApiAccountCreationTest"
[lhc/web/wiklou.git] / tests / phpunit / includes / api / ApiTestCase.php
index fcd581a..552fbfb 100644 (file)
@@ -1,4 +1,4 @@
-<?php 
+<?php
 
 abstract class ApiTestCase extends MediaWikiLangTestCase {
        protected static $apiUrl;
@@ -9,14 +9,10 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
        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
 
@@ -35,10 +31,28 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
                        )
                );
 
-               $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 );
        }
 
        /**
@@ -102,6 +116,8 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
         * @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;
@@ -129,12 +145,15 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
 
                $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;
        }
@@ -161,7 +180,9 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
 }
 
 class UserWrapper {
-       public $userName, $password, $user;
+       public $userName;
+       public $password;
+       public $user;
 
        public function __construct( $userName, $password, $group = '' ) {
                $this->userName = $userName;
@@ -183,10 +204,11 @@ class UserWrapper {
 }
 
 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(