wiki.techinc.nl/tests/phpunit/includes/content/RegistrationContentHandlerFactoryToMediaWikiServicesTest.php
daniel 090ec5777d Use services in WikitextContentHandler
Change-Id: I626b5ee9a070ad3a97ab9ac9f44cb7003d68bf13
2022-12-06 15:44:40 -05:00

90 lines
2.3 KiB
PHP

<?php
use MediaWiki\MainConfigNames;
/**
* @group ContentHandlerFactory
*/
class RegistrationContentHandlerFactoryToMediaWikiServicesTest extends MediaWikiIntegrationTestCase {
protected function setUp(): void {
parent::setUp();
$this->overrideConfigValue(
MainConfigNames::ContentHandlers,
[
CONTENT_MODEL_WIKITEXT => [
'class' => WikitextContentHandler::class,
'services' => [
'TitleFactory',
'ParserFactory',
'GlobalIdGenerator',
'LanguageNameUtils',
'MagicWordFactory',
],
],
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' => static function ( $modelId ) {
return new DummyContentHandlerForTesting( $modelId );
},
]
);
}
/**
* @covers \MediaWiki\MediaWikiServices::getContentHandlerFactory
*/
public function testCallFromService_get_ok(): void {
$this->assertInstanceOf(
\MediaWiki\Content\IContentHandlerFactory::class,
$this->getServiceContainer()->getContentHandlerFactory()
);
$this->assertSame(
[
'wikitext',
'javascript',
'json',
'css',
'text',
'testing',
'testing-callbacks',
],
$this->getServiceContainer()->getContentHandlerFactory()->getContentModels()
);
}
/**
* @covers \MediaWiki\MediaWikiServices::getContentHandlerFactory
*/
public function testCallFromService_second_same(): void {
$this->assertSame(
$this->getServiceContainer()->getContentHandlerFactory(),
$this->getServiceContainer()->getContentHandlerFactory()
);
}
/**
* @covers \MediaWiki\MediaWikiServices::getContentHandlerFactory
*/
public function testCallFromService_afterCustomDefine_same(): void {
$factory = $this->getServiceContainer()->getContentHandlerFactory();
$factory->defineContentHandler(
'model name',
DummyContentHandlerForTesting::class
);
$this->assertTrue(
$this->getServiceContainer()
->getContentHandlerFactory()
->isDefinedModel( 'model name' )
);
$this->assertSame(
$factory,
$this->getServiceContainer()->getContentHandlerFactory()
);
}
}