| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Content\CssContentHandler; |
| 4 |
use MediaWiki\Content\JavaScriptContentHandler; |
| 5 |
use MediaWiki\Content\JsonContentHandler; |
| 6 |
use MediaWiki\Content\TextContentHandler; |
| 7 |
use MediaWiki\Content\WikitextContentHandler; |
| 8 |
use MediaWiki\MainConfigNames; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
class RegistrationContentHandlerFactoryToMediaWikiServicesTest extends MediaWikiIntegrationTestCase { |
| 15 |
|
| 16 |
protected function setUp(): void { |
| 17 |
parent::setUp(); |
| 18 |
|
| 19 |
$this->overrideConfigValue( |
| 20 |
MainConfigNames::ContentHandlers, |
| 21 |
[ |
| 22 |
CONTENT_MODEL_WIKITEXT => [ |
| 23 |
'class' => WikitextContentHandler::class, |
| 24 |
'services' => [ |
| 25 |
'TitleFactory', |
| 26 |
'ParserFactory', |
| 27 |
'GlobalIdGenerator', |
| 28 |
'LanguageNameUtils', |
| 29 |
'LinkRenderer', |
| 30 |
'MagicWordFactory', |
| 31 |
'ParsoidParserFactory', |
| 32 |
], |
| 33 |
], |
| 34 |
CONTENT_MODEL_JAVASCRIPT => JavaScriptContentHandler::class, |
| 35 |
CONTENT_MODEL_JSON => JsonContentHandler::class, |
| 36 |
CONTENT_MODEL_CSS => CssContentHandler::class, |
| 37 |
CONTENT_MODEL_TEXT => TextContentHandler::class, |
| 38 |
'testing' => DummyContentHandlerForTesting::class, |
| 39 |
'testing-callbacks' => static function ( $modelId ) { |
| 40 |
return new DummyContentHandlerForTesting( $modelId ); |
| 41 |
}, |
| 42 |
] |
| 43 |
); |
| 44 |
} |
| 45 |
|
| 46 |
public function testCallFromService_get_ok(): void { |
| 47 |
$this->assertInstanceOf( |
| 48 |
\MediaWiki\Content\IContentHandlerFactory::class, |
| 49 |
$this->getServiceContainer()->getContentHandlerFactory() |
| 50 |
); |
| 51 |
|
| 52 |
$this->assertSame( |
| 53 |
[ |
| 54 |
'wikitext', |
| 55 |
'javascript', |
| 56 |
'json', |
| 57 |
'css', |
| 58 |
'text', |
| 59 |
'testing', |
| 60 |
'testing-callbacks', |
| 61 |
], |
| 62 |
$this->getServiceContainer()->getContentHandlerFactory()->getContentModels() |
| 63 |
); |
| 64 |
} |
| 65 |
|
| 66 |
public function testCallFromService_second_same(): void { |
| 67 |
$this->assertSame( |
| 68 |
$this->getServiceContainer()->getContentHandlerFactory(), |
| 69 |
$this->getServiceContainer()->getContentHandlerFactory() |
| 70 |
); |
| 71 |
} |
| 72 |
|
| 73 |
public function testCallFromService_afterCustomDefine_same(): void { |
| 74 |
$factory = $this->getServiceContainer()->getContentHandlerFactory(); |
| 75 |
$factory->defineContentHandler( |
| 76 |
'model name', |
| 77 |
DummyContentHandlerForTesting::class |
| 78 |
); |
| 79 |
$this->assertTrue( |
| 80 |
$this->getServiceContainer() |
| 81 |
->getContentHandlerFactory() |
| 82 |
->isDefinedModel( 'model name' ) |
| 83 |
); |
| 84 |
$this->assertSame( |
| 85 |
$factory, |
| 86 |
$this->getServiceContainer()->getContentHandlerFactory() |
| 87 |
); |
| 88 |
} |
| 89 |
} |