X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FEditPageTest.php;h=1f9465dee3dfc78fe463386a6c27adf608b4db5b;hb=9c7f6734c397a954b8eaa5ec73876f2b4bf92afb;hp=55d8fbb444bea193cf5c5ae07e97cb424f5f790c;hpb=329a72120e5f450e44b9a2c0c6dadaad1de9d43c;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/EditPageTest.php b/tests/phpunit/includes/EditPageTest.php index 55d8fbb444..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(); @@ -368,6 +368,9 @@ class EditPageTest extends MediaWikiLangTestCase { } } + /** + * @covers EditPage + */ public function testUpdatePage() { $checkIds = []; @@ -414,6 +417,9 @@ class EditPageTest extends MediaWikiLangTestCase { $this->assertGreaterThan( $checkIds[0], $checkIds[1], "Second event rev ID is higher" ); } + /** + * @covers EditPage + */ public function testUpdatePageTrx() { $text = "one"; $edit = [ @@ -684,16 +690,9 @@ hello /** * @depends testAutoMerge + * @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 = [ @@ -704,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 ); + } }