X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FEditPageTest.php;h=1f9465dee3dfc78fe463386a6c27adf608b4db5b;hp=f5fef61a0cb9edff9518d9488c5aa35491410474;hb=9e8439e79d67788916d488f645108f79016d9aca;hpb=aaa1d460ccfb2a914b9b48e9542d342d4b3af552 diff --git a/tests/phpunit/includes/EditPageTest.php b/tests/phpunit/includes/EditPageTest.php index f5fef61a0c..1f9465dee3 100644 --- a/tests/phpunit/includes/EditPageTest.php +++ b/tests/phpunit/includes/EditPageTest.php @@ -351,7 +351,7 @@ class EditPageTest extends MediaWikiLangTestCase { wfGetDB( DB_MASTER )->commit( __METHOD__ ); - $this->assertEquals( 0, DeferredUpdates::pendingUpdatesCount(), 'No deferred updates' ); + $this->assertSame( 0, DeferredUpdates::pendingUpdatesCount(), 'No deferred updates' ); if ( $expectedCode != EditPage::AS_BLANK_ARTICLE ) { $latest = $page->getLatest(); @@ -693,14 +693,6 @@ hello * @covers EditPage */ public function testCheckDirectEditingDisallowed_forNonTextContent() { - $title = Title::newFromText( 'Dummy:NonTextPageForEditPage' ); - $page = WikiPage::factory( $title ); - - $article = new Article( $title ); - $article->getContext()->setTitle( $title ); - $ep = new EditPage( $article ); - $ep->setContextTitle( $title ); - $user = $GLOBALS['wgUser']; $edit = [ @@ -711,15 +703,79 @@ hello 'wpUnicodeCheck' => EditPage::UNICODE_CHECK, ]; - $req = new FauxRequest( $edit, true ); - $ep->importFormData( $req ); - $this->setExpectedException( MWException::class, 'This content model is not supported: testing' ); - $ep->internalAttemptSave( $result, false ); + $this->doEditDummyNonTextPage( $edit ); + } + + /** @covers EditPage */ + public function testShouldPreventChangingContentModelWhenUserCannotChangeModelForTitle() { + $this->setTemporaryHook( 'getUserPermissionsErrors', + function ( Title $page, $user, $action, &$result ) { + if ( $action === 'editcontentmodel' && + $page->getContentModel() === CONTENT_MODEL_WIKITEXT ) { + $result = false; + + return false; + } + } ); + + $user = $GLOBALS['wgUser']; + + $status = $this->doEditDummyNonTextPage( [ + 'wpTextbox1' => 'some text', + 'wpEditToken' => $user->getEditToken(), + 'wpEdittime' => '', + 'wpStarttime' => wfTimestampNow(), + 'wpUnicodeCheck' => EditPage::UNICODE_CHECK, + 'model' => CONTENT_MODEL_WIKITEXT, + 'format' => CONTENT_FORMAT_WIKITEXT, + ] ); + + $this->assertFalse( $status->isOK() ); + $this->assertEquals( EditPage::AS_NO_CHANGE_CONTENT_MODEL, $status->getValue() ); } + /** @covers EditPage */ + public function testShouldPreventChangingContentModelWhenUserCannotEditTargetTitle() { + $this->setTemporaryHook( 'getUserPermissionsErrors', + function ( Title $page, $user, $action, &$result ) { + if ( $action === 'edit' && $page->getContentModel() === CONTENT_MODEL_WIKITEXT ) { + $result = false; + return false; + } + } ); + + $user = $GLOBALS['wgUser']; + + $status = $this->doEditDummyNonTextPage( [ + 'wpTextbox1' => 'some text', + 'wpEditToken' => $user->getEditToken(), + 'wpEdittime' => '', + 'wpStarttime' => wfTimestampNow(), + 'wpUnicodeCheck' => EditPage::UNICODE_CHECK, + 'model' => CONTENT_MODEL_WIKITEXT, + 'format' => CONTENT_FORMAT_WIKITEXT, + ] ); + + $this->assertFalse( $status->isOK() ); + $this->assertEquals( EditPage::AS_NO_CHANGE_CONTENT_MODEL, $status->getValue() ); + } + + private function doEditDummyNonTextPage( array $edit ): Status { + $title = Title::newFromText( 'Dummy:NonTextPageForEditPage' ); + + $article = new Article( $title ); + $article->getContext()->setTitle( $title ); + $ep = new EditPage( $article ); + $ep->setContextTitle( $title ); + + $req = new FauxRequest( $edit, true ); + $ep->importFormData( $req ); + + return $ep->internalAttemptSave( $result, false ); + } }