Move utility methods from ApiTestCase to MediaWikiTestCase
[lhc/web/wiklou.git] / tests / phpunit / includes / api / ApiTestCase.php
index 6506ea4..0fce35a 100644 (file)
@@ -41,43 +41,6 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
                parent::tearDown();
        }
 
-       /**
-        * Edits or creates a page/revision
-        * @param string $pageName Page title
-        * @param string $text Content of the page
-        * @param string $summary Optional summary string for the revision
-        * @param int $defaultNs Optional namespace id
-        * @return array 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 );
-       }
-
-       /**
-        * Revision-deletes a revision.
-        *
-        * @param Revision|int $rev Revision to delete
-        * @param array $value Keys are Revision::DELETED_* flags.  Values are 1 to set the bit, 0 to
-        *   clear, -1 to leave alone.  (All other values also clear the bit.)
-        * @param string $comment Deletion comment
-        */
-       protected function revisionDelete(
-               $rev, array $value = [ Revision::DELETED_TEXT => 1 ], $comment = ''
-       ) {
-               if ( is_int( $rev ) ) {
-                       $rev = Revision::newFromId( $rev );
-               }
-               RevisionDeleter::createList(
-                       'revision', RequestContext::getMain(), $rev->getTitle(), [ $rev->getId() ]
-               )->setVisibility( [
-                       'value' => $value,
-                       'comment' => $comment,
-               ] );
-       }
-
        /**
         * Does the API request and returns the result.
         *
@@ -121,6 +84,10 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
                }
 
                if ( $tokenType !== null ) {
+                       if ( $tokenType === 'auto' ) {
+                               $tokenType = ( new ApiMain() )->getModuleManager()
+                                       ->getModule( $params['action'], 'action' )->needsToken();
+                       }
                        $params['token'] = ApiQueryTokens::getToken(
                                $wgUser, $sessionObj, ApiQueryTokens::getTokenTypeSalts()[$tokenType]
                        )->toString();
@@ -164,7 +131,7 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
         * @return array Result of the API call
         */
        protected function doApiRequestWithToken( array $params, array $session = null,
-               User $user = null, $tokenType = 'csrf'
+               User $user = null, $tokenType = 'auto'
        ) {
                return $this->doApiRequest( $params, $session, false, $user, $tokenType );
        }