]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - tests/phpunit/includes/content/FileContentHandlerTest.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / tests / phpunit / includes / content / FileContentHandlerTest.php
diff --git a/tests/phpunit/includes/content/FileContentHandlerTest.php b/tests/phpunit/includes/content/FileContentHandlerTest.php
new file mode 100644 (file)
index 0000000..65efcc9
--- /dev/null
@@ -0,0 +1,50 @@
+<?php
+
+/**
+ * @group ContentHandler
+ */
+class FileContentHandlerTest extends MediaWikiLangTestCase {
+       /**
+        * @var FileContentHandler
+        */
+       private $handler;
+
+       protected function setUp() {
+               parent::setUp();
+
+               $this->handler = new FileContentHandler();
+       }
+
+       public function testIndexMapping() {
+               $mockEngine = $this->createMock( 'SearchEngine' );
+
+               $mockEngine->expects( $this->atLeastOnce() )
+                       ->method( 'makeSearchFieldMapping' )
+                       ->willReturnCallback( function ( $name, $type ) {
+                               $mockField =
+                                       $this->getMockBuilder( 'SearchIndexFieldDefinition' )
+                                               ->setMethods( [ 'getMapping' ] )
+                                               ->setConstructorArgs( [ $name, $type ] )
+                                               ->getMock();
+                               return $mockField;
+                       } );
+
+               $map = $this->handler->getFieldsForSearchIndex( $mockEngine );
+               $expect = [
+                       'file_media_type' => 1,
+                       'file_mime' => 1,
+                       'file_size' => 1,
+                       'file_width' => 1,
+                       'file_height' => 1,
+                       'file_bits' => 1,
+                       'file_resolution' => 1,
+                       'file_text' => 1,
+               ];
+               foreach ( $map as $name => $field ) {
+                       $this->assertInstanceOf( 'SearchIndexField', $field );
+                       $this->assertEquals( $name, $field->getName() );
+                       unset( $expect[$name] );
+               }
+               $this->assertEmpty( $expect );
+       }
+}