2011-12-06 23:35:42 +00:00
|
|
|
<?php
|
|
|
|
|
|
2012-03-15 15:38:11 +00:00
|
|
|
/**
|
2012-11-10 16:24:48 +00:00
|
|
|
* @group Editing
|
|
|
|
|
*
|
|
|
|
|
* @group Database
|
|
|
|
|
* ^--- tell jenkins this test needs the database
|
|
|
|
|
*
|
|
|
|
|
* @group medium
|
|
|
|
|
* ^--- tell phpunit that these test cases may take longer than 2 seconds.
|
2012-03-15 15:38:11 +00:00
|
|
|
*/
|
2013-07-26 21:53:06 +00:00
|
|
|
class EditPageTest extends MediaWikiLangTestCase {
|
2011-12-06 23:35:42 +00:00
|
|
|
|
2015-04-15 08:26:22 +00:00
|
|
|
protected function setUp() {
|
|
|
|
|
global $wgExtraNamespaces, $wgNamespaceContentModels, $wgContentHandlers, $wgContLang;
|
|
|
|
|
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
$this->setMwGlobals( array(
|
|
|
|
|
'wgExtraNamespaces' => $wgExtraNamespaces,
|
|
|
|
|
'wgNamespaceContentModels' => $wgNamespaceContentModels,
|
|
|
|
|
'wgContentHandlers' => $wgContentHandlers,
|
|
|
|
|
'wgContLang' => $wgContLang,
|
|
|
|
|
) );
|
|
|
|
|
|
|
|
|
|
$wgExtraNamespaces[12312] = 'Dummy';
|
|
|
|
|
$wgExtraNamespaces[12313] = 'Dummy_talk';
|
|
|
|
|
|
|
|
|
|
$wgNamespaceContentModels[12312] = "testing";
|
|
|
|
|
$wgContentHandlers["testing"] = 'DummyContentHandlerForTesting';
|
|
|
|
|
|
|
|
|
|
MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache
|
|
|
|
|
$wgContLang->resetNamespaces(); # reset namespace cache
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-06 23:35:42 +00:00
|
|
|
/**
|
2012-10-08 10:56:20 +00:00
|
|
|
* @dataProvider provideExtractSectionTitle
|
2013-10-24 10:54:02 +00:00
|
|
|
* @covers EditPage::extractSectionTitle
|
2011-12-06 23:35:42 +00:00
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testExtractSectionTitle( $section, $title ) {
|
2011-12-06 23:35:42 +00:00
|
|
|
$extracted = EditPage::extractSectionTitle( $section );
|
|
|
|
|
$this->assertEquals( $title, $extracted );
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
public static function provideExtractSectionTitle() {
|
2011-12-06 23:35:42 +00:00
|
|
|
return array(
|
|
|
|
|
array(
|
|
|
|
|
"== Test ==\n\nJust a test section.",
|
|
|
|
|
"Test"
|
|
|
|
|
),
|
|
|
|
|
array(
|
|
|
|
|
"An initial section, no header.",
|
|
|
|
|
false
|
|
|
|
|
),
|
|
|
|
|
array(
|
|
|
|
|
"An initial section with a fake heder (bug 32617)\n\n== Test == ??\nwtf",
|
|
|
|
|
false
|
|
|
|
|
),
|
|
|
|
|
array(
|
|
|
|
|
"== Section ==\nfollowed by a fake == Non-section == ??\nnoooo",
|
|
|
|
|
"Section"
|
2012-03-15 15:38:11 +00:00
|
|
|
),
|
|
|
|
|
array(
|
|
|
|
|
"== Section== \t\r\n followed by whitespace (bug 35051)",
|
|
|
|
|
'Section',
|
|
|
|
|
),
|
2011-12-06 23:35:42 +00:00
|
|
|
);
|
|
|
|
|
}
|
2012-11-10 16:24:48 +00:00
|
|
|
|
|
|
|
|
protected function forceRevisionDate( WikiPage $page, $timestamp ) {
|
|
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
|
|
|
|
|
|
|
|
|
$dbw->update( 'revision',
|
2013-01-21 23:01:05 +00:00
|
|
|
array( 'rev_timestamp' => $dbw->timestamp( $timestamp ) ),
|
2012-11-10 16:24:48 +00:00
|
|
|
array( 'rev_id' => $page->getLatest() ) );
|
|
|
|
|
|
|
|
|
|
$page->clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* User input text is passed to rtrim() by edit page. This is a simple
|
|
|
|
|
* wrapper around assertEquals() which calls rrtrim() to normalize the
|
|
|
|
|
* expected and actual texts.
|
2014-08-25 16:50:35 +00:00
|
|
|
* @param string $expected
|
|
|
|
|
* @param string $actual
|
|
|
|
|
* @param string $msg
|
2012-11-10 16:24:48 +00:00
|
|
|
*/
|
2013-10-24 10:54:02 +00:00
|
|
|
protected function assertEditedTextEquals( $expected, $actual, $msg = '' ) {
|
2013-02-14 11:22:13 +00:00
|
|
|
return $this->assertEquals( rtrim( $expected ), rtrim( $actual ), $msg );
|
2012-11-10 16:24:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Performs an edit and checks the result.
|
|
|
|
|
*
|
2014-04-17 18:43:42 +00:00
|
|
|
* @param string|Title $title The title of the page to edit
|
|
|
|
|
* @param string|null $baseText Some text to create the page with before attempting the edit.
|
|
|
|
|
* @param User|string|null $user The user to perform the edit as.
|
2012-11-10 16:24:48 +00:00
|
|
|
* @param array $edit An array of request parameters used to define the edit to perform.
|
|
|
|
|
* Some well known fields are:
|
|
|
|
|
* * wpTextbox1: the text to submit
|
|
|
|
|
* * wpSummary: the edit summary
|
|
|
|
|
* * wpEditToken: the edit token (will be inserted if not provided)
|
2014-04-24 09:57:41 +00:00
|
|
|
* * wpEdittime: timestamp of the edit's base revision (will be inserted
|
|
|
|
|
* if not provided)
|
2012-11-10 16:24:48 +00:00
|
|
|
* * wpStarttime: timestamp when the edit started (will be inserted if not provided)
|
|
|
|
|
* * wpSectionTitle: the section to edit
|
|
|
|
|
* * wpMinorEdit: mark as minor edit
|
|
|
|
|
* * wpWatchthis: whether to watch the page
|
|
|
|
|
* @param int|null $expectedCode The expected result code (EditPage::AS_XXX constants).
|
2014-07-22 00:50:47 +00:00
|
|
|
* Set to null to skip the check.
|
2014-04-17 18:43:42 +00:00
|
|
|
* @param string|null $expectedText The text expected to be on the page after the edit.
|
2012-11-10 16:24:48 +00:00
|
|
|
* Set to null to skip the check.
|
2014-04-17 18:43:42 +00:00
|
|
|
* @param string|null $message An optional message to show along with any error message.
|
2012-11-10 16:24:48 +00:00
|
|
|
*
|
|
|
|
|
* @return WikiPage The page that was just edited, useful for getting the edit's rev_id, etc.
|
|
|
|
|
*/
|
|
|
|
|
protected function assertEdit( $title, $baseText, $user = null, array $edit,
|
2014-07-22 00:50:47 +00:00
|
|
|
$expectedCode = null, $expectedText = null, $message = null
|
2012-11-10 16:24:48 +00:00
|
|
|
) {
|
|
|
|
|
if ( is_string( $title ) ) {
|
|
|
|
|
$ns = $this->getDefaultWikitextNS();
|
|
|
|
|
$title = Title::newFromText( $title, $ns );
|
|
|
|
|
}
|
2014-07-17 22:28:46 +00:00
|
|
|
$this->assertNotNull( $title );
|
2012-11-10 16:24:48 +00:00
|
|
|
|
|
|
|
|
if ( is_string( $user ) ) {
|
|
|
|
|
$user = User::newFromName( $user );
|
|
|
|
|
|
|
|
|
|
if ( $user->getId() === 0 ) {
|
|
|
|
|
$user->addToDatabase();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$page = WikiPage::factory( $title );
|
|
|
|
|
|
|
|
|
|
if ( $baseText !== null ) {
|
|
|
|
|
$content = ContentHandler::makeContent( $baseText, $title );
|
|
|
|
|
$page->doEditContent( $content, "base text for test" );
|
|
|
|
|
$this->forceRevisionDate( $page, '20120101000000' );
|
|
|
|
|
|
2015-09-11 13:44:59 +00:00
|
|
|
// sanity check
|
2012-11-10 16:24:48 +00:00
|
|
|
$page->clear();
|
|
|
|
|
$currentText = ContentHandler::getContentText( $page->getContent() );
|
|
|
|
|
|
|
|
|
|
# EditPage rtrim() the user input, so we alter our expected text
|
|
|
|
|
# to reflect that.
|
|
|
|
|
$this->assertEditedTextEquals( $baseText, $currentText );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $user == null ) {
|
|
|
|
|
$user = $GLOBALS['wgUser'];
|
|
|
|
|
} else {
|
|
|
|
|
$this->setMwGlobals( 'wgUser', $user );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !isset( $edit['wpEditToken'] ) ) {
|
|
|
|
|
$edit['wpEditToken'] = $user->getEditToken();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !isset( $edit['wpEdittime'] ) ) {
|
|
|
|
|
$edit['wpEdittime'] = $page->exists() ? $page->getTimestamp() : '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !isset( $edit['wpStarttime'] ) ) {
|
|
|
|
|
$edit['wpStarttime'] = wfTimestampNow();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$req = new FauxRequest( $edit, true ); // session ??
|
|
|
|
|
|
2014-07-17 22:28:46 +00:00
|
|
|
$article = new Article( $title );
|
|
|
|
|
$article->getContext()->setTitle( $title );
|
|
|
|
|
$ep = new EditPage( $article );
|
2012-11-10 16:24:48 +00:00
|
|
|
$ep->setContextTitle( $title );
|
|
|
|
|
$ep->importFormData( $req );
|
|
|
|
|
|
|
|
|
|
$bot = isset( $edit['bot'] ) ? (bool)$edit['bot'] : false;
|
|
|
|
|
|
|
|
|
|
// this is where the edit happens!
|
|
|
|
|
// Note: don't want to use EditPage::AttemptSave, because it messes with $wgOut
|
|
|
|
|
// and throws exceptions like PermissionsError
|
|
|
|
|
$status = $ep->internalAttemptSave( $result, $bot );
|
|
|
|
|
|
|
|
|
|
if ( $expectedCode !== null ) {
|
|
|
|
|
// check edit code
|
|
|
|
|
$this->assertEquals( $expectedCode, $status->value,
|
|
|
|
|
"Expected result code mismatch. $message" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$page = WikiPage::factory( $title );
|
|
|
|
|
|
|
|
|
|
if ( $expectedText !== null ) {
|
|
|
|
|
// check resulting page text
|
|
|
|
|
$content = $page->getContent();
|
|
|
|
|
$text = ContentHandler::getContentText( $content );
|
|
|
|
|
|
|
|
|
|
# EditPage rtrim() the user input, so we alter our expected text
|
|
|
|
|
# to reflect that.
|
|
|
|
|
$this->assertEditedTextEquals( $expectedText, $text,
|
|
|
|
|
"Expected article text mismatch. $message" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $page;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-18 01:28:26 +00:00
|
|
|
public static function provideCreatePages() {
|
2014-09-04 02:30:15 +00:00
|
|
|
return array(
|
|
|
|
|
array( 'expected article being created',
|
|
|
|
|
'EditPageTest_testCreatePage',
|
|
|
|
|
null,
|
|
|
|
|
'Hello World!',
|
|
|
|
|
EditPage::AS_SUCCESS_NEW_ARTICLE,
|
|
|
|
|
'Hello World!'
|
2013-07-01 11:25:41 +00:00
|
|
|
),
|
2014-09-04 02:30:15 +00:00
|
|
|
array( 'expected article not being created if empty',
|
|
|
|
|
'EditPageTest_testCreatePage',
|
|
|
|
|
null,
|
|
|
|
|
'',
|
|
|
|
|
EditPage::AS_BLANK_ARTICLE,
|
|
|
|
|
null
|
2013-07-01 11:25:41 +00:00
|
|
|
),
|
2014-09-04 02:30:15 +00:00
|
|
|
array( 'expected MediaWiki: page being created',
|
|
|
|
|
'MediaWiki:January',
|
|
|
|
|
'UTSysop',
|
|
|
|
|
'Not January',
|
|
|
|
|
EditPage::AS_SUCCESS_NEW_ARTICLE,
|
|
|
|
|
'Not January'
|
2013-07-01 11:25:41 +00:00
|
|
|
),
|
2014-09-04 02:30:15 +00:00
|
|
|
array( 'expected not-registered MediaWiki: page not being created if empty',
|
|
|
|
|
'MediaWiki:EditPageTest_testCreatePage',
|
|
|
|
|
'UTSysop',
|
|
|
|
|
'',
|
|
|
|
|
EditPage::AS_BLANK_ARTICLE,
|
|
|
|
|
null
|
2013-07-01 11:25:41 +00:00
|
|
|
),
|
2014-09-04 02:30:15 +00:00
|
|
|
array( 'expected registered MediaWiki: page being created even if empty',
|
|
|
|
|
'MediaWiki:January',
|
|
|
|
|
'UTSysop',
|
|
|
|
|
'',
|
|
|
|
|
EditPage::AS_SUCCESS_NEW_ARTICLE,
|
|
|
|
|
''
|
2013-07-01 11:25:41 +00:00
|
|
|
),
|
2015-03-14 08:35:54 +00:00
|
|
|
array( 'expected registered MediaWiki: page whose default content is empty'
|
|
|
|
|
. ' not being created if empty',
|
2014-09-04 02:30:15 +00:00
|
|
|
'MediaWiki:Ipb-default-expiry',
|
|
|
|
|
'UTSysop',
|
|
|
|
|
'',
|
|
|
|
|
EditPage::AS_BLANK_ARTICLE,
|
|
|
|
|
''
|
2013-07-01 11:25:41 +00:00
|
|
|
),
|
2014-09-04 02:30:15 +00:00
|
|
|
array( 'expected MediaWiki: page not being created if text equals default message',
|
|
|
|
|
'MediaWiki:January',
|
|
|
|
|
'UTSysop',
|
|
|
|
|
'January',
|
|
|
|
|
EditPage::AS_BLANK_ARTICLE,
|
|
|
|
|
null
|
|
|
|
|
),
|
|
|
|
|
array( 'expected empty article being created',
|
|
|
|
|
'EditPageTest_testCreatePage',
|
|
|
|
|
null,
|
|
|
|
|
'',
|
|
|
|
|
EditPage::AS_SUCCESS_NEW_ARTICLE,
|
|
|
|
|
'',
|
|
|
|
|
true
|
2013-07-01 11:25:41 +00:00
|
|
|
),
|
|
|
|
|
);
|
2014-09-04 02:30:15 +00:00
|
|
|
}
|
2014-07-13 01:36:37 +00:00
|
|
|
|
2014-09-04 02:30:15 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provideCreatePages
|
|
|
|
|
* @covers EditPage
|
|
|
|
|
*/
|
2015-03-14 08:35:54 +00:00
|
|
|
public function testCreatePage(
|
|
|
|
|
$desc, $pageTitle, $user, $editText, $expectedCode, $expectedText, $ignoreBlank = false
|
|
|
|
|
) {
|
2014-09-04 02:30:15 +00:00
|
|
|
$edit = array( 'wpTextbox1' => $editText );
|
|
|
|
|
if ( $ignoreBlank ) {
|
|
|
|
|
$edit['wpIgnoreBlankArticle'] = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$page = $this->assertEdit( $pageTitle, null, $user, $edit, $expectedCode, $expectedText, $desc );
|
|
|
|
|
|
|
|
|
|
if ( $expectedCode != EditPage::AS_BLANK_ARTICLE ) {
|
|
|
|
|
$page->doDeleteArticleReal( $pageTitle );
|
|
|
|
|
}
|
2012-11-10 16:24:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testUpdatePage() {
|
|
|
|
|
$text = "one";
|
|
|
|
|
$edit = array(
|
|
|
|
|
'wpTextbox1' => $text,
|
|
|
|
|
'wpSummary' => 'first update',
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$page = $this->assertEdit( 'EditPageTest_testUpdatePage', "zero", null, $edit,
|
|
|
|
|
EditPage::AS_SUCCESS_UPDATE, $text,
|
|
|
|
|
"expected successfull update with given text" );
|
|
|
|
|
|
|
|
|
|
$this->forceRevisionDate( $page, '20120101000000' );
|
|
|
|
|
|
|
|
|
|
$text = "two";
|
|
|
|
|
$edit = array(
|
|
|
|
|
'wpTextbox1' => $text,
|
|
|
|
|
'wpSummary' => 'second update',
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertEdit( 'EditPageTest_testUpdatePage', null, null, $edit,
|
|
|
|
|
EditPage::AS_SUCCESS_UPDATE, $text,
|
|
|
|
|
"expected successfull update with given text" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function provideSectionEdit() {
|
2013-02-14 11:22:13 +00:00
|
|
|
$text = 'Intro
|
2012-11-10 16:24:48 +00:00
|
|
|
|
|
|
|
|
== one ==
|
|
|
|
|
first section.
|
|
|
|
|
|
|
|
|
|
== two ==
|
|
|
|
|
second section.
|
|
|
|
|
';
|
|
|
|
|
|
2013-02-14 11:22:13 +00:00
|
|
|
$sectionOne = '== one ==
|
2012-11-10 16:24:48 +00:00
|
|
|
hello
|
|
|
|
|
';
|
|
|
|
|
|
2013-02-14 11:22:13 +00:00
|
|
|
$newSection = '== new section ==
|
2012-11-10 16:24:48 +00:00
|
|
|
|
|
|
|
|
hello
|
|
|
|
|
';
|
|
|
|
|
|
2013-02-14 11:22:13 +00:00
|
|
|
$textWithNewSectionOne = preg_replace(
|
|
|
|
|
'/== one ==.*== two ==/ms',
|
|
|
|
|
"$sectionOne\n== two ==", $text
|
|
|
|
|
);
|
2012-11-10 16:24:48 +00:00
|
|
|
|
|
|
|
|
$textWithNewSectionAdded = "$text\n$newSection";
|
|
|
|
|
|
|
|
|
|
return array(
|
2015-09-11 13:44:59 +00:00
|
|
|
array( # 0
|
2012-11-10 16:24:48 +00:00
|
|
|
$text,
|
|
|
|
|
'',
|
|
|
|
|
'hello',
|
|
|
|
|
'replace all',
|
|
|
|
|
'hello'
|
|
|
|
|
),
|
|
|
|
|
|
2015-09-11 13:44:59 +00:00
|
|
|
array( # 1
|
2012-11-10 16:24:48 +00:00
|
|
|
$text,
|
|
|
|
|
'1',
|
|
|
|
|
$sectionOne,
|
|
|
|
|
'replace first section',
|
|
|
|
|
$textWithNewSectionOne,
|
|
|
|
|
),
|
|
|
|
|
|
2015-09-11 13:44:59 +00:00
|
|
|
array( # 2
|
2012-11-10 16:24:48 +00:00
|
|
|
$text,
|
|
|
|
|
'new',
|
|
|
|
|
'hello',
|
|
|
|
|
'new section',
|
|
|
|
|
$textWithNewSectionAdded,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideSectionEdit
|
2013-10-24 10:54:02 +00:00
|
|
|
* @covers EditPage
|
2012-11-10 16:24:48 +00:00
|
|
|
*/
|
|
|
|
|
public function testSectionEdit( $base, $section, $text, $summary, $expected ) {
|
|
|
|
|
$edit = array(
|
|
|
|
|
'wpTextbox1' => $text,
|
|
|
|
|
'wpSummary' => $summary,
|
|
|
|
|
'wpSection' => $section,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertEdit( 'EditPageTest_testSectionEdit', $base, null, $edit,
|
|
|
|
|
EditPage::AS_SUCCESS_UPDATE, $expected,
|
|
|
|
|
"expected successfull update of section" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function provideAutoMerge() {
|
|
|
|
|
$tests = array();
|
|
|
|
|
|
2015-09-11 13:44:59 +00:00
|
|
|
$tests[] = array( # 0: plain conflict
|
2012-11-10 16:24:48 +00:00
|
|
|
"Elmo", # base edit user
|
|
|
|
|
"one\n\ntwo\n\nthree\n",
|
2015-09-11 13:44:59 +00:00
|
|
|
array( # adam's edit
|
2012-11-10 16:24:48 +00:00
|
|
|
'wpStarttime' => 1,
|
|
|
|
|
'wpTextbox1' => "ONE\n\ntwo\n\nthree\n",
|
|
|
|
|
),
|
2015-09-11 13:44:59 +00:00
|
|
|
array( # berta's edit
|
2012-11-10 16:24:48 +00:00
|
|
|
'wpStarttime' => 2,
|
|
|
|
|
'wpTextbox1' => "(one)\n\ntwo\n\nthree\n",
|
|
|
|
|
),
|
|
|
|
|
EditPage::AS_CONFLICT_DETECTED, # expected code
|
|
|
|
|
"ONE\n\ntwo\n\nthree\n", # expected text
|
|
|
|
|
'expected edit conflict', # message
|
|
|
|
|
);
|
|
|
|
|
|
2015-09-11 13:44:59 +00:00
|
|
|
$tests[] = array( # 1: successful merge
|
2012-11-10 16:24:48 +00:00
|
|
|
"Elmo", # base edit user
|
|
|
|
|
"one\n\ntwo\n\nthree\n",
|
2015-09-11 13:44:59 +00:00
|
|
|
array( # adam's edit
|
2012-11-10 16:24:48 +00:00
|
|
|
'wpStarttime' => 1,
|
|
|
|
|
'wpTextbox1' => "ONE\n\ntwo\n\nthree\n",
|
|
|
|
|
),
|
2015-09-11 13:44:59 +00:00
|
|
|
array( # berta's edit
|
2012-11-10 16:24:48 +00:00
|
|
|
'wpStarttime' => 2,
|
|
|
|
|
'wpTextbox1' => "one\n\ntwo\n\nTHREE\n",
|
|
|
|
|
),
|
|
|
|
|
EditPage::AS_SUCCESS_UPDATE, # expected code
|
|
|
|
|
"ONE\n\ntwo\n\nTHREE\n", # expected text
|
|
|
|
|
'expected automatic merge', # message
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$text = "Intro\n\n";
|
|
|
|
|
$text .= "== first section ==\n\n";
|
|
|
|
|
$text .= "one\n\ntwo\n\nthree\n\n";
|
|
|
|
|
$text .= "== second section ==\n\n";
|
|
|
|
|
$text .= "four\n\nfive\n\nsix\n\n";
|
|
|
|
|
|
|
|
|
|
// extract the first section.
|
|
|
|
|
$section = preg_replace( '/.*(== first section ==.*)== second section ==.*/sm', '$1', $text );
|
|
|
|
|
|
|
|
|
|
// generate expected text after merge
|
|
|
|
|
$expected = str_replace( 'one', 'ONE', str_replace( 'three', 'THREE', $text ) );
|
|
|
|
|
|
2015-09-11 13:44:59 +00:00
|
|
|
$tests[] = array( # 2: merge in section
|
2012-11-10 16:24:48 +00:00
|
|
|
"Elmo", # base edit user
|
|
|
|
|
$text,
|
2015-09-11 13:44:59 +00:00
|
|
|
array( # adam's edit
|
2012-11-10 16:24:48 +00:00
|
|
|
'wpStarttime' => 1,
|
|
|
|
|
'wpTextbox1' => str_replace( 'one', 'ONE', $section ),
|
|
|
|
|
'wpSection' => '1'
|
|
|
|
|
),
|
2015-09-11 13:44:59 +00:00
|
|
|
array( # berta's edit
|
2012-11-10 16:24:48 +00:00
|
|
|
'wpStarttime' => 2,
|
|
|
|
|
'wpTextbox1' => str_replace( 'three', 'THREE', $section ),
|
|
|
|
|
'wpSection' => '1'
|
|
|
|
|
),
|
|
|
|
|
EditPage::AS_SUCCESS_UPDATE, # expected code
|
|
|
|
|
$expected, # expected text
|
|
|
|
|
'expected automatic section merge', # message
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// see whether it makes a difference who did the base edit
|
2013-02-14 11:22:13 +00:00
|
|
|
$testsWithAdam = array_map( function ( $test ) {
|
2012-11-10 16:24:48 +00:00
|
|
|
$test[0] = 'Adam'; // change base edit user
|
|
|
|
|
return $test;
|
|
|
|
|
}, $tests );
|
|
|
|
|
|
2013-02-14 11:22:13 +00:00
|
|
|
$testsWithBerta = array_map( function ( $test ) {
|
2012-11-10 16:24:48 +00:00
|
|
|
$test[0] = 'Berta'; // change base edit user
|
|
|
|
|
return $test;
|
|
|
|
|
}, $tests );
|
|
|
|
|
|
|
|
|
|
return array_merge( $tests, $testsWithAdam, $testsWithBerta );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideAutoMerge
|
2013-10-24 10:54:02 +00:00
|
|
|
* @covers EditPage
|
2012-11-10 16:24:48 +00:00
|
|
|
*/
|
|
|
|
|
public function testAutoMerge( $baseUser, $text, $adamsEdit, $bertasEdit,
|
2013-02-14 11:22:13 +00:00
|
|
|
$expectedCode, $expectedText, $message = null
|
2012-11-10 16:24:48 +00:00
|
|
|
) {
|
2012-11-22 16:45:50 +00:00
|
|
|
$this->checkHasDiff3();
|
2012-11-10 16:24:48 +00:00
|
|
|
|
2015-09-11 13:44:59 +00:00
|
|
|
// create page
|
2012-11-10 16:24:48 +00:00
|
|
|
$ns = $this->getDefaultWikitextNS();
|
|
|
|
|
$title = Title::newFromText( 'EditPageTest_testAutoMerge', $ns );
|
|
|
|
|
$page = WikiPage::factory( $title );
|
|
|
|
|
|
|
|
|
|
if ( $page->exists() ) {
|
|
|
|
|
$page->doDeleteArticle( "clean slate for testing" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$baseEdit = array(
|
|
|
|
|
'wpTextbox1' => $text,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$page = $this->assertEdit( 'EditPageTest_testAutoMerge', null,
|
2013-02-14 11:22:13 +00:00
|
|
|
$baseUser, $baseEdit, null, null, __METHOD__ );
|
2012-11-10 16:24:48 +00:00
|
|
|
|
|
|
|
|
$this->forceRevisionDate( $page, '20120101000000' );
|
|
|
|
|
|
|
|
|
|
$edittime = $page->getTimestamp();
|
|
|
|
|
|
|
|
|
|
// start timestamps for conflict detection
|
|
|
|
|
if ( !isset( $adamsEdit['wpStarttime'] ) ) {
|
|
|
|
|
$adamsEdit['wpStarttime'] = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !isset( $bertasEdit['wpStarttime'] ) ) {
|
|
|
|
|
$bertasEdit['wpStarttime'] = 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$starttime = wfTimestampNow();
|
2014-04-24 09:57:41 +00:00
|
|
|
$adamsTime = wfTimestamp(
|
|
|
|
|
TS_MW,
|
|
|
|
|
(int)wfTimestamp( TS_UNIX, $starttime ) + (int)$adamsEdit['wpStarttime']
|
|
|
|
|
);
|
|
|
|
|
$bertasTime = wfTimestamp(
|
|
|
|
|
TS_MW,
|
|
|
|
|
(int)wfTimestamp( TS_UNIX, $starttime ) + (int)$bertasEdit['wpStarttime']
|
|
|
|
|
);
|
2012-11-10 16:24:48 +00:00
|
|
|
|
|
|
|
|
$adamsEdit['wpStarttime'] = $adamsTime;
|
|
|
|
|
$bertasEdit['wpStarttime'] = $bertasTime;
|
|
|
|
|
|
|
|
|
|
$adamsEdit['wpSummary'] = 'Adam\'s edit';
|
|
|
|
|
$bertasEdit['wpSummary'] = 'Bertas\'s edit';
|
|
|
|
|
|
|
|
|
|
$adamsEdit['wpEdittime'] = $edittime;
|
|
|
|
|
$bertasEdit['wpEdittime'] = $edittime;
|
|
|
|
|
|
|
|
|
|
// first edit
|
|
|
|
|
$this->assertEdit( 'EditPageTest_testAutoMerge', null, 'Adam', $adamsEdit,
|
|
|
|
|
EditPage::AS_SUCCESS_UPDATE, null, "expected successfull update" );
|
|
|
|
|
|
|
|
|
|
// second edit
|
|
|
|
|
$this->assertEdit( 'EditPageTest_testAutoMerge', null, 'Berta', $bertasEdit,
|
|
|
|
|
$expectedCode, $expectedText, $message );
|
|
|
|
|
}
|
2015-04-15 08:26:22 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @depends testAutoMerge
|
|
|
|
|
*/
|
|
|
|
|
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 = array(
|
|
|
|
|
'wpTextbox1' => serialize( 'non-text content' ),
|
|
|
|
|
'wpEditToken' => $user->getEditToken(),
|
|
|
|
|
'wpEdittime' => '',
|
|
|
|
|
'wpStarttime' => wfTimestampNow()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$req = new FauxRequest( $edit, true );
|
|
|
|
|
$ep->importFormData( $req );
|
|
|
|
|
|
|
|
|
|
$this->setExpectedException(
|
|
|
|
|
'MWException',
|
|
|
|
|
'This content model is not supported: testing'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$ep->internalAttemptSave( $result, false );
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-06 23:35:42 +00:00
|
|
|
}
|