test: basic test for ApiStashEdit
[lhc/web/wiklou.git] / tests / phpunit / includes / api / ApiTestCase.php
index ff5640a..e90b46f 100644 (file)
@@ -8,11 +8,6 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
         */
        protected $apiContext;
 
-       /**
-        * @var array
-        */
-       protected $tablesUsed = [ 'user', 'user_groups', 'user_properties' ];
-
        protected function setUp() {
                global $wgServer, $wgDisableAuthManager;
 
@@ -22,18 +17,8 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
                ApiQueryInfo::resetTokenCache(); // tokens are invalid because we cleared the session
 
                self::$users = [
-                       'sysop' => new TestUser(
-                               'Apitestsysop',
-                               'Api Test Sysop',
-                               'api_test_sysop@example.com',
-                               [ 'sysop' ]
-                       ),
-                       'uploader' => new TestUser(
-                               'Apitestuser',
-                               'Api Test User',
-                               'api_test_user@example.com',
-                               []
-                       )
+                       'sysop' => static::getTestSysop(),
+                       'uploader' => static::getTestUser(),
                ];
 
                $this->setMwGlobals( [
@@ -162,15 +147,19 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
                }
        }
 
-       protected function doLogin( $user = 'sysop' ) {
-               if ( !array_key_exists( $user, self::$users ) ) {
-                       throw new MWException( "Can not log in to undefined user $user" );
+       protected function doLogin( $testUser = 'sysop' ) {
+               if ( $testUser === null ) {
+                       $testUser = static::getTestSysop();
+               } elseif ( is_string( $testUser ) && array_key_exists( $testUser, self::$users ) ) {
+                       $testUser = self::$users[ $testUser ];
+               } elseif ( !$testUser instanceof TestUser ) {
+                       throw new MWException( "Can not log in to undefined user $testUser" );
                }
 
                $data = $this->doApiRequest( [
                        'action' => 'login',
-                       'lgname' => self::$users[$user]->username,
-                       'lgpassword' => self::$users[$user]->password ] );
+                       'lgname' => $testUser->username,
+                       'lgpassword' => $testUser->password ] );
 
                $token = $data[0]['login']['token'];
 
@@ -178,8 +167,8 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
                        [
                                'action' => 'login',
                                'lgtoken' => $token,
-                               'lgname' => self::$users[$user]->username,
-                               'lgpassword' => self::$users[$user]->password,
+                               'lgname' => $testUser->username,
+                               'lgpassword' => $testUser->password,
                        ],
                        $data[2]
                );
@@ -187,7 +176,7 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
                if ( $data[0]['login']['result'] === 'Success' ) {
                        // DWIM
                        global $wgUser;
-                       $wgUser = self::$users[$user]->getUser();
+                       $wgUser = $testUser->getUser();
                        RequestContext::getMain()->setUser( $wgUser );
                }