Merge "Add type hint for ParserOutput"
[lhc/web/wiklou.git] / tests / phpunit / includes / content / ContentHandlerTest.php
index 786788b..323a63d 100644 (file)
@@ -8,7 +8,6 @@ use MediaWiki\MediaWikiServices;
 class ContentHandlerTest extends MediaWikiTestCase {
 
        protected function setUp() {
-               global $wgContLang;
                parent::setUp();
 
                $this->setMwGlobals( [
@@ -22,32 +21,24 @@ class ContentHandlerTest extends MediaWikiTestCase {
                                12312 => 'testing',
                        ],
                        'wgContentHandlers' => [
-                               CONTENT_MODEL_WIKITEXT => 'WikitextContentHandler',
-                               CONTENT_MODEL_JAVASCRIPT => 'JavaScriptContentHandler',
-                               CONTENT_MODEL_JSON => 'JsonContentHandler',
-                               CONTENT_MODEL_CSS => 'CssContentHandler',
-                               CONTENT_MODEL_TEXT => 'TextContentHandler',
-                               'testing' => 'DummyContentHandlerForTesting',
+                               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' => function ( $modelId ) {
                                        return new DummyContentHandlerForTesting( $modelId );
                                }
                        ],
                ] );
 
-               // Reset namespace cache
-               MWNamespace::clearCaches();
-               $wgContLang->resetNamespaces();
-               // And LinkCache
+               // Reset LinkCache
                MediaWikiServices::getInstance()->resetServiceForTesting( 'LinkCache' );
        }
 
        protected function tearDown() {
-               global $wgContLang;
-
-               // Reset namespace cache
-               MWNamespace::clearCaches();
-               $wgContLang->resetNamespaces();
-               // And LinkCache
+               // Reset LinkCache
                MediaWikiServices::getInstance()->resetServiceForTesting( 'LinkCache' );
 
                parent::tearDown();
@@ -101,7 +92,7 @@ class ContentHandlerTest extends MediaWikiTestCase {
         */
        public function testGetForTitle( $title, $expectedContentModel ) {
                $title = Title::newFromText( $title );
-               LinkCache::singleton()->addBadLinkObj( $title );
+               MediaWikiServices::getInstance()->getLinkCache()->addBadLinkObj( $title );
                $handler = ContentHandler::getForTitle( $title );
                $this->assertEquals( $expectedContentModel, $handler->getModelID() );
        }
@@ -158,7 +149,7 @@ class ContentHandlerTest extends MediaWikiTestCase {
        public function testGetPageLanguage( $title, $expected ) {
                if ( is_string( $title ) ) {
                        $title = Title::newFromText( $title );
-                       LinkCache::singleton()->addBadLinkObj( $title );
+                       MediaWikiServices::getInstance()->getLinkCache()->addBadLinkObj( $title );
                }
 
                $expected = wfGetLangObj( $expected );
@@ -308,7 +299,7 @@ class ContentHandlerTest extends MediaWikiTestCase {
                $expectedModelId, $expectedNativeData, $shouldFail
        ) {
                $title = Title::newFromText( $title );
-               LinkCache::singleton()->addBadLinkObj( $title );
+               MediaWikiServices::getInstance()->getLinkCache()->addBadLinkObj( $title );
                try {
                        $content = ContentHandler::makeContent( $data, $title, $modelId, $format );
 
@@ -335,7 +326,7 @@ class ContentHandlerTest extends MediaWikiTestCase {
         * page.
         */
        public function testGetAutosummary() {
-               $this->setMwGlobals( 'wgContLang', Language::factory( 'en' ) );
+               $this->setContentLang( 'en' );
 
                $content = new DummyContentHandlerForTesting( CONTENT_MODEL_WIKITEXT );
                $title = Title::newFromText( 'Help:Test' );
@@ -394,13 +385,13 @@ class ContentHandlerTest extends MediaWikiTestCase {
 
        public function provideGetModelForID() {
                return [
-                       [ CONTENT_MODEL_WIKITEXT, 'WikitextContentHandler' ],
-                       [ CONTENT_MODEL_JAVASCRIPT, 'JavaScriptContentHandler' ],
-                       [ CONTENT_MODEL_JSON, 'JsonContentHandler' ],
-                       [ CONTENT_MODEL_CSS, 'CssContentHandler' ],
-                       [ CONTENT_MODEL_TEXT, 'TextContentHandler' ],
-                       [ 'testing', 'DummyContentHandlerForTesting' ],
-                       [ 'testing-callbacks', 'DummyContentHandlerForTesting' ],
+                       [ 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 ],
                ];
        }
 
@@ -432,7 +423,7 @@ class ContentHandlerTest extends MediaWikiTestCase {
        }
 
        private function newSearchEngine() {
-               $searchEngine = $this->getMockBuilder( 'SearchEngine' )
+               $searchEngine = $this->getMockBuilder( SearchEngine::class )
                        ->getMock();
 
                $searchEngine->expects( $this->any() )
@@ -448,7 +439,7 @@ class ContentHandlerTest extends MediaWikiTestCase {
         * @covers ContentHandler::getDataForSearchIndex
         */
        public function testDataIndexFields() {
-               $mockEngine = $this->createMock( 'SearchEngine' );
+               $mockEngine = $this->createMock( SearchEngine::class );
                $title = Title::newFromText( 'Not_Main_Page', NS_MAIN );
                $page = new WikiPage( $title );