"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tests/phpunit/includes/content/ContentHandlerTest.php" between
mediawiki-1.31.1.tar.gz and mediawiki-1.32.0.tar.gz

About: MediaWiki is a wiki engine (the collaborative editing software that runs for e.g. Wikipedia, the free encyclopedia).

ContentHandlerTest.php  (mediawiki-1.31.1):ContentHandlerTest.php  (mediawiki-1.32.0)
<?php <?php
use MediaWiki\MediaWikiServices; use MediaWiki\MediaWikiServices;
use Wikimedia\TestingAccessWrapper;
/** /**
* @group ContentHandler * @group ContentHandler
* @group Database * @group Database
*/ */
class ContentHandlerTest extends MediaWikiTestCase { class ContentHandlerTest extends MediaWikiTestCase {
protected function setUp() { protected function setUp() {
global $wgContLang;
parent::setUp(); parent::setUp();
$this->setMwGlobals( [ $this->setMwGlobals( [
'wgExtraNamespaces' => [ 'wgExtraNamespaces' => [
12312 => 'Dummy', 12312 => 'Dummy',
12313 => 'Dummy_talk', 12313 => 'Dummy_talk',
], ],
// The below tests assume that namespaces not mentioned h ere (Help, User, MediaWiki, ..) // The below tests assume that namespaces not mentioned h ere (Help, User, MediaWiki, ..)
// default to CONTENT_MODEL_WIKITEXT. // default to CONTENT_MODEL_WIKITEXT.
'wgNamespaceContentModels' => [ 'wgNamespaceContentModels' => [
skipping to change at line 37 skipping to change at line 37
CONTENT_MODEL_JSON => JsonContentHandler::class, CONTENT_MODEL_JSON => JsonContentHandler::class,
CONTENT_MODEL_CSS => CssContentHandler::class, CONTENT_MODEL_CSS => CssContentHandler::class,
CONTENT_MODEL_TEXT => TextContentHandler::class, CONTENT_MODEL_TEXT => TextContentHandler::class,
'testing' => DummyContentHandlerForTesting::class , 'testing' => DummyContentHandlerForTesting::class ,
'testing-callbacks' => function ( $modelId ) { 'testing-callbacks' => function ( $modelId ) {
return new DummyContentHandlerForTesting( $modelId ); return new DummyContentHandlerForTesting( $modelId );
} }
], ],
] ); ] );
// Reset namespace cache // Reset LinkCache
MWNamespace::clearCaches();
$wgContLang->resetNamespaces();
// And LinkCache
MediaWikiServices::getInstance()->resetServiceForTesting( 'LinkCa che' ); MediaWikiServices::getInstance()->resetServiceForTesting( 'LinkCa che' );
} }
protected function tearDown() { protected function tearDown() {
global $wgContLang; // Reset LinkCache
// Reset namespace cache
MWNamespace::clearCaches();
$wgContLang->resetNamespaces();
// And LinkCache
MediaWikiServices::getInstance()->resetServiceForTesting( 'LinkCa che' ); MediaWikiServices::getInstance()->resetServiceForTesting( 'LinkCa che' );
parent::tearDown(); parent::tearDown();
} }
public function addDBDataOnce() { public function addDBDataOnce() {
$this->insertPage( 'Not_Main_Page', 'This is not a main page' ); $this->insertPage( 'Not_Main_Page', 'This is not a main page' );
$this->insertPage( 'Smithee', 'A smithee is one who smiths. See a lso [[Alan Smithee]]' ); $this->insertPage( 'Smithee', 'A smithee is one who smiths. See a lso [[Alan Smithee]]' );
} }
skipping to change at line 104 skipping to change at line 96
$title = Title::newFromText( $title ); $title = Title::newFromText( $title );
$this->assertEquals( $expectedModelId, ContentHandler::getDefault ModelFor( $title ) ); $this->assertEquals( $expectedModelId, ContentHandler::getDefault ModelFor( $title ) );
} }
/** /**
* @dataProvider dataGetDefaultModelFor * @dataProvider dataGetDefaultModelFor
* @covers ContentHandler::getForTitle * @covers ContentHandler::getForTitle
*/ */
public function testGetForTitle( $title, $expectedContentModel ) { public function testGetForTitle( $title, $expectedContentModel ) {
$title = Title::newFromText( $title ); $title = Title::newFromText( $title );
LinkCache::singleton()->addBadLinkObj( $title ); MediaWikiServices::getInstance()->getLinkCache()->addBadLinkObj( $title );
$handler = ContentHandler::getForTitle( $title ); $handler = ContentHandler::getForTitle( $title );
$this->assertEquals( $expectedContentModel, $handler->getModelID( ) ); $this->assertEquals( $expectedContentModel, $handler->getModelID( ) );
} }
public static function dataGetLocalizedName() { public static function dataGetLocalizedName() {
return [ return [
[ null, null ], [ null, null ],
[ "xyzzy", null ], [ "xyzzy", null ],
// XXX: depends on content language // XXX: depends on content language
skipping to change at line 161 skipping to change at line 153
]; ];
} }
/** /**
* @dataProvider dataGetPageLanguage * @dataProvider dataGetPageLanguage
* @covers ContentHandler::getPageLanguage * @covers ContentHandler::getPageLanguage
*/ */
public function testGetPageLanguage( $title, $expected ) { public function testGetPageLanguage( $title, $expected ) {
if ( is_string( $title ) ) { if ( is_string( $title ) ) {
$title = Title::newFromText( $title ); $title = Title::newFromText( $title );
LinkCache::singleton()->addBadLinkObj( $title ); MediaWikiServices::getInstance()->getLinkCache()->addBadL inkObj( $title );
} }
$expected = wfGetLangObj( $expected ); $expected = wfGetLangObj( $expected );
$handler = ContentHandler::getForTitle( $title ); $handler = ContentHandler::getForTitle( $title );
$lang = $handler->getPageLanguage( $title ); $lang = $handler->getPageLanguage( $title );
$this->assertEquals( $expected->getCode(), $lang->getCode() ); $this->assertEquals( $expected->getCode(), $lang->getCode() );
} }
skipping to change at line 311 skipping to change at line 303
} }
/** /**
* @dataProvider dataMakeContent * @dataProvider dataMakeContent
* @covers ContentHandler::makeContent * @covers ContentHandler::makeContent
*/ */
public function testMakeContent( $data, $title, $modelId, $format, public function testMakeContent( $data, $title, $modelId, $format,
$expectedModelId, $expectedNativeData, $shouldFail $expectedModelId, $expectedNativeData, $shouldFail
) { ) {
$title = Title::newFromText( $title ); $title = Title::newFromText( $title );
LinkCache::singleton()->addBadLinkObj( $title ); MediaWikiServices::getInstance()->getLinkCache()->addBadLinkObj( $title );
try { try {
$content = ContentHandler::makeContent( $data, $title, $m odelId, $format ); $content = ContentHandler::makeContent( $data, $title, $m odelId, $format );
if ( $shouldFail ) { if ( $shouldFail ) {
$this->fail( "ContentHandler::makeContent should have failed!" ); $this->fail( "ContentHandler::makeContent should have failed!" );
} }
$this->assertEquals( $expectedModelId, $content->getModel (), 'bad model id' ); $this->assertEquals( $expectedModelId, $content->getModel (), 'bad model id' );
$this->assertEquals( $expectedNativeData, $content->getNa tiveData(), 'bads native data' ); $this->assertEquals( $expectedNativeData, $content->getNa tiveData(), 'bads native data' );
} catch ( MWException $ex ) { } catch ( MWException $ex ) {
skipping to change at line 338 skipping to change at line 330
} }
} }
/** /**
* @covers ContentHandler::getAutosummary * @covers ContentHandler::getAutosummary
* *
* Test if we become a "Created blank page" summary from getAutoSummary i f no Content added to * Test if we become a "Created blank page" summary from getAutoSummary i f no Content added to
* page. * page.
*/ */
public function testGetAutosummary() { public function testGetAutosummary() {
$this->setMwGlobals( 'wgContLang', Language::factory( 'en' ) ); $this->setContentLang( 'en' );
$content = new DummyContentHandlerForTesting( CONTENT_MODEL_WIKIT EXT ); $content = new DummyContentHandlerForTesting( CONTENT_MODEL_WIKIT EXT );
$title = Title::newFromText( 'Help:Test' ); $title = Title::newFromText( 'Help:Test' );
// Create a new content object with no content // Create a new content object with no content
$newContent = ContentHandler::makeContent( '', $title, CONTENT_MO DEL_WIKITEXT, null ); $newContent = ContentHandler::makeContent( '', $title, CONTENT_MO DEL_WIKITEXT, null );
// first check, if we become a blank page created summary with th e right bitmask // first check, if we become a blank page created summary with th e right bitmask
$autoSummary = $content->getAutosummary( null, $newContent, 97 ); $autoSummary = $content->getAutosummary( null, $newContent, 97 );
$this->assertEquals( $autoSummary, $this->assertEquals( $autoSummary,
wfMessage( 'autosumm-newblank' )->inContentLanguage()->te xt() ); wfMessage( 'autosumm-newblank' )->inContentLanguage()->te xt() );
// now check, what we become with another bitmask // now check, what we become with another bitmask
skipping to change at line 497 skipping to change at line 489
/** /**
* @covers ContentHandler::getContentModels * @covers ContentHandler::getContentModels
*/ */
public function testGetContentModelsHook() { public function testGetContentModelsHook() {
$this->setTemporaryHook( 'GetContentModels', function ( &$models ) { $this->setTemporaryHook( 'GetContentModels', function ( &$models ) {
$models[] = 'Ferrari'; $models[] = 'Ferrari';
} ); } );
$this->assertContains( 'Ferrari', ContentHandler::getContentModel s() ); $this->assertContains( 'Ferrari', ContentHandler::getContentModel s() );
} }
/**
* @covers ContentHandler::getSlotDiffRenderer
*/
public function testGetSlotDiffRenderer_default() {
$this->mergeMwGlobalArrayValue( 'wgHooks', [
'GetSlotDiffRenderer' => [],
] );
// test default renderer
$contentHandler = new WikitextContentHandler( CONTENT_MODEL_WIKIT
EXT );
$slotDiffRenderer = $contentHandler->getSlotDiffRenderer( Request
Context::getMain() );
$this->assertInstanceOf( TextSlotDiffRenderer::class, $slotDiffRe
nderer );
}
/**
* @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::cl
ass )
->setConstructorArgs( [ 'foo', [] ] )
->setMethods( [ 'createDifferenceEngine' ] )
->getMockForAbstractClass();
$customContentHandler->expects( $this->any() )
->method( 'createDifferenceEngine' )
->willReturn( $customDifferenceEngine );
/** @var $customContentHandler ContentHandler */
$slotDiffRenderer = $customContentHandler->getSlotDiffRenderer( R
equestContext::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 getSlotDiffRende
rerInternal is overridden
$customDifferenceEngine = $this->getMockBuilder( DifferenceEngine
::class )
->disableOriginalConstructor()
->getMock();
$customSlotDiffRenderer = $this->getMockBuilder( SlotDiffRenderer
::class )
->disableOriginalConstructor()
->getMockForAbstractClass();
$customContentHandler2 = $this->getMockBuilder( ContentHandler::c
lass )
->setConstructorArgs( [ 'bar', [] ] )
->setMethods( [ 'createDifferenceEngine', 'getSlotDiffRen
dererInternal' ] )
->getMockForAbstractClass();
$customContentHandler2->expects( $this->any() )
->method( 'createDifferenceEngine' )
->willReturn( $customDifferenceEngine );
$customContentHandler2->expects( $this->any() )
->method( 'getSlotDiffRendererInternal' )
->willReturn( $customSlotDiffRenderer );
/** @var $customContentHandler2 ContentHandler */
$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::cl
ass )
->setConstructorArgs( [ 'foo', [] ] )
->setMethods( [ 'createDifferenceEngine' ] )
->getMockForAbstractClass();
$customContentHandler->expects( $this->any() )
->method( 'createDifferenceEngine' )
->willReturn( $customDifferenceEngine );
/** @var $customContentHandler ContentHandler */
$customSlotDiffRenderer = $this->getMockBuilder( SlotDiffRenderer
::class )
->disableOriginalConstructor()
->getMockForAbstractClass();
$customContentHandler2 = $this->getMockBuilder( ContentHandler::c
lass )
->setConstructorArgs( [ 'bar', [] ] )
->setMethods( [ 'createDifferenceEngine', 'getSlotDiffRen
dererInternal' ] )
->getMockForAbstractClass();
$customContentHandler2->expects( $this->any() )
->method( 'createDifferenceEngine' )
->willReturn( $customDifferenceEngine );
$customContentHandler2->expects( $this->any() )
->method( 'getSlotDiffRendererInternal' )
->willReturn( $customSlotDiffRenderer );
/** @var $customContentHandler2 ContentHandler */
$customSlotDiffRenderer2 = $this->getMockBuilder( SlotDiffRendere
r::class )
->disableOriginalConstructor()
->getMockForAbstractClass();
$this->setTemporaryHook( 'GetSlotDiffRenderer',
function ( $handler, &$slotDiffRenderer ) use ( $customSl
otDiffRenderer2 ) {
$slotDiffRenderer = $customSlotDiffRenderer2;
} );
$slotDiffRenderer = $customContentHandler->getSlotDiffRenderer( R
equestContext::getMain() );
$this->assertSame( $customSlotDiffRenderer2, $slotDiffRenderer );
$slotDiffRenderer = $customContentHandler2->getSlotDiffRenderer(
RequestContext::getMain() );
$this->assertSame( $customSlotDiffRenderer2, $slotDiffRenderer );
}
} }
 End of changes. 9 change blocks. 
15 lines changed or deleted 155 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)