Merge "Added release notes for 'ContentHandler::runLegacyHooks' removal"
[mediawiki.git] / tests / phpunit / includes / content / TextContentHandlerTest.php
blob918815ca05e831ff050a56f37b70e3d662f8ba9c
1 <?php
3 /**
4 * @group ContentHandler
5 */
6 class TextContentHandlerTest extends MediaWikiLangTestCase {
7 public function testSupportsDirectEditing() {
8 $handler = new TextContentHandler();
9 $this->assertTrue( $handler->supportsDirectEditing(), 'direct editing is supported' );
12 /**
13 * @covers SearchEngine::makeSearchFieldMapping
14 * @covers ContentHandler::getFieldsForSearchIndex
16 public function testFieldsForIndex() {
17 $handler = new TextContentHandler();
19 $mockEngine = $this->getMock( 'SearchEngine' );
21 $mockEngine->expects( $this->atLeastOnce() )
22 ->method( 'makeSearchFieldMapping' )
23 ->willReturnCallback( function ( $name, $type ) {
24 $mockField =
25 $this->getMockBuilder( 'SearchIndexFieldDefinition' )
26 ->setConstructorArgs( [ $name, $type ] )
27 ->getMock();
28 $mockField->expects( $this->atLeastOnce() )->method( 'getMapping' )->willReturn( [
29 'testData' => 'test',
30 'name' => $name,
31 'type' => $type,
32 ] );
33 return $mockField;
34 } );
36 /**
37 * @var $mockEngine SearchEngine
39 $fields = $handler->getFieldsForSearchIndex( $mockEngine );
40 $mappedFields = [];
41 foreach ( $fields as $name => $field ) {
42 $this->assertInstanceOf( 'SearchIndexField', $field );
43 /**
44 * @var $field SearchIndexField
46 $mappedFields[$name] = $field->getMapping( $mockEngine );
48 $this->assertArrayHasKey( 'language', $mappedFields );
49 $this->assertEquals( 'test', $mappedFields['language']['testData'] );
50 $this->assertEquals( 'language', $mappedFields['language']['name'] );