These new classes provide a mechanism for defining the behavior of slots, like the content models it supports. This acts as an extension point for extensions that need to define custom slots, like the MediaInfo extension for the SDC project. Bug: T194046 Change-Id: Ia20c98eee819293199e541be75b5521f6413bc2f
79 lines
2.4 KiB
PHP
79 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Tests\Revision;
|
|
|
|
use MediaWiki\Revision\MainSlotRoleHandler;
|
|
use MediaWikiTestCase;
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
|
use Title;
|
|
|
|
/**
|
|
* @covers \MediaWiki\Revision\MainSlotRoleHandler
|
|
*/
|
|
class MainSlotRoleHandlerTest extends MediaWikiTestCase {
|
|
|
|
private function makeTitleObject( $ns ) {
|
|
/** @var Title|MockObject $title */
|
|
$title = $this->getMockBuilder( Title::class )
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
$title->method( 'getNamespace' )
|
|
->willReturn( $ns );
|
|
|
|
return $title;
|
|
}
|
|
|
|
/**
|
|
* @covers \MediaWiki\Revision\MainSlotRoleHandler::__construct
|
|
* @covers \MediaWiki\Revision\MainSlotRoleHandler::getRole()
|
|
* @covers \MediaWiki\Revision\MainSlotRoleHandler::getNameMessageKey()
|
|
* @covers \MediaWiki\Revision\MainSlotRoleHandler::getOutputLayoutHints()
|
|
*/
|
|
public function testConstruction() {
|
|
$handler = new MainSlotRoleHandler( [] );
|
|
$this->assertSame( '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 testFetDefaultModel() {
|
|
$handler = new MainSlotRoleHandler( [ 100 => CONTENT_MODEL_TEXT ] );
|
|
|
|
// For the main handler, the namespace determins the defualt model
|
|
$titleMain = $this->makeTitleObject( NS_MAIN );
|
|
$this->assertSame( CONTENT_MODEL_WIKITEXT, $handler->getDefaultModel( $titleMain ) );
|
|
|
|
$title100 = $this->makeTitleObject( 100 );
|
|
$this->assertSame( CONTENT_MODEL_TEXT, $handler->getDefaultModel( $title100 ) );
|
|
}
|
|
|
|
/**
|
|
* @covers \MediaWiki\Revision\MainSlotRoleHandler::isAllowedModel()
|
|
*/
|
|
public function testIsAllowedModel() {
|
|
$handler = new MainSlotRoleHandler( [] );
|
|
|
|
// For the main handler, (nearly) all models are allowed
|
|
$title = $this->makeTitleObject( 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 = new MainSlotRoleHandler( [] );
|
|
|
|
$this->assertTrue( $handler->supportsArticleCount() );
|
|
}
|
|
|
|
}
|