1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
<?php
use MediaWiki\Content\CssContentHandler;
use MediaWiki\Content\JavaScriptContentHandler;
use MediaWiki\Content\JsonContentHandler;
use MediaWiki\Content\TextContentHandler;
use MediaWiki\Content\WikitextContentHandler;
use MediaWiki\MainConfigNames;
/**
* @group ContentHandlerFactory
* @covers \MediaWiki\MediaWikiServices::getContentHandlerFactory
*/
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',
'LinkRenderer',
'MagicWordFactory',
'ParsoidParserFactory',
],
],
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 );
},
]
);
}
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()
);
}
public function testCallFromService_second_same(): void {
$this->assertSame(
$this->getServiceContainer()->getContentHandlerFactory(),
$this->getServiceContainer()->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()
);
}
}
|