TextContentHandlerTest.php 1.6 KB

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