2012-04-18 13:02:21 +00:00
|
|
|
<?php
|
2019-05-28 14:04:23 +00:00
|
|
|
|
2021-10-22 12:48:23 +00:00
|
|
|
use MediaWiki\Content\ValidationParams;
|
2016-05-12 22:44:33 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2021-10-22 12:48:23 +00:00
|
|
|
use MediaWiki\Page\PageIdentity;
|
|
|
|
|
use MediaWiki\Page\PageIdentityValue;
|
[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
|
|
|
use Wikimedia\TestingAccessWrapper;
|
2012-04-18 13:02:21 +00:00
|
|
|
|
2012-05-13 22:02:29 +00:00
|
|
|
/**
|
|
|
|
|
* @group ContentHandler
|
2016-05-16 20:24:10 +00:00
|
|
|
* @group Database
|
2012-05-13 22:02:29 +00:00
|
|
|
*/
|
2020-06-30 15:09:24 +00:00
|
|
|
class ContentHandlerTest extends MediaWikiIntegrationTestCase {
|
2012-04-18 13:02:21 +00:00
|
|
|
|
2021-07-22 03:11:47 +00:00
|
|
|
protected function setUp(): void {
|
2013-03-22 16:44:34 +00:00
|
|
|
parent::setUp();
|
2012-09-12 11:43:52 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->setMwGlobals( [
|
|
|
|
|
'wgExtraNamespaces' => [
|
2012-10-20 01:51:15 +00:00
|
|
|
12312 => 'Dummy',
|
|
|
|
|
12313 => 'Dummy_talk',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2012-10-20 01:51:15 +00:00
|
|
|
// The below tests assume that namespaces not mentioned here (Help, User, MediaWiki, ..)
|
|
|
|
|
// default to CONTENT_MODEL_WIKITEXT.
|
2016-02-17 09:09:32 +00:00
|
|
|
'wgNamespaceContentModels' => [
|
2012-10-20 01:51:15 +00:00
|
|
|
12312 => 'testing',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'wgContentHandlers' => [
|
2018-01-13 00:02:09 +00:00
|
|
|
CONTENT_MODEL_WIKITEXT => WikitextContentHandler::class,
|
|
|
|
|
CONTENT_MODEL_JAVASCRIPT => JavaScriptContentHandler::class,
|
|
|
|
|
CONTENT_MODEL_JSON => JsonContentHandler::class,
|
|
|
|
|
CONTENT_MODEL_CSS => CssContentHandler::class,
|
|
|
|
|
CONTENT_MODEL_TEXT => TextContentHandler::class,
|
|
|
|
|
'testing' => DummyContentHandlerForTesting::class,
|
2021-02-07 13:10:36 +00:00
|
|
|
'testing-callbacks' => static function ( $modelId ) {
|
2016-02-05 13:40:39 +00:00
|
|
|
return new DummyContentHandlerForTesting( $modelId );
|
|
|
|
|
}
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
] );
|
2012-10-20 01:51:15 +00:00
|
|
|
|
2018-08-01 12:40:47 +00:00
|
|
|
// Reset LinkCache
|
2016-05-12 22:44:33 +00:00
|
|
|
MediaWikiServices::getInstance()->resetServiceForTesting( 'LinkCache' );
|
2012-04-26 10:11:01 +00:00
|
|
|
}
|
|
|
|
|
|
2021-07-22 03:11:47 +00:00
|
|
|
protected function tearDown(): void {
|
2018-08-01 12:40:47 +00:00
|
|
|
// Reset LinkCache
|
2016-05-12 22:44:33 +00:00
|
|
|
MediaWikiServices::getInstance()->resetServiceForTesting( 'LinkCache' );
|
2012-04-26 10:11:01 +00:00
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
parent::tearDown();
|
2012-04-26 10:11:01 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-16 20:24:10 +00:00
|
|
|
public function addDBDataOnce() {
|
|
|
|
|
$this->insertPage( 'Not_Main_Page', 'This is not a main page' );
|
|
|
|
|
$this->insertPage( 'Smithee', 'A smithee is one who smiths. See also [[Alan Smithee]]' );
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
public static function dataGetDefaultModelFor() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[ 'Help:Foo', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
[ 'Help:Foo.js', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
[ 'Help:Foo.css', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
[ 'Help:Foo.json', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
[ 'Help:Foo/bar.js', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
[ 'User:Foo', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
[ 'User:Foo.js', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
[ 'User:Foo.css', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
[ 'User:Foo.json', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
[ 'User:Foo/bar.js', CONTENT_MODEL_JAVASCRIPT ],
|
|
|
|
|
[ 'User:Foo/bar.css', CONTENT_MODEL_CSS ],
|
|
|
|
|
[ 'User:Foo/bar.json', CONTENT_MODEL_JSON ],
|
|
|
|
|
[ 'User:Foo/bar.json.nope', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
[ 'User talk:Foo/bar.css', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
[ 'User:Foo/bar.js.xxx', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
[ 'User:Foo/bar.xxx', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
[ 'MediaWiki:Foo.js', CONTENT_MODEL_JAVASCRIPT ],
|
|
|
|
|
[ 'MediaWiki:Foo.JS', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
[ 'MediaWiki:Foo.css', CONTENT_MODEL_CSS ],
|
|
|
|
|
[ 'MediaWiki:Foo.css.xxx', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
[ 'MediaWiki:Foo.CSS', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
[ 'MediaWiki:Foo.json', CONTENT_MODEL_JSON ],
|
|
|
|
|
[ 'MediaWiki:Foo.JSON', CONTENT_MODEL_WIKITEXT ],
|
|
|
|
|
];
|
2012-04-25 16:35:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider dataGetDefaultModelFor
|
2013-10-18 10:53:29 +00:00
|
|
|
* @covers ContentHandler::getDefaultModelFor
|
2012-04-25 16:35:36 +00:00
|
|
|
*/
|
2012-05-13 22:02:29 +00:00
|
|
|
public function testGetDefaultModelFor( $title, $expectedModelId ) {
|
2012-04-25 16:35:36 +00:00
|
|
|
$title = Title::newFromText( $title );
|
2012-05-13 22:02:29 +00:00
|
|
|
$this->assertEquals( $expectedModelId, ContentHandler::getDefaultModelFor( $title ) );
|
2012-04-25 16:35:36 +00:00
|
|
|
}
|
2012-10-20 01:51:15 +00:00
|
|
|
|
2012-04-25 16:35:36 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider dataGetDefaultModelFor
|
2013-10-18 10:53:29 +00:00
|
|
|
* @covers ContentHandler::getForTitle
|
2012-04-25 16:35:36 +00:00
|
|
|
*/
|
|
|
|
|
public function testGetForTitle( $title, $expectedContentModel ) {
|
2021-05-28 20:22:01 +00:00
|
|
|
$this->hideDeprecated( 'ContentHandler::getForTitle' );
|
2012-04-25 16:35:36 +00:00
|
|
|
$title = Title::newFromText( $title );
|
2018-06-11 06:55:11 +00:00
|
|
|
MediaWikiServices::getInstance()->getLinkCache()->addBadLinkObj( $title );
|
2012-04-25 16:35:36 +00:00
|
|
|
$handler = ContentHandler::getForTitle( $title );
|
2012-05-13 22:02:29 +00:00
|
|
|
$this->assertEquals( $expectedContentModel, $handler->getModelID() );
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
public static function dataGetLocalizedName() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[ null, null ],
|
|
|
|
|
[ "xyzzy", null ],
|
2012-05-13 22:02:29 +00:00
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
// XXX: depends on content language
|
2016-02-17 09:09:32 +00:00
|
|
|
[ CONTENT_MODEL_JAVASCRIPT, '/javascript/i' ],
|
|
|
|
|
];
|
2012-05-13 22:02:29 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-19 12:45:25 +00:00
|
|
|
/**
|
2012-06-25 21:30:51 +00:00
|
|
|
* @dataProvider dataGetLocalizedName
|
2013-10-18 10:53:29 +00:00
|
|
|
* @covers ContentHandler::getLocalizedName
|
2012-06-19 12:45:25 +00:00
|
|
|
*/
|
|
|
|
|
public function testGetLocalizedName( $id, $expected ) {
|
2012-06-25 21:30:51 +00:00
|
|
|
$name = ContentHandler::getLocalizedName( $id );
|
2012-06-19 12:45:25 +00:00
|
|
|
|
2012-06-25 21:30:51 +00:00
|
|
|
if ( $expected ) {
|
|
|
|
|
$this->assertNotNull( $name, "no name found for content model $id" );
|
2013-01-28 10:27:15 +00:00
|
|
|
$this->assertTrue( preg_match( $expected, $name ) > 0,
|
2012-10-20 01:51:15 +00:00
|
|
|
"content model name for #$id did not match pattern $expected"
|
|
|
|
|
);
|
2012-06-25 21:30:51 +00:00
|
|
|
} else {
|
2012-08-20 19:33:07 +00:00
|
|
|
$this->assertEquals( $id, $name, "localization of unknown model $id should have "
|
2012-10-20 01:51:15 +00:00
|
|
|
. "fallen back to use the model id directly."
|
|
|
|
|
);
|
2012-06-19 12:45:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
public static function dataGetPageLanguage() {
|
2012-06-26 14:37:42 +00:00
|
|
|
global $wgLanguageCode;
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[ "Main", $wgLanguageCode ],
|
|
|
|
|
[ "Dummy:Foo", $wgLanguageCode ],
|
|
|
|
|
[ "MediaWiki:common.js", 'en' ],
|
|
|
|
|
[ "User:Foo/common.js", 'en' ],
|
|
|
|
|
[ "MediaWiki:common.css", 'en' ],
|
|
|
|
|
[ "User:Foo/common.css", 'en' ],
|
|
|
|
|
[ "User:Foo", $wgLanguageCode ],
|
|
|
|
|
|
|
|
|
|
[ CONTENT_MODEL_JAVASCRIPT, 'javascript' ],
|
|
|
|
|
];
|
2012-06-26 14:37:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider dataGetPageLanguage
|
2013-10-18 10:53:29 +00:00
|
|
|
* @covers ContentHandler::getPageLanguage
|
2012-06-26 14:37:42 +00:00
|
|
|
*/
|
|
|
|
|
public function testGetPageLanguage( $title, $expected ) {
|
|
|
|
|
if ( is_string( $title ) ) {
|
|
|
|
|
$title = Title::newFromText( $title );
|
2018-06-11 06:55:11 +00:00
|
|
|
MediaWikiServices::getInstance()->getLinkCache()->addBadLinkObj( $title );
|
2012-06-26 14:37:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$expected = wfGetLangObj( $expected );
|
|
|
|
|
|
2021-05-28 20:22:01 +00:00
|
|
|
$handler = MediaWikiServices::getInstance()
|
|
|
|
|
->getContentHandlerFactory()
|
|
|
|
|
->getContentHandler( $title->getContentModel() );
|
2012-06-26 14:37:42 +00:00
|
|
|
$lang = $handler->getPageLanguage( $title );
|
|
|
|
|
|
2019-03-06 12:23:06 +00:00
|
|
|
$this->assertInstanceOf( Language::class, $lang );
|
2012-06-26 14:37:42 +00:00
|
|
|
$this->assertEquals( $expected->getCode(), $lang->getCode() );
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-22 14:16:35 +00:00
|
|
|
public static function dataGetContentText_Null() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[ 'fail' ],
|
|
|
|
|
[ 'serialize' ],
|
|
|
|
|
[ 'ignore' ],
|
|
|
|
|
];
|
2013-03-22 14:16:35 +00:00
|
|
|
}
|
2012-04-25 16:35:36 +00:00
|
|
|
|
2013-03-22 14:16:35 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider dataGetContentText_Null
|
2013-10-18 10:53:29 +00:00
|
|
|
* @covers ContentHandler::getContentText
|
2013-03-22 14:16:35 +00:00
|
|
|
*/
|
|
|
|
|
public function testGetContentText_Null( $contentHandlerTextFallback ) {
|
|
|
|
|
$this->setMwGlobals( 'wgContentHandlerTextFallback', $contentHandlerTextFallback );
|
2012-04-25 16:35:36 +00:00
|
|
|
|
2013-03-22 14:16:35 +00:00
|
|
|
$content = null;
|
2012-04-25 16:35:36 +00:00
|
|
|
|
|
|
|
|
$text = ContentHandler::getContentText( $content );
|
2019-09-17 14:28:35 +00:00
|
|
|
$this->assertSame( '', $text );
|
2013-03-22 14:16:35 +00:00
|
|
|
}
|
2012-04-25 16:35:36 +00:00
|
|
|
|
2013-03-22 14:16:35 +00:00
|
|
|
public static function dataGetContentText_TextContent() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[ 'fail' ],
|
|
|
|
|
[ 'serialize' ],
|
|
|
|
|
[ 'ignore' ],
|
|
|
|
|
];
|
2012-04-25 16:35:36 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-22 14:16:35 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider dataGetContentText_TextContent
|
2013-10-18 10:53:29 +00:00
|
|
|
* @covers ContentHandler::getContentText
|
2013-03-22 14:16:35 +00:00
|
|
|
*/
|
|
|
|
|
public function testGetContentText_TextContent( $contentHandlerTextFallback ) {
|
|
|
|
|
$this->setMwGlobals( 'wgContentHandlerTextFallback', $contentHandlerTextFallback );
|
2012-04-25 16:35:36 +00:00
|
|
|
|
|
|
|
|
$content = new WikitextContent( "hello world" );
|
|
|
|
|
|
|
|
|
|
$text = ContentHandler::getContentText( $content );
|
2018-11-08 15:19:23 +00:00
|
|
|
$this->assertEquals( $content->getText(), $text );
|
2012-04-25 16:35:36 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-22 14:16:35 +00:00
|
|
|
/**
|
|
|
|
|
* ContentHandler::getContentText should have thrown an exception for non-text Content object
|
2019-10-11 22:22:26 +00:00
|
|
|
*
|
2013-10-18 10:53:29 +00:00
|
|
|
* @covers ContentHandler::getContentText
|
2013-03-22 14:16:35 +00:00
|
|
|
*/
|
|
|
|
|
public function testGetContentText_NonTextContent_fail() {
|
|
|
|
|
$this->setMwGlobals( 'wgContentHandlerTextFallback', 'fail' );
|
2012-04-25 16:35:36 +00:00
|
|
|
|
|
|
|
|
$content = new DummyContentForTesting( "hello world" );
|
|
|
|
|
|
2019-10-11 22:22:26 +00:00
|
|
|
$this->expectException( MWException::class );
|
2013-03-22 14:16:35 +00:00
|
|
|
ContentHandler::getContentText( $content );
|
|
|
|
|
}
|
2012-04-25 16:35:36 +00:00
|
|
|
|
2013-10-18 10:53:29 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ContentHandler::getContentText
|
|
|
|
|
*/
|
2013-03-22 14:16:35 +00:00
|
|
|
public function testGetContentText_NonTextContent_serialize() {
|
|
|
|
|
$this->setMwGlobals( 'wgContentHandlerTextFallback', 'serialize' );
|
2012-04-25 16:35:36 +00:00
|
|
|
|
2013-03-22 14:16:35 +00:00
|
|
|
$content = new DummyContentForTesting( "hello world" );
|
2012-04-25 16:35:36 +00:00
|
|
|
|
|
|
|
|
$text = ContentHandler::getContentText( $content );
|
|
|
|
|
$this->assertEquals( $content->serialize(), $text );
|
2013-03-22 14:16:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-18 10:53:29 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ContentHandler::getContentText
|
|
|
|
|
*/
|
2013-03-22 14:16:35 +00:00
|
|
|
public function testGetContentText_NonTextContent_ignore() {
|
|
|
|
|
$this->setMwGlobals( 'wgContentHandlerTextFallback', 'ignore' );
|
|
|
|
|
|
|
|
|
|
$content = new DummyContentForTesting( "hello world" );
|
2012-04-25 16:35:36 +00:00
|
|
|
|
|
|
|
|
$text = ContentHandler::getContentText( $content );
|
|
|
|
|
$this->assertNull( $text );
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
public static function dataMakeContent() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2018-11-08 15:19:23 +00:00
|
|
|
[ 'hallo', 'Help:Test', null, null, CONTENT_MODEL_WIKITEXT, false ],
|
|
|
|
|
[ 'hallo', 'MediaWiki:Test.js', null, null, CONTENT_MODEL_JAVASCRIPT, false ],
|
2021-10-20 02:08:02 +00:00
|
|
|
[ 'hallo', 'Dummy:Test', null, null, "testing", false ],
|
2012-04-25 16:35:36 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2014-04-24 16:06:21 +00:00
|
|
|
'hallo',
|
|
|
|
|
'Help:Test',
|
|
|
|
|
null,
|
|
|
|
|
CONTENT_FORMAT_WIKITEXT,
|
|
|
|
|
CONTENT_MODEL_WIKITEXT,
|
|
|
|
|
false
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[
|
2014-04-24 16:06:21 +00:00
|
|
|
'hallo',
|
|
|
|
|
'MediaWiki:Test.js',
|
|
|
|
|
null,
|
|
|
|
|
CONTENT_FORMAT_JAVASCRIPT,
|
|
|
|
|
CONTENT_MODEL_JAVASCRIPT,
|
|
|
|
|
false
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2021-10-20 02:08:02 +00:00
|
|
|
[ 'hallo', 'Dummy:Test', null, "testing", "testing", false ],
|
2012-04-25 16:35:36 +00:00
|
|
|
|
2018-11-08 15:19:23 +00:00
|
|
|
[ 'hallo', 'Help:Test', CONTENT_MODEL_CSS, null, CONTENT_MODEL_CSS, false ],
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2014-04-24 16:06:21 +00:00
|
|
|
'hallo',
|
|
|
|
|
'MediaWiki:Test.js',
|
|
|
|
|
CONTENT_MODEL_CSS,
|
|
|
|
|
null,
|
|
|
|
|
CONTENT_MODEL_CSS,
|
|
|
|
|
false
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[
|
2014-04-24 16:06:21 +00:00
|
|
|
serialize( 'hallo' ),
|
|
|
|
|
'Dummy:Test',
|
|
|
|
|
CONTENT_MODEL_CSS,
|
|
|
|
|
null,
|
|
|
|
|
CONTENT_MODEL_CSS,
|
|
|
|
|
false
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2012-04-20 19:33:13 +00:00
|
|
|
|
2018-11-08 15:19:23 +00:00
|
|
|
[ 'hallo', 'Help:Test', CONTENT_MODEL_WIKITEXT, "testing", null, true ],
|
|
|
|
|
[ 'hallo', 'MediaWiki:Test.js', CONTENT_MODEL_CSS, "testing", null, true ],
|
|
|
|
|
[ 'hallo', 'Dummy:Test', CONTENT_MODEL_JAVASCRIPT, "testing", null, true ],
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2012-04-25 16:35:36 +00:00
|
|
|
}
|
2012-04-20 19:33:13 +00:00
|
|
|
|
2012-04-25 16:35:36 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider dataMakeContent
|
2013-10-18 10:53:29 +00:00
|
|
|
* @covers ContentHandler::makeContent
|
2012-04-25 16:35:36 +00:00
|
|
|
*/
|
2014-04-24 16:06:21 +00:00
|
|
|
public function testMakeContent( $data, $title, $modelId, $format,
|
2018-11-08 15:19:23 +00:00
|
|
|
$expectedModelId, $shouldFail
|
2014-04-24 16:06:21 +00:00
|
|
|
) {
|
2012-04-25 16:35:36 +00:00
|
|
|
$title = Title::newFromText( $title );
|
2018-06-11 06:55:11 +00:00
|
|
|
MediaWikiServices::getInstance()->getLinkCache()->addBadLinkObj( $title );
|
2012-04-25 16:35:36 +00:00
|
|
|
try {
|
2012-05-13 22:02:29 +00:00
|
|
|
$content = ContentHandler::makeContent( $data, $title, $modelId, $format );
|
2012-04-20 19:33:13 +00:00
|
|
|
|
2012-10-20 01:51:15 +00:00
|
|
|
if ( $shouldFail ) {
|
|
|
|
|
$this->fail( "ContentHandler::makeContent should have failed!" );
|
|
|
|
|
}
|
2012-04-20 19:33:13 +00:00
|
|
|
|
2012-05-13 22:02:29 +00:00
|
|
|
$this->assertEquals( $expectedModelId, $content->getModel(), 'bad model id' );
|
2018-11-08 15:19:23 +00:00
|
|
|
$this->assertEquals( $data, $content->serialize(), 'bad serialized data' );
|
2012-04-25 16:35:36 +00:00
|
|
|
} catch ( MWException $ex ) {
|
2013-02-14 13:10:38 +00:00
|
|
|
if ( !$shouldFail ) {
|
|
|
|
|
$this->fail( "ContentHandler::makeContent failed unexpectedly: " . $ex->getMessage() );
|
2013-03-25 23:27:14 +00:00
|
|
|
} else {
|
2013-02-14 13:10:38 +00:00
|
|
|
// dummy, so we don't get the "test did not perform any assertions" message.
|
|
|
|
|
$this->assertTrue( true );
|
|
|
|
|
}
|
2012-04-25 16:35:36 +00:00
|
|
|
}
|
|
|
|
|
}
|
2012-04-20 19:33:13 +00:00
|
|
|
|
2017-12-25 01:08:48 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ContentHandler::getAutosummary
|
|
|
|
|
*
|
2014-07-27 12:18:26 +00:00
|
|
|
* Test if we become a "Created blank page" summary from getAutoSummary if no Content added to
|
|
|
|
|
* page.
|
|
|
|
|
*/
|
|
|
|
|
public function testGetAutosummary() {
|
2018-07-25 14:57:23 +00:00
|
|
|
$this->setContentLang( 'en' );
|
2014-09-27 09:53:02 +00:00
|
|
|
|
2014-07-27 12:18:26 +00:00
|
|
|
$content = new DummyContentHandlerForTesting( CONTENT_MODEL_WIKITEXT );
|
|
|
|
|
$title = Title::newFromText( 'Help:Test' );
|
|
|
|
|
// Create a new content object with no content
|
2017-11-09 11:13:16 +00:00
|
|
|
$newContent = ContentHandler::makeContent( '', $title, CONTENT_MODEL_WIKITEXT, null );
|
2014-07-27 12:18:26 +00:00
|
|
|
// first check, if we become a blank page created summary with the right bitmask
|
|
|
|
|
$autoSummary = $content->getAutosummary( null, $newContent, 97 );
|
2017-11-09 11:13:16 +00:00
|
|
|
$this->assertEquals( $autoSummary,
|
|
|
|
|
wfMessage( 'autosumm-newblank' )->inContentLanguage()->text() );
|
2014-07-27 12:18:26 +00:00
|
|
|
// now check, what we become with another bitmask
|
|
|
|
|
$autoSummary = $content->getAutosummary( null, $newContent, 92 );
|
2021-01-30 12:51:38 +00:00
|
|
|
$this->assertSame( '', $autoSummary );
|
2014-07-27 12:18:26 +00:00
|
|
|
}
|
|
|
|
|
|
2017-11-09 11:13:16 +00:00
|
|
|
/**
|
|
|
|
|
* Test software tag that is added when content model of the page changes
|
|
|
|
|
* @covers ContentHandler::getChangeTag
|
|
|
|
|
*/
|
|
|
|
|
public function testGetChangeTag() {
|
|
|
|
|
$this->setMwGlobals( 'wgSoftwareTags', [ 'mw-contentmodelchange' => true ] );
|
|
|
|
|
$wikitextContentHandler = new DummyContentHandlerForTesting( CONTENT_MODEL_WIKITEXT );
|
|
|
|
|
// Create old content object with javascript content model
|
|
|
|
|
$oldContent = ContentHandler::makeContent( '', null, CONTENT_MODEL_JAVASCRIPT, null );
|
|
|
|
|
// Create new content object with wikitext content model
|
|
|
|
|
$newContent = ContentHandler::makeContent( '', null, CONTENT_MODEL_WIKITEXT, null );
|
|
|
|
|
// Get the tag for this edit
|
|
|
|
|
$tag = $wikitextContentHandler->getChangeTag( $oldContent, $newContent, EDIT_UPDATE );
|
2021-01-30 12:51:38 +00:00
|
|
|
$this->assertSame( 'mw-contentmodelchange', $tag );
|
2017-11-09 11:13:16 +00:00
|
|
|
}
|
|
|
|
|
|
2017-12-25 01:08:48 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ContentHandler::supportsCategories
|
|
|
|
|
*/
|
2016-02-15 15:19:58 +00:00
|
|
|
public function testSupportsCategories() {
|
|
|
|
|
$handler = new DummyContentHandlerForTesting( CONTENT_MODEL_WIKITEXT );
|
|
|
|
|
$this->assertTrue( $handler->supportsCategories(), 'content model supports categories' );
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-25 01:08:48 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ContentHandler::supportsDirectEditing
|
|
|
|
|
*/
|
2015-04-15 08:26:22 +00:00
|
|
|
public function testSupportsDirectEditing() {
|
|
|
|
|
$handler = new DummyContentHandlerForTesting( CONTENT_MODEL_JSON );
|
|
|
|
|
$this->assertFalse( $handler->supportsDirectEditing(), 'direct editing is not supported' );
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-20 17:28:20 +00:00
|
|
|
public static function dummyHookHandler( $foo, &$text, $bar ) {
|
|
|
|
|
if ( $text === null || $text === false ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$text = strtoupper( $text );
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2016-02-05 13:40:39 +00:00
|
|
|
|
|
|
|
|
public function provideGetModelForID() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2018-01-13 00:02:09 +00:00
|
|
|
[ CONTENT_MODEL_WIKITEXT, WikitextContentHandler::class ],
|
|
|
|
|
[ CONTENT_MODEL_JAVASCRIPT, JavaScriptContentHandler::class ],
|
|
|
|
|
[ CONTENT_MODEL_JSON, JsonContentHandler::class ],
|
|
|
|
|
[ CONTENT_MODEL_CSS, CssContentHandler::class ],
|
|
|
|
|
[ CONTENT_MODEL_TEXT, TextContentHandler::class ],
|
|
|
|
|
[ 'testing', DummyContentHandlerForTesting::class ],
|
|
|
|
|
[ 'testing-callbacks', DummyContentHandlerForTesting::class ],
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2016-02-05 13:40:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-12-25 01:08:48 +00:00
|
|
|
* @covers ContentHandler::getForModelID
|
2016-02-05 13:40:39 +00:00
|
|
|
* @dataProvider provideGetModelForID
|
|
|
|
|
*/
|
|
|
|
|
public function testGetModelForID( $modelId, $handlerClass ) {
|
|
|
|
|
$handler = ContentHandler::getForModelID( $modelId );
|
|
|
|
|
|
|
|
|
|
$this->assertInstanceOf( $handlerClass, $handler );
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-25 01:08:48 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ContentHandler::getFieldsForSearchIndex
|
|
|
|
|
*/
|
2016-08-09 17:22:09 +00:00
|
|
|
public function testGetFieldsForSearchIndex() {
|
|
|
|
|
$searchEngine = $this->newSearchEngine();
|
|
|
|
|
|
|
|
|
|
$handler = ContentHandler::getForModelID( CONTENT_MODEL_WIKITEXT );
|
|
|
|
|
|
|
|
|
|
$fields = $handler->getFieldsForSearchIndex( $searchEngine );
|
|
|
|
|
|
|
|
|
|
$this->assertArrayHasKey( 'category', $fields );
|
|
|
|
|
$this->assertArrayHasKey( 'external_link', $fields );
|
|
|
|
|
$this->assertArrayHasKey( 'outgoing_link', $fields );
|
|
|
|
|
$this->assertArrayHasKey( 'template', $fields );
|
2017-01-26 19:15:03 +00:00
|
|
|
$this->assertArrayHasKey( 'content_model', $fields );
|
2016-08-09 17:22:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function newSearchEngine() {
|
2018-01-13 00:02:09 +00:00
|
|
|
$searchEngine = $this->getMockBuilder( SearchEngine::class )
|
2016-08-09 17:22:09 +00:00
|
|
|
->getMock();
|
|
|
|
|
|
2021-04-22 08:40:46 +00:00
|
|
|
$searchEngine->method( 'makeSearchFieldMapping' )
|
2021-02-07 13:10:36 +00:00
|
|
|
->will( $this->returnCallback( static function ( $name, $type ) {
|
2016-08-09 17:22:09 +00:00
|
|
|
return new DummySearchIndexFieldDefinition( $name, $type );
|
|
|
|
|
} ) );
|
|
|
|
|
|
|
|
|
|
return $searchEngine;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-16 20:24:10 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ContentHandler::getDataForSearchIndex
|
|
|
|
|
*/
|
|
|
|
|
public function testDataIndexFields() {
|
2018-01-13 00:02:09 +00:00
|
|
|
$mockEngine = $this->createMock( SearchEngine::class );
|
2016-05-16 20:24:10 +00:00
|
|
|
$title = Title::newFromText( 'Not_Main_Page', NS_MAIN );
|
|
|
|
|
$page = new WikiPage( $title );
|
|
|
|
|
|
|
|
|
|
$this->setTemporaryHook( 'SearchDataForIndex',
|
2021-02-07 13:10:36 +00:00
|
|
|
static function (
|
2017-02-25 21:53:36 +00:00
|
|
|
&$fields,
|
|
|
|
|
ContentHandler $handler,
|
|
|
|
|
WikiPage $page,
|
|
|
|
|
ParserOutput $output,
|
|
|
|
|
SearchEngine $engine
|
|
|
|
|
) {
|
2016-05-16 20:24:10 +00:00
|
|
|
$fields['testDataField'] = 'test content';
|
|
|
|
|
} );
|
|
|
|
|
|
2021-10-14 14:01:58 +00:00
|
|
|
$contentRenderer = $this->getServiceContainer()->getContentRenderer();
|
|
|
|
|
$output = $contentRenderer->getParserOutput( $page->getContent(), $title );
|
2016-05-16 20:24:10 +00:00
|
|
|
$data = $page->getContentHandler()->getDataForSearchIndex( $page, $output, $mockEngine );
|
|
|
|
|
$this->assertArrayHasKey( 'text', $data );
|
|
|
|
|
$this->assertArrayHasKey( 'text_bytes', $data );
|
|
|
|
|
$this->assertArrayHasKey( 'language', $data );
|
|
|
|
|
$this->assertArrayHasKey( 'testDataField', $data );
|
|
|
|
|
$this->assertEquals( 'test content', $data['testDataField'] );
|
2017-01-26 19:15:03 +00:00
|
|
|
$this->assertEquals( 'wikitext', $data['content_model'] );
|
2016-05-16 20:24:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers ContentHandler::getParserOutputForIndexing
|
|
|
|
|
*/
|
|
|
|
|
public function testParserOutputForIndexing() {
|
|
|
|
|
$title = Title::newFromText( 'Smithee', NS_MAIN );
|
|
|
|
|
$page = new WikiPage( $title );
|
|
|
|
|
|
|
|
|
|
$out = $page->getContentHandler()->getParserOutputForIndexing( $page );
|
|
|
|
|
$this->assertInstanceOf( ParserOutput::class, $out );
|
2019-12-14 10:27:56 +00:00
|
|
|
$this->assertStringContainsString( 'one who smiths', $out->getRawText() );
|
2016-05-16 20:24:10 +00:00
|
|
|
}
|
|
|
|
|
|
2017-01-31 05:31:30 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ContentHandler::getContentModels
|
|
|
|
|
*/
|
|
|
|
|
public function testGetContentModelsHook() {
|
2021-02-07 13:10:36 +00:00
|
|
|
$this->setTemporaryHook( 'GetContentModels', static function ( &$models ) {
|
2017-01-31 05:31:30 +00:00
|
|
|
$models[] = 'Ferrari';
|
|
|
|
|
} );
|
|
|
|
|
$this->assertContains( 'Ferrari', ContentHandler::getContentModels() );
|
|
|
|
|
}
|
[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
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers ContentHandler::getSlotDiffRenderer
|
|
|
|
|
*/
|
|
|
|
|
public function testGetSlotDiffRenderer_default() {
|
|
|
|
|
$this->mergeMwGlobalArrayValue( 'wgHooks', [
|
|
|
|
|
'GetSlotDiffRenderer' => [],
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
// test default renderer
|
|
|
|
|
$contentHandler = new WikitextContentHandler( CONTENT_MODEL_WIKITEXT );
|
|
|
|
|
$slotDiffRenderer = $contentHandler->getSlotDiffRenderer( RequestContext::getMain() );
|
|
|
|
|
$this->assertInstanceOf( TextSlotDiffRenderer::class, $slotDiffRenderer );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers ContentHandler::getSlotDiffRenderer
|
|
|
|
|
*/
|
|
|
|
|
public function testGetSlotDiffRenderer_bc() {
|
|
|
|
|
$this->mergeMwGlobalArrayValue( 'wgHooks', [
|
|
|
|
|
'GetSlotDiffRenderer' => [],
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
// test B/C renderer
|
|
|
|
|
$customDifferenceEngine = $this->getMockBuilder( DifferenceEngine::class )
|
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMock();
|
|
|
|
|
// hack to track object identity across cloning
|
|
|
|
|
$customDifferenceEngine->objectId = 12345;
|
|
|
|
|
$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
|
|
|
$slotDiffRenderer = $customContentHandler->getSlotDiffRenderer( RequestContext::getMain() );
|
|
|
|
|
$this->assertInstanceOf( DifferenceEngineSlotDiffRenderer::class, $slotDiffRenderer );
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
$customDifferenceEngine->objectId,
|
|
|
|
|
TestingAccessWrapper::newFromObject( $slotDiffRenderer )->differenceEngine->objectId
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers ContentHandler::getSlotDiffRenderer
|
|
|
|
|
*/
|
|
|
|
|
public function testGetSlotDiffRenderer_nobc() {
|
|
|
|
|
$this->mergeMwGlobalArrayValue( 'wgHooks', [
|
|
|
|
|
'GetSlotDiffRenderer' => [],
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
// test that B/C renderer does not get used when getSlotDiffRendererInternal is overridden
|
|
|
|
|
$customDifferenceEngine = $this->getMockBuilder( DifferenceEngine::class )
|
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMock();
|
|
|
|
|
$customSlotDiffRenderer = $this->getMockBuilder( SlotDiffRenderer::class )
|
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMockForAbstractClass();
|
|
|
|
|
$customContentHandler2 = $this->getMockBuilder( ContentHandler::class )
|
|
|
|
|
->setConstructorArgs( [ 'bar', [] ] )
|
2021-03-20 15:18:58 +00:00
|
|
|
->onlyMethods( [ 'createDifferenceEngine', 'getSlotDiffRendererInternal' ] )
|
[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
|
|
|
$customContentHandler2->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 );
|
2021-04-22 08:40:46 +00:00
|
|
|
$customContentHandler2->method( 'getSlotDiffRendererInternal' )
|
[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( $customSlotDiffRenderer );
|
2019-02-02 13:39:58 +00:00
|
|
|
/** @var ContentHandler $customContentHandler2 */
|
[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 = $customContentHandler2->getSlotDiffRenderer( RequestContext::getMain() );
|
|
|
|
|
$this->assertSame( $customSlotDiffRenderer, $slotDiffRenderer );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers ContentHandler::getSlotDiffRenderer
|
|
|
|
|
*/
|
|
|
|
|
public function testGetSlotDiffRenderer_hook() {
|
|
|
|
|
$this->mergeMwGlobalArrayValue( 'wgHooks', [
|
|
|
|
|
'GetSlotDiffRenderer' => [],
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
// test that the hook handler takes precedence
|
|
|
|
|
$customDifferenceEngine = $this->getMockBuilder( DifferenceEngine::class )
|
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->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
|
|
|
|
|
|
|
|
$customSlotDiffRenderer = $this->getMockBuilder( SlotDiffRenderer::class )
|
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMockForAbstractClass();
|
|
|
|
|
$customContentHandler2 = $this->getMockBuilder( ContentHandler::class )
|
|
|
|
|
->setConstructorArgs( [ 'bar', [] ] )
|
2021-03-20 15:18:58 +00:00
|
|
|
->onlyMethods( [ 'createDifferenceEngine', 'getSlotDiffRendererInternal' ] )
|
[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
|
|
|
$customContentHandler2->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 );
|
2021-04-22 08:40:46 +00:00
|
|
|
$customContentHandler2->method( 'getSlotDiffRendererInternal' )
|
[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( $customSlotDiffRenderer );
|
2019-02-02 13:39:58 +00:00
|
|
|
/** @var ContentHandler $customContentHandler2 */
|
[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
|
|
|
|
|
|
|
|
$customSlotDiffRenderer2 = $this->getMockBuilder( SlotDiffRenderer::class )
|
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMockForAbstractClass();
|
|
|
|
|
$this->setTemporaryHook( 'GetSlotDiffRenderer',
|
2021-02-07 13:10:36 +00:00
|
|
|
static function ( $handler, &$slotDiffRenderer ) use ( $customSlotDiffRenderer2 ) {
|
[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 = $customSlotDiffRenderer2;
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
$slotDiffRenderer = $customContentHandler->getSlotDiffRenderer( RequestContext::getMain() );
|
|
|
|
|
$this->assertSame( $customSlotDiffRenderer2, $slotDiffRenderer );
|
|
|
|
|
$slotDiffRenderer = $customContentHandler2->getSlotDiffRenderer( RequestContext::getMain() );
|
|
|
|
|
$this->assertSame( $customSlotDiffRenderer2, $slotDiffRenderer );
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-25 09:37:37 +00:00
|
|
|
public function providerGetPageViewLanguage() {
|
|
|
|
|
yield [ NS_FILE, 'sr', 'sr-ec', 'sr-ec' ];
|
|
|
|
|
yield [ NS_FILE, 'sr', 'sr', 'sr' ];
|
|
|
|
|
yield [ NS_MEDIAWIKI, 'sr-ec', 'sr', 'sr-ec' ];
|
|
|
|
|
yield [ NS_MEDIAWIKI, 'sr', 'sr-ec', 'sr' ];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider providerGetPageViewLanguage
|
|
|
|
|
* @covers ContentHandler::getPageViewLanguage
|
|
|
|
|
*/
|
|
|
|
|
public function testGetPageViewLanguage( $namespace, $lang, $variant, $expected ) {
|
2021-03-09 17:28:59 +00:00
|
|
|
$contentHandler = $this->getMockBuilder( ContentHandler::class )
|
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMockForAbstractClass();
|
2020-03-25 09:37:37 +00:00
|
|
|
|
|
|
|
|
$title = Title::newFromText( "SimpleTitle", $namespace );
|
|
|
|
|
|
|
|
|
|
$this->setMwGlobals( [
|
|
|
|
|
'wgDefaultLanguageVariant' => $variant,
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$this->setUserLang( $lang );
|
|
|
|
|
$this->setContentLang( $lang );
|
|
|
|
|
|
|
|
|
|
$pageViewLanguage = $contentHandler->getPageViewLanguage( $title );
|
|
|
|
|
$this->assertEquals( $expected, $pageViewLanguage->getCode() );
|
|
|
|
|
}
|
2021-10-22 12:48:23 +00:00
|
|
|
|
|
|
|
|
public function provideValidateSave() {
|
|
|
|
|
yield 'wikitext' => [
|
|
|
|
|
new WikitextContent( 'hello world' ),
|
|
|
|
|
true
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
yield 'valid json' => [
|
|
|
|
|
new JsonContent( '{ "0": "bar" }' ),
|
|
|
|
|
true
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
yield 'invalid json' => [
|
|
|
|
|
new JsonContent( 'foo' ),
|
|
|
|
|
false
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideValidateSave
|
|
|
|
|
* @covers ContentHandler::validateSave
|
|
|
|
|
*/
|
|
|
|
|
public function testValidateSave( $content, $expectedResult ) {
|
|
|
|
|
$page = new PageIdentityValue( 0, 1, 'Foo', PageIdentity::LOCAL );
|
|
|
|
|
$contentHandlerFactory = MediaWikiServices::getInstance()->getContentHandlerFactory();
|
|
|
|
|
$contentHandler = $contentHandlerFactory->getContentHandler( $content->getModel() );
|
|
|
|
|
$validateParams = new ValidationParams( $page, 0 );
|
|
|
|
|
|
|
|
|
|
$status = $contentHandler->validateSave( $content, $validateParams );
|
|
|
|
|
$this->assertEquals( $status->isOk(), $expectedResult );
|
|
|
|
|
}
|
2012-04-20 19:33:13 +00:00
|
|
|
}
|