summaryrefslogtreecommitdiff
path: root/www/wiki/tests/phpunit/includes/content/TextContentHandlerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/tests/phpunit/includes/content/TextContentHandlerTest.php')
-rw-r--r--www/wiki/tests/phpunit/includes/content/TextContentHandlerTest.php55
1 files changed, 55 insertions, 0 deletions
diff --git a/www/wiki/tests/phpunit/includes/content/TextContentHandlerTest.php b/www/wiki/tests/phpunit/includes/content/TextContentHandlerTest.php
new file mode 100644
index 00000000..6d0a3d5c
--- /dev/null
+++ b/www/wiki/tests/phpunit/includes/content/TextContentHandlerTest.php
@@ -0,0 +1,55 @@
+<?php
+
+/**
+ * @group ContentHandler
+ */
+class TextContentHandlerTest extends MediaWikiLangTestCase {
+ /**
+ * @covers TextContentHandler::supportsDirectEditing
+ */
+ public function testSupportsDirectEditing() {
+ $handler = new TextContentHandler();
+ $this->assertTrue( $handler->supportsDirectEditing(), 'direct editing is supported' );
+ }
+
+ /**
+ * @covers SearchEngine::makeSearchFieldMapping
+ * @covers ContentHandler::getFieldsForSearchIndex
+ */
+ public function testFieldsForIndex() {
+ $handler = new TextContentHandler();
+
+ $mockEngine = $this->createMock( SearchEngine::class );
+
+ $mockEngine->expects( $this->atLeastOnce() )
+ ->method( 'makeSearchFieldMapping' )
+ ->willReturnCallback( function ( $name, $type ) {
+ $mockField =
+ $this->getMockBuilder( SearchIndexFieldDefinition::class )
+ ->setConstructorArgs( [ $name, $type ] )
+ ->getMock();
+ $mockField->expects( $this->atLeastOnce() )->method( 'getMapping' )->willReturn( [
+ 'testData' => 'test',
+ 'name' => $name,
+ 'type' => $type,
+ ] );
+ return $mockField;
+ } );
+
+ /**
+ * @var $mockEngine SearchEngine
+ */
+ $fields = $handler->getFieldsForSearchIndex( $mockEngine );
+ $mappedFields = [];
+ foreach ( $fields as $name => $field ) {
+ $this->assertInstanceOf( SearchIndexField::class, $field );
+ /**
+ * @var $field SearchIndexField
+ */
+ $mappedFields[$name] = $field->getMapping( $mockEngine );
+ }
+ $this->assertArrayHasKey( 'language', $mappedFields );
+ $this->assertEquals( 'test', $mappedFields['language']['testData'] );
+ $this->assertEquals( 'language', $mappedFields['language']['name'] );
+ }
+}