createMock( ContentHandler::class ); $contentHandler->method( 'canBeUsedOn' )->willReturn( true ); $contentHandlerFactory = $this->getDummyContentHandlerFactory( [ CONTENT_MODEL_WIKITEXT => $contentHandler, CONTENT_MODEL_TEXT => $contentHandler, ] ); // TitleFactory that for these tests is only called with Title objects, so just // return them $titleFactory = $this->createMock( TitleFactory::class ); $titleFactory->method( 'newFromLinkTarget' ) ->with( $this->isInstanceOf( Title::class ) ) ->willReturnArgument( 0 ); $titleFactory->method( 'castFromPageIdentity' ) ->with( $this->isInstanceOf( Title::class ) ) ->willReturnArgument( 0 ); return new MainSlotRoleHandler( $namespaceContentModels, $contentHandlerFactory, $this->createHookContainer(), $titleFactory ); } /** * @covers \MediaWiki\Revision\MainSlotRoleHandler::__construct * @covers \MediaWiki\Revision\MainSlotRoleHandler::getRole() * @covers \MediaWiki\Revision\MainSlotRoleHandler::getNameMessageKey() * @covers \MediaWiki\Revision\MainSlotRoleHandler::getOutputLayoutHints() */ public function testConstruction() { $handler = $this->getRoleHandler( [] ); $this->assertSame( SlotRecord::MAIN, $handler->getRole() ); $this->assertSame( 'slot-name-main', $handler->getNameMessageKey() ); $hints = $handler->getOutputLayoutHints(); $this->assertArrayHasKey( 'display', $hints ); $this->assertArrayHasKey( 'region', $hints ); $this->assertArrayHasKey( 'placement', $hints ); } /** * @covers \MediaWiki\Revision\MainSlotRoleHandler::getDefaultModel() */ public function testGetDefaultModel() { $handler = $this->getRoleHandler( [ 100 => CONTENT_MODEL_TEXT ] ); // For the main handler, the namespace determins the default model $titleMain = $this->makeMockTitle( 'Article', [ 'namespace' => NS_MAIN ] ); $this->assertSame( CONTENT_MODEL_WIKITEXT, $handler->getDefaultModel( $titleMain ) ); $title100 = $this->makeMockTitle( 'Other page', [ 'namespace' => 100 ] ); $this->assertSame( CONTENT_MODEL_TEXT, $handler->getDefaultModel( $title100 ) ); } /** * @covers \MediaWiki\Revision\MainSlotRoleHandler::isAllowedModel() */ public function testIsAllowedModel() { $handler = $this->getRoleHandler( [] ); // For the main handler, (nearly) all models are allowed $title = $this->makeMockTitle( 'Article', [ 'namespace' => NS_MAIN ] ); $this->assertTrue( $handler->isAllowedModel( CONTENT_MODEL_WIKITEXT, $title ) ); $this->assertTrue( $handler->isAllowedModel( CONTENT_MODEL_TEXT, $title ) ); } /** * @covers \MediaWiki\Revision\MainSlotRoleHandler::supportsArticleCount() */ public function testSupportsArticleCount() { $handler = $this->getRoleHandler( [] ); $this->assertTrue( $handler->supportsArticleCount() ); } }