Merge "Selenium: replace UserLoginPage with BlankPage where possible"
[lhc/web/wiklou.git] / tests / phpunit / includes / api / ApiEditPageTest.php
index aeb829d..5e5fea3 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+use MediaWiki\Block\DatabaseBlock;
+
 /**
  * Tests for MediaWiki api.php?action=edit.
  *
@@ -37,6 +39,7 @@ class ApiEditPageTest extends ApiTestCase {
                        $this->tablesUsed,
                        [ 'change_tag', 'change_tag_def', 'logging' ]
                );
+               $this->resetServices();
        }
 
        public function testEdit() {
@@ -408,10 +411,10 @@ class ApiEditPageTest extends ApiTestCase {
                $count++;
 
                /*
-               * T43990: if the target page has a newer revision than the redirect, then editing the
-               * redirect while specifying 'redirect' and *not* specifying 'basetimestamp' erroneously
-               * caused an edit conflict to be detected.
-               */
+                * T43990: if the target page has a newer revision than the redirect, then editing the
+                * redirect while specifying 'redirect' and *not* specifying 'basetimestamp' erroneously
+                * caused an edit conflict to be detected.
+                */
 
                // assume NS_HELP defaults to wikitext
                $name = "Help:ApiEditPageTest_testEditConflict_redirect_T43990_$count";
@@ -1365,69 +1368,21 @@ class ApiEditPageTest extends ApiTestCase {
                ChangeTags::defineTag( 'custom tag' );
                $this->setMwGlobals( 'wgRevokePermissions',
                        [ 'user' => [ 'applychangetags' => true ] ] );
-               try {
-                       $this->doApiRequestWithToken( [
-                               'action' => 'edit',
-                               'title' => $name,
-                               'text' => 'Some text',
-                               'tags' => 'custom tag',
-                       ] );
-               } finally {
-                       $this->assertFalse( Title::newFromText( $name )->exists() );
-               }
-       }
-
-       public function testEditAbortedByHook() {
-               $name = 'Help:' . ucfirst( __FUNCTION__ );
-
-               $this->setExpectedException( ApiUsageException::class,
-                       'The modification you tried to make was aborted by an extension.' );
-
-               $this->hideDeprecated( 'APIEditBeforeSave hook (used in ' .
-                       'hook-APIEditBeforeSave-closure)' );
-
-               $this->setTemporaryHook( 'APIEditBeforeSave',
-                       function () {
-                               return false;
-                       }
-               );
+               // Supply services with updated globals
+               $this->resetServices();
 
                try {
                        $this->doApiRequestWithToken( [
                                'action' => 'edit',
                                'title' => $name,
                                'text' => 'Some text',
+                               'tags' => 'custom tag',
                        ] );
                } finally {
                        $this->assertFalse( Title::newFromText( $name )->exists() );
                }
        }
 
-       public function testEditAbortedByHookWithCustomOutput() {
-               $name = 'Help:' . ucfirst( __FUNCTION__ );
-
-               $this->hideDeprecated( 'APIEditBeforeSave hook (used in ' .
-                       'hook-APIEditBeforeSave-closure)' );
-
-               $this->setTemporaryHook( 'APIEditBeforeSave',
-                       function ( $unused1, $unused2, &$r ) {
-                               $r['msg'] = 'Some message';
-                               return false;
-                       } );
-
-               $result = $this->doApiRequestWithToken( [
-                       'action' => 'edit',
-                       'title' => $name,
-                       'text' => 'Some text',
-               ] );
-               Wikimedia\restoreWarnings();
-
-               $this->assertSame( [ 'msg' => 'Some message', 'result' => 'Failure' ],
-                       $result[0]['edit'] );
-
-               $this->assertFalse( Title::newFromText( $name )->exists() );
-       }
-
        public function testEditAbortedByEditPageHookWithResult() {
                $name = 'Help:' . ucfirst( __FUNCTION__ );
 
@@ -1474,9 +1429,9 @@ class ApiEditPageTest extends ApiTestCase {
        public function testEditWhileBlocked() {
                $name = 'Help:' . ucfirst( __FUNCTION__ );
 
-               $this->assertNull( Block::newFromTarget( '127.0.0.1' ), 'Sanity check' );
+               $this->assertNull( DatabaseBlock::newFromTarget( '127.0.0.1' ), 'Sanity check' );
 
-               $block = new Block( [
+               $block = new DatabaseBlock( [
                        'address' => self::$users['sysop']->getUser()->getName(),
                        'by' => self::$users['sysop']->getUser()->getId(),
                        'reason' => 'Capriciousness',
@@ -1495,7 +1450,7 @@ class ApiEditPageTest extends ApiTestCase {
                        $this->fail( 'Expected exception not thrown' );
                } catch ( ApiUsageException $ex ) {
                        $this->assertSame( 'You have been blocked from editing.', $ex->getMessage() );
-                       $this->assertNotNull( Block::newFromTarget( '127.0.0.1' ), 'Autoblock spread' );
+                       $this->assertNotNull( DatabaseBlock::newFromTarget( '127.0.0.1' ), 'Autoblock spread' );
                } finally {
                        $block->delete();
                        self::$users['sysop']->getUser()->clearInstanceCache();
@@ -1543,6 +1498,8 @@ class ApiEditPageTest extends ApiTestCase {
 
                $this->setMwGlobals( 'wgRevokePermissions',
                        [ 'user' => [ 'upload' => true ] ] );
+               // Supply services with updated globals
+               $this->resetServices();
 
                $this->doApiRequestWithToken( [
                        'action' => 'edit',
@@ -1558,6 +1515,8 @@ class ApiEditPageTest extends ApiTestCase {
                        'The content you supplied exceeds the article size limit of 1 kilobyte.' );
 
                $this->setMwGlobals( 'wgMaxArticleSize', 1 );
+               // Supply services with updated globals
+               $this->resetServices();
 
                $text = str_repeat( '!', 1025 );
 
@@ -1575,6 +1534,8 @@ class ApiEditPageTest extends ApiTestCase {
                        'The action you have requested is limited to users in the group: ' );
 
                $this->setMwGlobals( 'wgRevokePermissions', [ '*' => [ 'edit' => true ] ] );
+               // Supply services with updated globals
+               $this->resetServices();
 
                $this->doApiRequestWithToken( [
                        'action' => 'edit',
@@ -1591,6 +1552,8 @@ class ApiEditPageTest extends ApiTestCase {
 
                $this->setMwGlobals( 'wgRevokePermissions',
                        [ 'user' => [ 'editcontentmodel' => true ] ] );
+               // Supply services with updated globals
+               $this->resetServices();
 
                $this->doApiRequestWithToken( [
                        'action' => 'edit',