| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Revision; |
| 4 |
|
| 5 |
use MediaWiki\Page\PageIdentityValue; |
| 6 |
use MediaWiki\Revision\SlotRoleHandler; |
| 7 |
use MediaWiki\Title\Title; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
class SlotRoleHandlerTest extends \MediaWikiUnitTestCase { |
| 13 |
|
| 14 |
public function testConstruction() { |
| 15 |
$handler = new SlotRoleHandler( 'foo', 'FooModel', [ 'frob' => 'niz' ] ); |
| 16 |
$this->assertSame( 'foo', $handler->getRole() ); |
| 17 |
$this->assertSame( 'slot-name-foo', $handler->getNameMessageKey() ); |
| 18 |
|
| 19 |
$title = $this->createMock( Title::class ); |
| 20 |
$this->assertSame( 'FooModel', $handler->getDefaultModel( $title ) ); |
| 21 |
|
| 22 |
$hints = $handler->getOutputLayoutHints(); |
| 23 |
$this->assertArrayHasKey( 'frob', $hints ); |
| 24 |
$this->assertSame( 'niz', $hints['frob'] ); |
| 25 |
|
| 26 |
$this->assertArrayHasKey( 'display', $hints ); |
| 27 |
$this->assertArrayHasKey( 'region', $hints ); |
| 28 |
$this->assertArrayHasKey( 'placement', $hints ); |
| 29 |
} |
| 30 |
|
| 31 |
public function testDerived() { |
| 32 |
$handler = new SlotRoleHandler( 'foo', 'FooModel', [ 'frob' => 'niz' ] ); |
| 33 |
$this->assertFalse( $handler->isDerived() ); |
| 34 |
|
| 35 |
$handler = new SlotRoleHandler( 'foo', 'FooModel', [ 'frob' => 'niz' ], false ); |
| 36 |
$this->assertFalse( $handler->isDerived() ); |
| 37 |
|
| 38 |
$handler = new SlotRoleHandler( 'foo', 'FooModel', [ 'frob' => 'niz' ], true ); |
| 39 |
$this->assertTrue( $handler->isDerived() ); |
| 40 |
} |
| 41 |
|
| 42 |
public function testIsAllowedModel() { |
| 43 |
$handler = new SlotRoleHandler( 'foo', 'FooModel' ); |
| 44 |
$this->assertTrue( $handler->isAllowedModel( |
| 45 |
'FooModel', |
| 46 |
PageIdentityValue::localIdentity( 1, NS_MAIN, 'Test' ) |
| 47 |
) ); |
| 48 |
$this->assertFalse( $handler->isAllowedModel( |
| 49 |
'QuaxModel', |
| 50 |
PageIdentityValue::localIdentity( 1, NS_MAIN, 'Test' ) ) |
| 51 |
); |
| 52 |
} |
| 53 |
|
| 54 |
public function testSupportsArticleCount() { |
| 55 |
$handler = new SlotRoleHandler( 'foo', 'FooModel' ); |
| 56 |
|
| 57 |
$this->assertFalse( $handler->supportsArticleCount() ); |
| 58 |
} |
| 59 |
|
| 60 |
} |