Make content handlers assemble content for search
[lhc/web/wiklou.git] / tests / phpunit / includes / content / WikitextContentHandlerTest.php
index 38fb573..9d4abe8 100644 (file)
@@ -64,11 +64,11 @@ class WikitextContentHandlerTest extends MediaWikiLangTestCase {
        }
 
        public static function dataIsSupportedFormat() {
-               return array(
-                       array( null, true ),
-                       array( CONTENT_FORMAT_WIKITEXT, true ),
-                       array( 99887766, false ),
-               );
+               return [
+                       [ null, true ],
+                       [ CONTENT_FORMAT_WIKITEXT, true ],
+                       [ 99887766, false ],
+               ];
        }
 
        /**
@@ -91,20 +91,20 @@ class WikitextContentHandlerTest extends MediaWikiLangTestCase {
        }
 
        public static function provideMakeRedirectContent() {
-               return array(
-                       array( 'Hello', '#REDIRECT [[Hello]]' ),
-                       array( 'Template:Hello', '#REDIRECT [[Template:Hello]]' ),
-                       array( 'Hello#section', '#REDIRECT [[Hello#section]]' ),
-                       array( 'user:john_doe#section', '#REDIRECT [[User:John doe#section]]' ),
-                       array( 'MEDIAWIKI:FOOBAR', '#REDIRECT [[MediaWiki:FOOBAR]]' ),
-                       array( 'Category:Foo', '#REDIRECT [[:Category:Foo]]' ),
-                       array( Title::makeTitle( NS_MAIN, 'en:Foo' ), '#REDIRECT [[en:Foo]]' ),
-                       array( Title::makeTitle( NS_MAIN, 'Foo', '', 'en' ), '#REDIRECT [[:en:Foo]]' ),
-                       array(
+               return [
+                       [ 'Hello', '#REDIRECT [[Hello]]' ],
+                       [ 'Template:Hello', '#REDIRECT [[Template:Hello]]' ],
+                       [ 'Hello#section', '#REDIRECT [[Hello#section]]' ],
+                       [ 'user:john_doe#section', '#REDIRECT [[User:John doe#section]]' ],
+                       [ 'MEDIAWIKI:FOOBAR', '#REDIRECT [[MediaWiki:FOOBAR]]' ],
+                       [ 'Category:Foo', '#REDIRECT [[:Category:Foo]]' ],
+                       [ Title::makeTitle( NS_MAIN, 'en:Foo' ), '#REDIRECT [[en:Foo]]' ],
+                       [ Title::makeTitle( NS_MAIN, 'Foo', '', 'en' ), '#REDIRECT [[:en:Foo]]' ],
+                       [
                                Title::makeTitle( NS_MAIN, 'Bar', 'fragment', 'google' ),
                                '#REDIRECT [[google:Bar#fragment]]'
-                       ),
-               );
+                       ],
+               ];
        }
 
        /**
@@ -115,9 +115,14 @@ class WikitextContentHandlerTest extends MediaWikiLangTestCase {
                $this->assertEquals( $supported, $this->handler->isSupportedFormat( $format ) );
        }
 
+       public function testSupportsDirectEditing() {
+               $handler = new WikiTextContentHandler();
+               $this->assertTrue( $handler->supportsDirectEditing(), 'direct editing is supported' );
+       }
+
        public static function dataMerge3() {
-               return array(
-                       array(
+               return [
+                       [
                                "first paragraph
 
                                        second paragraph\n",
@@ -133,9 +138,9 @@ class WikitextContentHandlerTest extends MediaWikiLangTestCase {
                                "FIRST paragraph
 
                                        SECOND paragraph\n",
-                       ),
+                       ],
 
-                       array( "first paragraph
+                       [ "first paragraph
                                        second paragraph\n",
 
                                "Bla bla\n",
@@ -143,8 +148,8 @@ class WikitextContentHandlerTest extends MediaWikiLangTestCase {
                                "Blubberdibla\n",
 
                                false,
-                       ),
-               );
+                       ],
+               ];
        }
 
        /**
@@ -152,7 +157,7 @@ class WikitextContentHandlerTest extends MediaWikiLangTestCase {
         * @covers WikitextContentHandler::merge3
         */
        public function testMerge3( $old, $mine, $yours, $expected ) {
-               $this->checkHasDiff3();
+               $this->markTestSkippedIfNoDiff3();
 
                // test merge
                $oldContent = new WikitextContent( $old );
@@ -165,29 +170,29 @@ class WikitextContentHandlerTest extends MediaWikiLangTestCase {
        }
 
        public static function dataGetAutosummary() {
-               return array(
-                       array(
+               return [
+                       [
                                'Hello there, world!',
                                '#REDIRECT [[Foo]]',
                                0,
                                '/^Redirected page .*Foo/'
-                       ),
+                       ],
 
-                       array(
+                       [
                                null,
                                'Hello world!',
                                EDIT_NEW,
                                '/^Created page .*Hello/'
-                       ),
+                       ],
 
-                       array(
+                       [
                                'Hello there, world!',
                                '',
                                0,
                                '/^Blanked/'
-                       ),
+                       ],
 
-                       array(
+                       [
                                'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
                                eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
                                voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet
@@ -195,15 +200,15 @@ class WikitextContentHandlerTest extends MediaWikiLangTestCase {
                                'Hello world!',
                                0,
                                '/^Replaced .*Hello/'
-                       ),
+                       ],
 
-                       array(
+                       [
                                'foo',
                                'bar',
                                0,
                                '/^$/'
-                       ),
-               );
+                       ],
+               ];
        }
 
        /**
@@ -238,4 +243,20 @@ class WikitextContentHandlerTest extends MediaWikiLangTestCase {
        ) {
        }
        */
+
+       public function testDataIndexFieldsFile() {
+               $mockEngine = $this->getMock( 'SearchEngine' );
+               $title = Title::newFromText( 'Somefile.jpg', NS_FILE );
+               $page = new WikiPage( $title );
+
+               $handler = $this->getMockBuilder( WikitextContentHandler::class )
+                       ->disableOriginalConstructor()
+                       ->setMethods( [ 'getFileText' ] )
+                       ->getMock();
+               $handler->method( 'getFileText' )->will( $this->returnValue( 'This is file content' ) );
+
+               $data = $handler->getDataForSearchIndex( $page, new ParserOutput(), $mockEngine );
+               $this->assertArrayHasKey( 'file_text', $data );
+               $this->assertEquals( 'This is file content', $data['file_text'] );
+       }
 }