Merge "registration: Only allow one extension to set a specific config setting"
[lhc/web/wiklou.git] / tests / phpunit / includes / content / ContentHandlerTest.php
index 39948ca..2422e79 100644 (file)
@@ -28,14 +28,14 @@ class ContentHandlerTest extends MediaWikiTestCase {
                                CONTENT_MODEL_CSS => 'CssContentHandler',
                                CONTENT_MODEL_TEXT => 'TextContentHandler',
                                'testing' => 'DummyContentHandlerForTesting',
-                               'testing-callbacks' => function( $modelId ) {
+                               'testing-callbacks' => function ( $modelId ) {
                                        return new DummyContentHandlerForTesting( $modelId );
                                }
                        ],
                ] );
 
                // Reset namespace cache
-               MWNamespace::getCanonicalNamespaces( true );
+               MWNamespace::clearCaches();
                $wgContLang->resetNamespaces();
                // And LinkCache
                MediaWikiServices::getInstance()->resetServiceForTesting( 'LinkCache' );
@@ -45,7 +45,7 @@ class ContentHandlerTest extends MediaWikiTestCase {
                global $wgContLang;
 
                // Reset namespace cache
-               MWNamespace::getCanonicalNamespaces( true );
+               MWNamespace::clearCaches();
                $wgContLang->resetNamespaces();
                // And LinkCache
                MediaWikiServices::getInstance()->resetServiceForTesting( 'LinkCache' );
@@ -367,22 +367,6 @@ class ContentHandlerTest extends MediaWikiTestCase {
                $this->assertFalse( $handler->supportsDirectEditing(), 'direct editing is not supported' );
        }
 
-       /**
-        * @covers ContentHandler::runLegacyHooks
-        */
-       public function testRunLegacyHooks() {
-               Hooks::register( 'testRunLegacyHooks', __CLASS__ . '::dummyHookHandler' );
-
-               $content = new WikitextContent( 'test text' );
-               $ok = ContentHandler::runLegacyHooks(
-                       'testRunLegacyHooks',
-                       [ 'foo', &$content, 'bar' ]
-               );
-
-               $this->assertTrue( $ok, "runLegacyHooks should have returned true" );
-               $this->assertEquals( "TEST TEXT", $content->getNativeData() );
-       }
-
        public static function dummyHookHandler( $foo, &$text, $bar ) {
                if ( $text === null || $text === false ) {
                        return false;
@@ -425,6 +409,7 @@ class ContentHandlerTest extends MediaWikiTestCase {
                $this->assertArrayHasKey( 'external_link', $fields );
                $this->assertArrayHasKey( 'outgoing_link', $fields );
                $this->assertArrayHasKey( 'template', $fields );
+               $this->assertArrayHasKey( 'content_model', $fields );
        }
 
        private function newSearchEngine() {
@@ -433,7 +418,7 @@ class ContentHandlerTest extends MediaWikiTestCase {
 
                $searchEngine->expects( $this->any() )
                        ->method( 'makeSearchFieldMapping' )
-                       ->will( $this->returnCallback( function( $name, $type ) {
+                       ->will( $this->returnCallback( function ( $name, $type ) {
                                        return new DummySearchIndexFieldDefinition( $name, $type );
                        } ) );
 
@@ -444,13 +429,18 @@ class ContentHandlerTest extends MediaWikiTestCase {
         * @covers ContentHandler::getDataForSearchIndex
         */
        public function testDataIndexFields() {
-               $mockEngine = $this->getMock( 'SearchEngine' );
+               $mockEngine = $this->createMock( 'SearchEngine' );
                $title = Title::newFromText( 'Not_Main_Page', NS_MAIN );
                $page = new WikiPage( $title );
 
                $this->setTemporaryHook( 'SearchDataForIndex',
-                       function ( &$fields, ContentHandler $handler, WikiPage $page, ParserOutput $output,
-                                          SearchEngine $engine ) {
+                       function (
+                               &$fields,
+                               ContentHandler $handler,
+                               WikiPage $page,
+                               ParserOutput $output,
+                               SearchEngine $engine
+                       ) {
                                $fields['testDataField'] = 'test content';
                        } );
 
@@ -461,6 +451,7 @@ class ContentHandlerTest extends MediaWikiTestCase {
                $this->assertArrayHasKey( 'language', $data );
                $this->assertArrayHasKey( 'testDataField', $data );
                $this->assertEquals( 'test content', $data['testDataField'] );
+               $this->assertEquals( 'wikitext', $data['content_model'] );
        }
 
        /**
@@ -475,4 +466,13 @@ class ContentHandlerTest extends MediaWikiTestCase {
                $this->assertContains( 'one who smiths', $out->getRawText() );
        }
 
+       /**
+        * @covers ContentHandler::getContentModels
+        */
+       public function testGetContentModelsHook() {
+               $this->setTemporaryHook( 'GetContentModels', function ( &$models ) {
+                       $models[] = 'Ferrari';
+               } );
+               $this->assertContains( 'Ferrari', ContentHandler::getContentModels() );
+       }
 }