Debian Codegraph @

tests/phpunit/unit/includes/content/FileContentHandlerTest.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Tests\Unit;
4
5 use MediaWiki\Content\FileContentHandler;
6 use MediaWiki\Languages\LanguageNameUtils;
7 use MediaWiki\Linker\LinkRenderer;
8 use MediaWiki\Parser\MagicWordFactory;
9 use MediaWiki\Parser\ParserFactory;
10 use MediaWiki\Parser\Parsoid\ParsoidParserFactory;
11 use MediaWiki\Title\TitleFactory;
12 use MediaWikiUnitTestCase;
13 use SearchEngine;
14 use SearchIndexField;
15 use SearchIndexFieldDefinition;
16 use Wikimedia\UUID\GlobalIdGenerator;
17
18 /**
19 * @group ContentHandler
20 *
21 * @covers \MediaWiki\Content\FileContentHandler
22 */
23 class FileContentHandlerTest extends MediaWikiUnitTestCase {
24 /**
25 * @var FileContentHandler
26 */
27 private $handler;
28
29 protected function setUp(): void {
30 parent::setUp();
31
32 $this->handler = new FileContentHandler(
33 CONTENT_MODEL_WIKITEXT,
34 $this->createMock( TitleFactory::class ),
35 $this->createMock( ParserFactory::class ),
36 $this->createMock( GlobalIdGenerator::class ),
37 $this->createMock( LanguageNameUtils::class ),
38 $this->createMock( LinkRenderer::class ),
39 $this->createMock( MagicWordFactory::class ),
40 $this->createMock( ParsoidParserFactory::class )
41 );
42 }
43
44 public function testIndexMapping() {
45 $mockEngine = $this->createMock( SearchEngine::class );
46
47 $mockEngine->expects( $this->atLeastOnce() )
48 ->method( 'makeSearchFieldMapping' )
49 ->willReturnCallback( function ( $name, $type ) {
50 $mockField =
51 $this->getMockBuilder( SearchIndexFieldDefinition::class )
52 ->onlyMethods( [ 'getMapping' ] )
53 ->setConstructorArgs( [ $name, $type ] )
54 ->getMock();
55 return $mockField;
56 } );
57
58 $map = $this->handler->getFieldsForSearchIndex( $mockEngine );
59 $expect = [
60 'file_media_type' => 1,
61 'file_mime' => 1,
62 'file_size' => 1,
63 'file_width' => 1,
64 'file_height' => 1,
65 'file_bits' => 1,
66 'file_resolution' => 1,
67 'file_text' => 1,
68 ];
69 foreach ( $map as $name => $field ) {
70 $this->assertInstanceOf( SearchIndexField::class, $field );
71 $this->assertEquals( $name, $field->getName() );
72 unset( $expect[$name] );
73 }
74 $this->assertSame( [], $expect );
75 }
76 }