+ $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() );