diff options
6 files changed, 48 insertions, 9 deletions
diff --git a/tests/phpunit/includes/content/ContentHandlerTest.php b/tests/phpunit/includes/content/ContentHandlerTest.php index 26ca5325d570..40f59874e1cd 100644 --- a/tests/phpunit/includes/content/ContentHandlerTest.php +++ b/tests/phpunit/includes/content/ContentHandlerTest.php @@ -98,6 +98,7 @@ class ContentHandlerTest extends MediaWikiIntegrationTestCase { */ public function testGetDefaultModelFor( $title, $expectedModelId ) { $title = Title::newFromText( $title ); + $this->hideDeprecated( 'ContentHandler::getDefaultModelFor' ); $this->assertEquals( $expectedModelId, ContentHandler::getDefaultModelFor( $title ) ); } @@ -350,7 +351,8 @@ class ContentHandlerTest extends MediaWikiIntegrationTestCase { * @dataProvider provideGetModelForID */ public function testGetModelForID( $modelId, $handlerClass ) { - $handler = ContentHandler::getForModelID( $modelId ); + $handler = $this->getServiceContainer()->getContentHandlerFactory() + ->getContentHandler( $modelId ); $this->assertInstanceOf( $handlerClass, $handler ); } @@ -361,7 +363,12 @@ class ContentHandlerTest extends MediaWikiIntegrationTestCase { public function testGetFieldsForSearchIndex() { $searchEngine = $this->newSearchEngine(); - $handler = ContentHandler::getForModelID( CONTENT_MODEL_WIKITEXT ); + $handler = $this->getMockBuilder( ContentHandler::class ) + ->onlyMethods( + [ 'serializeContent', 'unserializeContent', 'makeEmptyContent' ] + ) + ->disableOriginalConstructor() + ->getMock(); $fields = $handler->getFieldsForSearchIndex( $searchEngine ); diff --git a/tests/phpunit/includes/content/ContentModelChangeTest.php b/tests/phpunit/includes/content/ContentModelChangeTest.php index e6f643db06de..c05ddc08a4ba 100644 --- a/tests/phpunit/includes/content/ContentModelChangeTest.php +++ b/tests/phpunit/includes/content/ContentModelChangeTest.php @@ -194,7 +194,11 @@ class ContentModelChangeTest extends MediaWikiIntegrationTestCase { $title = Title::newFromText( 'Dummy:NoDirectEditing' ); $wikipage = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title ); - $dummyContent = ContentHandler::getForModelID( 'testing' )->makeEmptyContent(); + $dummyContent = $this->getServiceContainer() + ->getContentHandlerFactory() + ->getContentHandler( 'testing' ) + ->makeEmptyContent(); + $wikipage->doUserEditContent( $dummyContent, $this->getTestSysop()->getUser(), diff --git a/tests/phpunit/includes/content/WikitextContentHandlerTest.php b/tests/phpunit/includes/content/WikitextContentHandlerTest.php index b14f6c9ab8f7..e52288a23719 100644 --- a/tests/phpunit/includes/content/WikitextContentHandlerTest.php +++ b/tests/phpunit/includes/content/WikitextContentHandlerTest.php @@ -238,6 +238,29 @@ class WikitextContentHandlerTest extends MediaWikiLangTestCase { /** * @covers \WikitextContentHandler::getDataForSearchIndex + * @covers \ContentHandler::getFieldsForSearchIndex + */ + public function testGetFieldsForSearchIndex() { + $searchEngine = $this->createMock( SearchEngine::class ); + + $searchEngine->method( 'makeSearchFieldMapping' ) + ->willReturnCallback( static function ( $name, $type ) { + return new DummySearchIndexFieldDefinition( $name, $type ); + } ); + + $this->hideDeprecated( 'ContentHandler::getForModelID' ); + + $fields = $this->handler->getFieldsForSearchIndex( $searchEngine ); + + $this->assertArrayHasKey( 'category', $fields ); + $this->assertArrayHasKey( 'external_link', $fields ); + $this->assertArrayHasKey( 'outgoing_link', $fields ); + $this->assertArrayHasKey( 'template', $fields ); + $this->assertArrayHasKey( 'content_model', $fields ); + } + + /** + * @covers WikitextContentHandler::getDataForSearchIndex */ public function testDataIndexFieldsFile() { $mockEngine = $this->createMock( SearchEngine::class ); diff --git a/tests/phpunit/includes/page/WikiPageDbTest.php b/tests/phpunit/includes/page/WikiPageDbTest.php index f234fdb42263..39d9800aff1d 100644 --- a/tests/phpunit/includes/page/WikiPageDbTest.php +++ b/tests/phpunit/includes/page/WikiPageDbTest.php @@ -192,9 +192,11 @@ class WikiPageDbTest extends MediaWikiLangTestCase { $comment = CommentStoreComment::newUnsavedComment( __METHOD__ ); - $contentHandler = ContentHandler::getForModelID( CONTENT_MODEL_WIKITEXT ); // PST turns [[|foo]] into [[foo]] - $content = $contentHandler->unserializeContent( __METHOD__ . ' [[|foo]][[bar]]' ); + $content = $this->getServiceContainer() + ->getContentHandlerFactory() + ->getContentHandler( CONTENT_MODEL_WIKITEXT ) + ->unserializeContent( __METHOD__ . ' [[|foo]][[bar]]' ); $revRecord = new MutableRevisionRecord( $page->getTitle() ); $revRecord->setContent( SlotRecord::MAIN, $content ); diff --git a/tests/phpunit/maintenance/DumpTestCase.php b/tests/phpunit/maintenance/DumpTestCase.php index ffcd835c867c..a23ffa78a495 100644 --- a/tests/phpunit/maintenance/DumpTestCase.php +++ b/tests/phpunit/maintenance/DumpTestCase.php @@ -3,7 +3,6 @@ namespace MediaWiki\Tests\Maintenance; use Content; -use ContentHandler; use DOMDocument; use ExecutableFinder; use MediaWiki\CommentStore\CommentStoreComment; @@ -69,7 +68,9 @@ abstract class DumpTestCase extends MediaWikiLangTestCase { $summary, $model = CONTENT_MODEL_WIKITEXT ) { - $contentHandler = ContentHandler::getForModelID( $model ); + $contentHandler = $this->getServiceContainer() + ->getContentHandlerFactory()->getContentHandler( $model ); + $content = $contentHandler->unserializeContent( $text ); $rev = $this->addMultiSlotRevision( $page, [ SlotRecord::MAIN => $content ], $summary ); @@ -110,7 +111,9 @@ abstract class DumpTestCase extends MediaWikiLangTestCase { * @return string */ protected function getSlotFormat( SlotRecord $slot ) { - $contentHandler = ContentHandler::getForModelID( $slot->getModel() ); + $contentHandler = $this->getServiceContainer() + ->getContentHandlerFactory()->getContentHandler( $slot->getModel() ); + return $contentHandler->getDefaultFormat(); } diff --git a/tests/phpunit/maintenance/PageDumpTestDataTrait.php b/tests/phpunit/maintenance/PageDumpTestDataTrait.php index 0e8275f5eb3b..a9fa28c6bf68 100644 --- a/tests/phpunit/maintenance/PageDumpTestDataTrait.php +++ b/tests/phpunit/maintenance/PageDumpTestDataTrait.php @@ -147,8 +147,8 @@ trait PageDumpTestDataTrait { // class), we have to assert, that the page id are consecutively // increasing $this->assertEquals( - [ $this->pageId2, $this->pageId3, $this->pageId4 ], [ $this->pageId1 + 1, $this->pageId1 + 2, $this->pageId1 + 3 ], + [ $this->pageId2, $this->pageId3, $this->pageId4 ], "Page ids increasing without holes" ); } |