Debian Codegraph @

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

raw symbols SCIP
1 <?php
2
3 use MediaWiki\Content\TextContentHandler;
4
5 /**
6 * @group ContentHandler
7 * @covers \MediaWiki\Content\TextContentHandler
8 * @covers \MediaWiki\Content\ContentHandler
9 */
10 class TextContentHandlerTest extends MediaWikiUnitTestCase {
11
12 public function testSupportsDirectEditing() {
13 $handler = new TextContentHandler();
14 $this->assertTrue( $handler->supportsDirectEditing(), 'direct editing is supported' );
15 }
16
17 /**
18 * @covers \SearchEngine
19 */
20 public function testFieldsForIndex() {
21 $handler = new TextContentHandler();
22
23 $mockEngine = $this->createMock( SearchEngine::class );
24
25 $mockEngine->expects( $this->atLeastOnce() )
26 ->method( 'makeSearchFieldMapping' )
27 ->willReturnCallback( function ( $name, $type ) {
28 $mockField =
29 $this->getMockBuilder( SearchIndexFieldDefinition::class )
30 ->setConstructorArgs( [ $name, $type ] )
31 ->getMock();
32 $mockField->expects( $this->atLeastOnce() )->method( 'getMapping' )->willReturn( [
33 'testData' => 'test',
34 'name' => $name,
35 'type' => $type,
36 ] );
37 return $mockField;
38 } );
39
40 /** @var SearchEngine $mockEngine */
41 $fields = $handler->getFieldsForSearchIndex( $mockEngine );
42 $mappedFields = [];
43 foreach ( $fields as $name => $field ) {
44 $this->assertInstanceOf( SearchIndexField::class, $field );
45 /** @var SearchIndexField $field */
46 $mappedFields[$name] = $field->getMapping( $mockEngine );
47 }
48 $this->assertArrayHasKey( 'language', $mappedFields );
49 $this->assertEquals( 'test', $mappedFields['language']['testData'] );
50 $this->assertEquals( 'language', $mappedFields['language']['name'] );
51 }
52 }