2013-10-29 11:06:11 +00:00
|
|
|
<?php
|
|
|
|
|
|
2022-07-20 12:42:41 +00:00
|
|
|
use MediaWiki\MainConfigNames;
|
2022-12-17 22:11:10 +00:00
|
|
|
use MediaWiki\Permissions\SimpleAuthority;
|
2018-09-20 17:29:04 +00:00
|
|
|
use MediaWiki\Revision\MutableRevisionRecord;
|
|
|
|
|
use MediaWiki\Revision\RevisionRecord;
|
|
|
|
|
use MediaWiki\Revision\SlotRecord;
|
2023-03-01 20:33:26 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2017-11-22 13:28:52 +00:00
|
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
|
|
2013-10-29 11:06:11 +00:00
|
|
|
/**
|
|
|
|
|
* @covers DifferenceEngine
|
|
|
|
|
*
|
|
|
|
|
* @todo tests for the rest of DifferenceEngine!
|
|
|
|
|
*
|
|
|
|
|
* @group Database
|
2014-02-26 21:47:40 +00:00
|
|
|
* @group Diff
|
2013-10-29 11:06:11 +00:00
|
|
|
*
|
|
|
|
|
* @author Katie Filbert < aude.wiki@gmail.com >
|
|
|
|
|
*/
|
2020-06-30 15:09:24 +00:00
|
|
|
class DifferenceEngineTest extends MediaWikiIntegrationTestCase {
|
2021-02-24 05:12:55 +00:00
|
|
|
use MockTitleTrait;
|
2013-10-29 11:06:11 +00:00
|
|
|
|
|
|
|
|
protected $context;
|
|
|
|
|
|
|
|
|
|
private static $revisions;
|
|
|
|
|
|
2021-07-22 03:11:47 +00:00
|
|
|
protected function setUp(): void {
|
2013-10-29 11:06:11 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
$title = $this->getTitle();
|
|
|
|
|
|
|
|
|
|
$this->context = new RequestContext();
|
|
|
|
|
$this->context->setTitle( $title );
|
|
|
|
|
|
2022-07-20 12:42:41 +00:00
|
|
|
$this->overrideConfigValue( MainConfigNames::DiffEngine, 'php' );
|
2021-03-07 04:41:19 +00:00
|
|
|
|
|
|
|
|
$slotRoleRegistry = $this->getServiceContainer()->getSlotRoleRegistry();
|
|
|
|
|
|
|
|
|
|
if ( !$slotRoleRegistry->isDefinedRole( 'derivedslot' ) ) {
|
|
|
|
|
$slotRoleRegistry->defineRoleWithModel(
|
|
|
|
|
'derivedslot',
|
|
|
|
|
CONTENT_MODEL_WIKITEXT,
|
|
|
|
|
[],
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
}
|
2013-10-29 11:06:11 +00:00
|
|
|
}
|
|
|
|
|
|
2023-06-21 02:57:16 +00:00
|
|
|
public function addDBDataOnce() {
|
|
|
|
|
self::$revisions = $this->doEdits();
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-29 11:06:11 +00:00
|
|
|
/**
|
|
|
|
|
* @return Title
|
|
|
|
|
*/
|
|
|
|
|
protected function getTitle() {
|
|
|
|
|
$namespace = $this->getDefaultWikitextNS();
|
2022-07-05 22:21:30 +00:00
|
|
|
return Title::makeTitle( $namespace, 'Kitten' );
|
2013-10-29 11:06:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-08-13 17:54:49 +00:00
|
|
|
* @return int[] Revision ids
|
2013-10-29 11:06:11 +00:00
|
|
|
*/
|
|
|
|
|
protected function doEdits() {
|
|
|
|
|
$title = $this->getTitle();
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$strings = [ "it is a kitten", "two kittens", "three kittens", "four kittens" ];
|
|
|
|
|
$revisions = [];
|
2013-10-29 11:06:11 +00:00
|
|
|
|
2022-09-02 18:51:18 +00:00
|
|
|
$user = $this->getTestSysop()->getAuthority();
|
2013-11-19 18:03:54 +00:00
|
|
|
foreach ( $strings as $string ) {
|
2022-09-02 18:51:18 +00:00
|
|
|
$status = $this->editPage(
|
|
|
|
|
$title,
|
|
|
|
|
$string,
|
|
|
|
|
'edit page',
|
|
|
|
|
NS_MAIN,
|
|
|
|
|
$user
|
|
|
|
|
);
|
2022-11-14 20:17:19 +00:00
|
|
|
$revisions[] = $status->getNewRevision()->getId();
|
2013-10-29 11:06:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $revisions;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-21 02:57:16 +00:00
|
|
|
private function expandData( $data ) {
|
|
|
|
|
if ( is_array( $data ) ) {
|
|
|
|
|
foreach ( $data as &$value ) {
|
|
|
|
|
$value = $this->expandData( $value );
|
|
|
|
|
}
|
|
|
|
|
} elseif ( is_string( $data ) ) {
|
|
|
|
|
$data = preg_replace_callback(
|
|
|
|
|
'/rev\[([0-9]+)]/',
|
|
|
|
|
static function ( $m ) {
|
|
|
|
|
return self::$revisions[(int)$m[1]];
|
|
|
|
|
},
|
|
|
|
|
$data
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
2013-10-29 11:06:11 +00:00
|
|
|
|
2023-06-21 02:57:16 +00:00
|
|
|
private function expandTestArgs( $args ) {
|
|
|
|
|
foreach ( $args as &$arg ) {
|
|
|
|
|
$arg = $this->expandData( $arg );
|
2013-10-29 11:06:11 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-21 02:57:16 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provideMapDiffPrevNext
|
|
|
|
|
*/
|
|
|
|
|
public function testMapDiffPrevNext( $expected, $old, $new, $message ) {
|
|
|
|
|
$this->expandTestArgs( [ &$expected, &$old, &$new, &$message ] );
|
|
|
|
|
$diffEngine = new DifferenceEngine( $this->context, $old, $new, 2, true, false );
|
|
|
|
|
$diffMap = $diffEngine->mapDiffPrevNext( $old, $new );
|
|
|
|
|
$this->assertEquals( $expected, $diffMap, $message );
|
|
|
|
|
}
|
2013-10-29 11:06:11 +00:00
|
|
|
|
2023-06-21 02:57:16 +00:00
|
|
|
public static function provideMapDiffPrevNext() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2023-06-21 02:57:16 +00:00
|
|
|
[ [ 'rev[1]', 'rev[2]' ], 'rev[2]', 'prev', 'diff=prev' ],
|
|
|
|
|
[ [ 'rev[2]', 'rev[3]' ], 'rev[2]', 'next', 'diff=next' ],
|
|
|
|
|
[ [ 'rev[1]', 'rev[3]' ], 'rev[1]', 'rev[3]', 'diff=rev3' ]
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2013-10-29 11:06:11 +00:00
|
|
|
}
|
|
|
|
|
|
2023-06-21 02:57:16 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provideLoadRevision
|
|
|
|
|
*/
|
|
|
|
|
public function testLoadRevisionData( $expectedOld, $expectedNew, $expectedRet, $old, $new ) {
|
|
|
|
|
$this->expandTestArgs( [ &$expectedOld, &$expectedNew, &$expectedRet, &$old, &$new ] );
|
|
|
|
|
$diffEngine = new DifferenceEngine( $this->context, $old, $new, 2, true, false );
|
|
|
|
|
$ret = $diffEngine->loadRevisionData();
|
|
|
|
|
$ret2 = $diffEngine->loadRevisionData();
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expectedOld, $diffEngine->getOldid() );
|
|
|
|
|
$this->assertEquals( $expectedNew, $diffEngine->getNewid() );
|
|
|
|
|
$this->assertEquals( $expectedRet, $ret );
|
|
|
|
|
$this->assertEquals( $expectedRet, $ret2 );
|
2013-10-29 11:06:11 +00:00
|
|
|
}
|
|
|
|
|
|
2023-06-21 02:57:16 +00:00
|
|
|
public static function provideLoadRevision() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2023-06-21 02:57:16 +00:00
|
|
|
'diff=prev' => [ 'rev[2]', 'rev[3]', true, 'rev[3]', 'prev' ],
|
|
|
|
|
'diff=next' => [ 'rev[2]', 'rev[3]', true, 'rev[2]', 'next' ],
|
|
|
|
|
'diff=' . 'rev[3]' => [ 'rev[1]', 'rev[3]', true, 'rev[1]', 'rev[3]' ],
|
|
|
|
|
'diff=0' => [ 'rev[1]', 'rev[3]', true, 'rev[1]', 0 ],
|
|
|
|
|
'diff=prev&oldid=<first>' => [ false, 'rev[0]', true, 'rev[0]', 'prev' ],
|
|
|
|
|
'invalid' => [ 123456789, 'rev[1]', false, 123456789, 'rev[1]' ],
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2013-10-29 11:06:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetOldid() {
|
|
|
|
|
$revs = self::$revisions;
|
|
|
|
|
|
|
|
|
|
$diffEngine = new DifferenceEngine( $this->context, $revs[1], $revs[2], 2, true, false );
|
|
|
|
|
$this->assertEquals( $revs[1], $diffEngine->getOldid(), 'diff get old id' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetNewid() {
|
|
|
|
|
$revs = self::$revisions;
|
|
|
|
|
|
|
|
|
|
$diffEngine = new DifferenceEngine( $this->context, $revs[1], $revs[2], 2, true, false );
|
|
|
|
|
$this->assertEquals( $revs[2], $diffEngine->getNewid(), 'diff get new id' );
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-23 11:36:19 +00:00
|
|
|
public static function provideLocaliseTitleTooltipsTestData() {
|
2017-11-22 13:28:52 +00:00
|
|
|
return [
|
|
|
|
|
'moved paragraph left shoud get new location title' => [
|
|
|
|
|
'<a class="mw-diff-movedpara-left">⚫</a>',
|
|
|
|
|
'<a class="mw-diff-movedpara-left" title="(diff-paragraph-moved-tonew)">⚫</a>',
|
|
|
|
|
],
|
|
|
|
|
'moved paragraph right shoud get old location title' => [
|
|
|
|
|
'<a class="mw-diff-movedpara-right">⚫</a>',
|
|
|
|
|
'<a class="mw-diff-movedpara-right" title="(diff-paragraph-moved-toold)">⚫</a>',
|
|
|
|
|
],
|
|
|
|
|
'nothing changed when key not hit' => [
|
|
|
|
|
'<a class="mw-diff-movedpara-rightis">⚫</a>',
|
|
|
|
|
'<a class="mw-diff-movedpara-rightis">⚫</a>',
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideLocaliseTitleTooltipsTestData
|
|
|
|
|
*/
|
|
|
|
|
public function testAddLocalisedTitleTooltips( $input, $expected ) {
|
|
|
|
|
$this->setContentLang( 'qqx' );
|
2022-01-21 08:55:23 +00:00
|
|
|
/** @var DifferenceEngine $diffEngine */
|
2017-11-22 13:28:52 +00:00
|
|
|
$diffEngine = TestingAccessWrapper::newFromObject( new DifferenceEngine() );
|
|
|
|
|
$this->assertEquals( $expected, $diffEngine->addLocalisedTitleTooltips( $input ) );
|
|
|
|
|
}
|
|
|
|
|
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provideGenerateContentDiffBody
|
|
|
|
|
*/
|
|
|
|
|
public function testGenerateContentDiffBody(
|
2019-08-26 08:17:59 +00:00
|
|
|
array $oldContentArgs, array $newContentArgs, $expectedDiff
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
) {
|
2019-08-26 08:17:59 +00:00
|
|
|
$this->mergeMwGlobalArrayValue( 'wgContentHandlers', [
|
|
|
|
|
'testing-nontext' => DummyNonTextContentHandler::class,
|
|
|
|
|
] );
|
|
|
|
|
$oldContent = ContentHandler::makeContent( ...$oldContentArgs );
|
|
|
|
|
$newContent = ContentHandler::makeContent( ...$newContentArgs );
|
|
|
|
|
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
$differenceEngine = new DifferenceEngine();
|
|
|
|
|
$diff = $differenceEngine->generateContentDiffBody( $oldContent, $newContent );
|
|
|
|
|
$this->assertSame( $expectedDiff, $this->getPlainDiff( $diff ) );
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-26 08:17:59 +00:00
|
|
|
public static function provideGenerateContentDiffBody() {
|
|
|
|
|
$content1 = [ 'xxx', null, CONTENT_MODEL_TEXT ];
|
|
|
|
|
$content2 = [ 'yyy', null, CONTENT_MODEL_TEXT ];
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
'self-diff' => [ $content1, $content1, '' ],
|
|
|
|
|
'text diff' => [ $content1, $content2, '-xxx+yyy' ],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGenerateTextDiffBody() {
|
|
|
|
|
$oldText = "aaa\nbbb\nccc";
|
|
|
|
|
$newText = "aaa\nxxx\nccc";
|
|
|
|
|
$expectedDiff = " aaa aaa\n-bbb+xxx\n ccc ccc";
|
|
|
|
|
|
|
|
|
|
$differenceEngine = new DifferenceEngine();
|
|
|
|
|
$diff = $differenceEngine->generateTextDiffBody( $oldText, $newText );
|
|
|
|
|
$this->assertSame( $expectedDiff, $this->getPlainDiff( $diff ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testSetContent() {
|
|
|
|
|
$oldContent = ContentHandler::makeContent( 'xxx', null, CONTENT_MODEL_TEXT );
|
|
|
|
|
$newContent = ContentHandler::makeContent( 'yyy', null, CONTENT_MODEL_TEXT );
|
|
|
|
|
|
|
|
|
|
$differenceEngine = new DifferenceEngine();
|
|
|
|
|
$differenceEngine->setContent( $oldContent, $newContent );
|
|
|
|
|
$diff = $differenceEngine->getDiffBody();
|
|
|
|
|
$this->assertSame( "Line 1:\nLine 1:\n-xxx+yyy", $this->getPlainDiff( $diff ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testSetRevisions() {
|
2023-06-21 02:57:16 +00:00
|
|
|
$rev1 = $this->getRevisionRecord( [ SlotRecord::MAIN => 'xxx' ] );
|
|
|
|
|
$rev2 = $this->getRevisionRecord( [ SlotRecord::MAIN => 'yyy' ] );
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
|
|
|
|
|
$differenceEngine = new DifferenceEngine();
|
|
|
|
|
$differenceEngine->setRevisions( $rev1, $rev2 );
|
|
|
|
|
$this->assertSame( $rev1, $differenceEngine->getOldRevision() );
|
|
|
|
|
$this->assertSame( $rev2, $differenceEngine->getNewRevision() );
|
|
|
|
|
$this->assertSame( true, $differenceEngine->loadRevisionData() );
|
|
|
|
|
$this->assertSame( true, $differenceEngine->loadText() );
|
|
|
|
|
|
|
|
|
|
$differenceEngine->setRevisions( null, $rev2 );
|
|
|
|
|
$this->assertSame( null, $differenceEngine->getOldRevision() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideGetDiffBody
|
|
|
|
|
*/
|
|
|
|
|
public function testGetDiffBody(
|
2023-06-21 02:57:16 +00:00
|
|
|
?array $oldSlots, ?array $newSlots, $expectedDiff
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
) {
|
2023-06-21 02:57:16 +00:00
|
|
|
$oldRevision = $this->getRevisionRecord( $oldSlots );
|
|
|
|
|
$newRevision = $this->getRevisionRecord( $newSlots );
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
if ( $expectedDiff instanceof Exception ) {
|
2019-10-06 09:52:39 +00:00
|
|
|
$this->expectException( get_class( $expectedDiff ) );
|
|
|
|
|
$this->expectExceptionMessage( $expectedDiff->getMessage() );
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
}
|
|
|
|
|
$differenceEngine = new DifferenceEngine();
|
|
|
|
|
$differenceEngine->setRevisions( $oldRevision, $newRevision );
|
|
|
|
|
if ( $expectedDiff instanceof Exception ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$diff = $differenceEngine->getDiffBody();
|
|
|
|
|
$this->assertSame( $expectedDiff, $this->getPlainDiff( $diff ) );
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-21 02:57:16 +00:00
|
|
|
public static function provideGetDiffBody() {
|
|
|
|
|
$main1 = [ SlotRecord::MAIN => 'xxx' ];
|
|
|
|
|
$main2 = [ SlotRecord::MAIN => 'yyy' ];
|
|
|
|
|
$slot1 = [ 'slot' => 'aaa' ];
|
|
|
|
|
$slot2 = [ 'slot' => 'bbb' ];
|
2019-01-20 23:11:59 +00:00
|
|
|
$slot3 = [ 'derivedslot' => [ 'text' => 'aaa', 'derived' => true ] ];
|
|
|
|
|
$slot4 = [ 'derivedslot' => [ 'text' => 'bbb', 'derived' => true ] ];
|
|
|
|
|
$slot5 = [ 'slot' => [ 'model' => 'testing' ] ];
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
'revision vs. null' => [
|
|
|
|
|
null,
|
2023-06-21 02:57:16 +00:00
|
|
|
$main1 + $slot1,
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
'',
|
|
|
|
|
],
|
|
|
|
|
'revision vs. itself' => [
|
2023-06-21 02:57:16 +00:00
|
|
|
$main1 + $slot1,
|
|
|
|
|
$main1 + $slot1,
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
'',
|
|
|
|
|
],
|
|
|
|
|
'different text in one slot' => [
|
2023-06-21 02:57:16 +00:00
|
|
|
$main1 + $slot1,
|
|
|
|
|
$main1 + $slot2,
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
"slotLine 1:\nLine 1:\n-aaa+bbb",
|
|
|
|
|
],
|
|
|
|
|
'different text in two slots' => [
|
2023-06-21 02:57:16 +00:00
|
|
|
$main1 + $slot1,
|
|
|
|
|
$main2 + $slot2,
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
"Line 1:\nLine 1:\n-xxx+yyy\nslotLine 1:\nLine 1:\n-aaa+bbb",
|
|
|
|
|
],
|
|
|
|
|
'new slot' => [
|
2023-06-21 02:57:16 +00:00
|
|
|
$main1,
|
|
|
|
|
$main1 + $slot1,
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
"slotLine 1:\nLine 1:\n- +aaa",
|
|
|
|
|
],
|
2021-03-07 04:41:19 +00:00
|
|
|
'ignored difference in derived slot' => [
|
2023-06-21 02:57:16 +00:00
|
|
|
$main1 + $slot3,
|
|
|
|
|
$main1 + $slot4,
|
2021-03-07 04:41:19 +00:00
|
|
|
'',
|
|
|
|
|
],
|
2019-01-20 23:11:59 +00:00
|
|
|
'incompatible slot' => [
|
|
|
|
|
$main1 + $slot5,
|
|
|
|
|
$main2 + $slot1,
|
|
|
|
|
"Line 1:\nLine 1:\n-xxx+yyy\nslotCannot compare content models \"testing\" and \"plain text\"",
|
|
|
|
|
],
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testRecursion() {
|
|
|
|
|
// Set up a ContentHandler which will return a wrapped DifferenceEngine as
|
|
|
|
|
// SlotDiffRenderer, then pass it a content which uses the same ContentHandler.
|
|
|
|
|
// This tests the anti-recursion logic in DifferenceEngine::generateContentDiffBody.
|
|
|
|
|
|
|
|
|
|
$customDifferenceEngine = $this->getMockBuilder( DifferenceEngine::class )
|
|
|
|
|
->enableProxyingToOriginalMethods()
|
|
|
|
|
->getMock();
|
|
|
|
|
$customContentHandler = $this->getMockBuilder( ContentHandler::class )
|
|
|
|
|
->setConstructorArgs( [ 'foo', [] ] )
|
2021-03-20 15:18:58 +00:00
|
|
|
->onlyMethods( [ 'createDifferenceEngine' ] )
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
->getMockForAbstractClass();
|
2021-04-22 08:40:46 +00:00
|
|
|
$customContentHandler->method( 'createDifferenceEngine' )
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
->willReturn( $customDifferenceEngine );
|
2019-02-02 13:39:58 +00:00
|
|
|
/** @var ContentHandler $customContentHandler */
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
$customContent = $this->getMockBuilder( Content::class )
|
2021-03-20 15:18:58 +00:00
|
|
|
->onlyMethods( [ 'getContentHandler' ] )
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
->getMockForAbstractClass();
|
2021-04-22 08:40:46 +00:00
|
|
|
$customContent->method( 'getContentHandler' )
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
->willReturn( $customContentHandler );
|
2019-02-02 13:39:58 +00:00
|
|
|
/** @var Content $customContent */
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
$customContent2 = clone $customContent;
|
|
|
|
|
|
|
|
|
|
$slotDiffRenderer = $customContentHandler->getSlotDiffRenderer( RequestContext::getMain() );
|
2019-10-05 15:42:53 +00:00
|
|
|
$this->expectException( Exception::class );
|
|
|
|
|
$this->expectExceptionMessage(
|
|
|
|
|
': could not maintain backwards compatibility. Please use a SlotDiffRenderer.'
|
|
|
|
|
);
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
$slotDiffRenderer->getDiff( $customContent, $customContent2 );
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-25 15:39:48 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provideMarkPatrolledLink
|
|
|
|
|
*/
|
|
|
|
|
public function testMarkPatrolledLink( $group, $config, $expectedResult ) {
|
|
|
|
|
$this->setUserLang( 'qqx' );
|
|
|
|
|
$user = $this->getTestUser( $group )->getUser();
|
|
|
|
|
$this->context->setUser( $user );
|
|
|
|
|
if ( $config ) {
|
2023-06-21 02:57:16 +00:00
|
|
|
$this->context->setConfig( new HashConfig( $config ) );
|
2021-05-25 15:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
2022-12-04 19:09:28 +00:00
|
|
|
$page = $this->getNonexistingTestPage( 'Page1' );
|
2021-11-21 16:23:11 +00:00
|
|
|
$this->assertTrue( $this->editPage( $page, 'Edit1' )->isGood(), 'edited a page' );
|
2021-05-25 15:39:48 +00:00
|
|
|
$rev1 = $page->getRevisionRecord();
|
2021-11-21 16:23:11 +00:00
|
|
|
$this->assertTrue( $this->editPage( $page, 'Edit2' )->isGood(), 'edited a page' );
|
2021-05-25 15:39:48 +00:00
|
|
|
$rev2 = $page->getRevisionRecord();
|
|
|
|
|
|
|
|
|
|
$diffEngine = new DifferenceEngine( $this->context );
|
|
|
|
|
$diffEngine->setRevisions( $rev1, $rev2 );
|
|
|
|
|
|
|
|
|
|
$html = $diffEngine->markPatrolledLink();
|
|
|
|
|
$this->assertStringContainsString( $expectedResult, $html );
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-23 11:36:19 +00:00
|
|
|
public static function provideMarkPatrolledLink() {
|
2021-05-25 15:39:48 +00:00
|
|
|
yield 'PatrollingEnabledUserAllowed' => [
|
|
|
|
|
'sysop',
|
2023-06-21 02:57:16 +00:00
|
|
|
[ MainConfigNames::UseRCPatrol => true, MainConfigNames::LanguageCode => 'qxx' ],
|
2021-05-25 15:39:48 +00:00
|
|
|
'Mark as patrolled'
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
yield 'PatrollingEnabledUserNotAllowed' => [
|
|
|
|
|
null,
|
2023-06-21 02:57:16 +00:00
|
|
|
[ MainConfigNames::UseRCPatrol => true, MainConfigNames::LanguageCode => 'qxx' ],
|
2021-05-25 15:39:48 +00:00
|
|
|
''
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
yield 'PatrollingDisabledUserAllowed' => [
|
|
|
|
|
'sysop',
|
|
|
|
|
null,
|
|
|
|
|
''
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
yield 'PatrollingDisabledUserNotAllowed' => [
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
''
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
/**
|
|
|
|
|
* Convert a HTML diff to a human-readable format and hopefully make the test less fragile.
|
2021-01-14 08:20:36 +00:00
|
|
|
* @param string $diff
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
private function getPlainDiff( $diff ) {
|
|
|
|
|
$replacements = [
|
|
|
|
|
html_entity_decode( ' ' ) => ' ',
|
|
|
|
|
html_entity_decode( '−' ) => '-',
|
|
|
|
|
];
|
2020-11-29 20:46:02 +00:00
|
|
|
// Preserve markers when stripping tags
|
|
|
|
|
$diff = str_replace( '<td class="diff-marker"></td>', ' ', $diff );
|
|
|
|
|
$diff = str_replace( '<td colspan="2"></td>', ' ', $diff );
|
|
|
|
|
$diff = preg_replace( '/data-marker="([^"]*)">/', '>$1', $diff );
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
return str_replace( array_keys( $replacements ), array_values( $replacements ),
|
|
|
|
|
trim( strip_tags( $diff ), "\n" ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-01-20 23:11:59 +00:00
|
|
|
* @param string[]|array[]|null $slots Array mapping slot role to content.
|
|
|
|
|
* If the content is a string, a normal text slot will be created. If the
|
|
|
|
|
* content is an associative array, it can have the following keys:
|
|
|
|
|
* - derived: If present and true, the slot is a derived slot
|
|
|
|
|
* - text: The serialized content
|
|
|
|
|
* - model: The content model ID
|
2023-06-21 02:57:16 +00:00
|
|
|
* @return MutableRevisionRecord|null
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
*/
|
2023-06-21 02:57:16 +00:00
|
|
|
private function getRevisionRecord( $slots ) {
|
|
|
|
|
if ( $slots === null ) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-20 23:11:59 +00:00
|
|
|
$contentHandlerFactory = $this->getServiceContainer()->getContentHandlerFactory();
|
2021-02-24 05:12:55 +00:00
|
|
|
$title = $this->makeMockTitle( __CLASS__ );
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
$revision = new MutableRevisionRecord( $title );
|
2019-01-20 23:11:59 +00:00
|
|
|
foreach ( $slots as $role => $info ) {
|
|
|
|
|
if ( is_string( $info ) ) {
|
|
|
|
|
$info = [
|
|
|
|
|
'text' => $info,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
$info += [ 'text' => '', 'model' => CONTENT_MODEL_TEXT ];
|
|
|
|
|
|
|
|
|
|
if ( !$contentHandlerFactory->isDefinedModel( $info['model'] ) ) {
|
|
|
|
|
$contentHandlerFactory->defineContentHandler(
|
|
|
|
|
$info['model'], DummyContentHandlerForTesting::class );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$content = ContentHandler::makeContent( $info['text'], null, $info['model'] );
|
|
|
|
|
if ( $info['derived'] ?? false ) {
|
2023-06-21 02:57:16 +00:00
|
|
|
$slotRecord = SlotRecord::newDerived( $role, $content );
|
|
|
|
|
} else {
|
|
|
|
|
$slotRecord = SlotRecord::newUnsaved( $role, $content );
|
|
|
|
|
}
|
|
|
|
|
$revision->setSlot( $slotRecord );
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
}
|
|
|
|
|
return $revision;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-17 22:11:10 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provideRevisionHeader
|
|
|
|
|
*/
|
|
|
|
|
public function testRevisionHeader( $deletedFlag, $allowedAction ) {
|
|
|
|
|
$revs = self::$revisions;
|
|
|
|
|
|
|
|
|
|
if ( $deletedFlag !== 'none' ) {
|
|
|
|
|
$this->revisionDelete(
|
|
|
|
|
$revs[1],
|
|
|
|
|
[
|
|
|
|
|
RevisionRecord::DELETED_TEXT => 1,
|
|
|
|
|
RevisionRecord::DELETED_RESTRICTED => $deletedFlag === 'suppressed' ? 1 : 0,
|
|
|
|
|
],
|
|
|
|
|
'Testing'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$context = new DerivativeContext( $this->context );
|
|
|
|
|
$context->setLanguage( 'qqx' );
|
|
|
|
|
$permissionSet = [];
|
|
|
|
|
if ( $allowedAction !== 'none' ) {
|
|
|
|
|
if ( $allowedAction === 'edit' ) {
|
|
|
|
|
$permissionSet[] = 'edit';
|
|
|
|
|
}
|
|
|
|
|
if ( $deletedFlag === 'suppressed' ) {
|
|
|
|
|
$permissionSet[] = 'suppressrevision';
|
|
|
|
|
} else {
|
|
|
|
|
$permissionSet[] = 'deletedtext';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$context->setAuthority(
|
|
|
|
|
new SimpleAuthority( $this->getTestUser()->getUser(), $permissionSet )
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$diffEngine = new DifferenceEngine( $context, $revs[1], $revs[2], 2, true, true );
|
|
|
|
|
$this->assertTrue( $diffEngine->loadRevisionData() );
|
|
|
|
|
$revisionHeaderHtml = $diffEngine->getRevisionHeader( $diffEngine->getOldRevision(), 'complete' );
|
|
|
|
|
|
|
|
|
|
// Always show the timestamp
|
|
|
|
|
$this->assertStringContainsString( '(revisionasof:', $revisionHeaderHtml );
|
|
|
|
|
|
2022-12-17 20:50:05 +00:00
|
|
|
if ( $allowedAction === 'none' ) {
|
|
|
|
|
$this->assertStringNotContainsString( 'oldid=' . $revs[1], $revisionHeaderHtml );
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertStringContainsString( 'oldid=' . $revs[1], $revisionHeaderHtml );
|
|
|
|
|
}
|
2022-12-17 22:11:10 +00:00
|
|
|
if ( $allowedAction === 'edit' ) {
|
|
|
|
|
$this->assertStringContainsString( '(editold)', $revisionHeaderHtml );
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertStringNotContainsString( '(editold)', $revisionHeaderHtml );
|
|
|
|
|
}
|
|
|
|
|
if ( $allowedAction === 'view' ) {
|
|
|
|
|
$this->assertStringContainsString( '(viewsourceold)', $revisionHeaderHtml );
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertStringNotContainsString( '(viewsourceold)', $revisionHeaderHtml );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $deletedFlag === 'none' ) {
|
|
|
|
|
$this->assertStringNotContainsString( 'history-deleted', $revisionHeaderHtml );
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertStringContainsString( 'history-deleted', $revisionHeaderHtml );
|
|
|
|
|
}
|
2022-12-17 20:50:05 +00:00
|
|
|
if ( $deletedFlag === 'suppressed' ) {
|
2022-12-17 22:11:10 +00:00
|
|
|
$this->assertStringContainsString( 'mw-history-suppressed', $revisionHeaderHtml );
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertStringNotContainsString( 'mw-history-suppressed', $revisionHeaderHtml );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-23 11:36:19 +00:00
|
|
|
public static function provideRevisionHeader() {
|
2022-12-17 22:11:10 +00:00
|
|
|
return [
|
|
|
|
|
[ 'none', 'view' ],
|
|
|
|
|
[ 'none', 'edit' ],
|
|
|
|
|
[ 'deleted', 'none' ],
|
|
|
|
|
[ 'deleted', 'view' ],
|
|
|
|
|
[ 'deleted', 'edit' ],
|
|
|
|
|
[ 'suppressed', 'none' ],
|
|
|
|
|
[ 'suppressed', 'view' ],
|
|
|
|
|
[ 'suppressed', 'edit' ],
|
|
|
|
|
];
|
|
|
|
|
}
|
2013-10-29 11:06:11 +00:00
|
|
|
}
|