Addshore has uploaded a new change for review.
https://gerrit.wikimedia.org/r/266764
Change subject: Refactor EditPageTest::testAutoMerge to enable more edits
......................................................................
Refactor EditPageTest::testAutoMerge to enable more edits
This will allow future easy testing with 3 edits
involved in a conflict.
This will allow easy testing of many issues reported
around edit conflicts.
Change-Id: Icf7cbe09cf01742a5e3f43a047f76f471507bcd7
---
M tests/phpunit/includes/EditPageTest.php
1 file changed, 90 insertions(+), 70 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/64/266764/1
diff --git a/tests/phpunit/includes/EditPageTest.php
b/tests/phpunit/includes/EditPageTest.php
index 51f0083..8e368cd 100644
--- a/tests/phpunit/includes/EditPageTest.php
+++ b/tests/phpunit/includes/EditPageTest.php
@@ -383,33 +383,49 @@
$tests[] = array( # 0: plain conflict
"Elmo", # base edit user
"one\n\ntwo\n\nthree\n",
- array( # adam's edit
- 'wpStarttime' => 1,
- 'wpTextbox1' => "ONE\n\ntwo\n\nthree\n",
+ array(
+ array(
+ 'user' => 'Adam',
+ 'edit' => array(
+ 'wpStarttime' => 1,
+ 'wpTextbox1' =>
"ONE\n\ntwo\n\nthree\n",
+ ),
+ ),
+ array(
+ 'user' => 'Berta',
+ 'edit' => array(
+ 'wpStarttime' => 2,
+ 'wpTextbox1' =>
"(one)\n\ntwo\n\nthree\n",
+ ),
+ 'code' =>
EditPage::AS_CONFLICT_DETECTED,
+ 'text' => "ONE\n\ntwo\n\nthree\n",
+ 'message' => 'expected edit conflict',
+ ),
),
- array( # berta's edit
- '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
);
$tests[] = array( # 1: successful merge
"Elmo", # base edit user
"one\n\ntwo\n\nthree\n",
- array( # adam's edit
- 'wpStarttime' => 1,
- 'wpTextbox1' => "ONE\n\ntwo\n\nthree\n",
+ array(
+ array(
+ 'user' => 'Adam',
+ 'edit' => array(
+ 'wpStarttime' => 1,
+ 'wpTextbox1' =>
"ONE\n\ntwo\n\nthree\n",
+ ),
+ ),
+ array(
+ 'user' => 'Berta',
+ 'edit' => array(
+ 'wpStarttime' => 2,
+ 'wpTextbox1' =>
"one\n\ntwo\n\nTHREE\n",
+ ),
+ 'code' => EditPage::AS_SUCCESS_UPDATE,
+ 'text' => "ONE\n\ntwo\n\nTHREE\n",
+ 'message' => 'expected automatic merge',
+ ),
),
- array( # berta's edit
- '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";
@@ -427,19 +443,28 @@
$tests[] = array( # 2: merge in section
"Elmo", # base edit user
$text,
- array( # adam's edit
- 'wpStarttime' => 1,
- 'wpTextbox1' => str_replace( 'one', 'ONE',
$section ),
- 'wpSection' => '1'
+ array(
+ array(
+ 'user' => 'Adam',
+ 'edit' => array(
+ 'wpStarttime' => 1,
+ 'wpTextbox1' => str_replace(
'one', 'ONE', $section ),
+ 'wpSection' => '1'
+ ),
+ 'message' => "expected successfull
update",
+ ),
+ array(
+ 'user' => 'Berta',
+ 'edit' => array(
+ 'wpStarttime' => 2,
+ 'wpTextbox1' => str_replace(
'three', 'THREE', $section ),
+ 'wpSection' => '1'
+ ),
+ 'code' => EditPage::AS_SUCCESS_UPDATE,
+ 'text' => $expected,
+ 'message' => 'expected automatic
section merge',
+ ),
),
- array( # berta's edit
- '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
@@ -460,9 +485,7 @@
* @dataProvider provideAutoMerge
* @covers EditPage
*/
- public function testAutoMerge( $baseUser, $text, $adamsEdit,
$bertasEdit,
- $expectedCode, $expectedText, $message = null
- ) {
+ public function testAutoMerge( $baseUser, $text, $edits ) {
$this->checkHasDiff3();
// create page
@@ -483,43 +506,40 @@
$this->forceRevisionDate( $page, '20120101000000' );
- $edittime = $page->getTimestamp();
+ $editTime = $page->getTimestamp();
+ $timeBase = wfTimestampNow();
- // start timestamps for conflict detection
- if ( !isset( $adamsEdit['wpStarttime'] ) ) {
- $adamsEdit['wpStarttime'] = 1;
+ foreach ( $edits as $key => $editProvider ) {
+ $edit = $editProvider['edit'];
+
+ // start timestamps for conflict detection
+ if ( !isset( $edit['wpStarttime'] ) ) {
+ $edit['wpStarttime'] = 1;
+ }
+ $startTime = wfTimestamp(
+ TS_MW,
+ (int)wfTimestamp( TS_UNIX, $timeBase ) +
(int)$edit['wpStarttime']
+ );
+ $edit['wpStarttime'] = $startTime;
+ $edit['wpSummary'] = $editProvider['user'] . '\'s edit';
+ $edit['wpEdittime'] = $editTime;
+
+ $expectedCode = EditPage::AS_SUCCESS_UPDATE;
+ if ( array_key_exists( 'code', $editProvider ) ) {
+ $expectedCode = $editProvider['code'];
+ }
+ $expectedText = null;
+ if ( array_key_exists( 'text', $editProvider ) ) {
+ $expectedText = $editProvider['text'];
+ }
+ $message = "expected successfull update";
+ if ( array_key_exists( 'message', $editProvider ) ) {
+ $message = $editProvider['message'];
+ }
+
+ $this->assertEdit( 'EditPageTest_testAutoMerge', null,
$editProvider['user'], $edit,
+ $expectedCode, $expectedText, $message );
}
-
- if ( !isset( $bertasEdit['wpStarttime'] ) ) {
- $bertasEdit['wpStarttime'] = 2;
- }
-
- $starttime = wfTimestampNow();
- $adamsTime = wfTimestamp(
- TS_MW,
- (int)wfTimestamp( TS_UNIX, $starttime ) +
(int)$adamsEdit['wpStarttime']
- );
- $bertasTime = wfTimestamp(
- TS_MW,
- (int)wfTimestamp( TS_UNIX, $starttime ) +
(int)$bertasEdit['wpStarttime']
- );
-
- $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 );
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/266764
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Icf7cbe09cf01742a5e3f43a047f76f471507bcd7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits