diff options
author | jenkins-bot <jenkins-bot@gerrit.wikimedia.org> | 2019-05-22 11:18:36 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@wikimedia.org> | 2019-05-22 11:18:36 +0000 |
commit | 77863a92cd14eb3485945977d8587f2e758d6ae7 (patch) | |
tree | 70f9d7480853360d1257d2e557aa91c6e143b219 /tests | |
parent | 7c821908c4f2b69bfd913037ea9e49756624dc73 (diff) | |
parent | b537e44c4ea80c06e969f94a77377ea7e3626084 (diff) | |
download | mediawikicore-77863a92cd14eb3485945977d8587f2e758d6ae7.tar.gz mediawikicore-77863a92cd14eb3485945977d8587f2e758d6ae7.zip |
Merge "EditPage: Migrate Title::userCan() calls to PermissionManager"
Diffstat (limited to 'tests')
-rw-r--r-- | tests/phpunit/includes/EditPageTest.php | 80 |
1 files changed, 68 insertions, 12 deletions
diff --git a/tests/phpunit/includes/EditPageTest.php b/tests/phpunit/includes/EditPageTest.php index f5fef61a0cb9..d2540f6f4d0c 100644 --- a/tests/phpunit/includes/EditPageTest.php +++ b/tests/phpunit/includes/EditPageTest.php @@ -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 ); + } } |