MediaWiki  1.33.1
MainSlotRoleHandlerTest.php
Go to the documentation of this file.
1 <?php
2 
4 
7 use PHPUnit\Framework\MockObject\MockObject;
8 use Title;
9 
14 
15  private function makeTitleObject( $ns ) {
17  $title = $this->getMockBuilder( Title::class )
18  ->disableOriginalConstructor()
19  ->getMock();
20 
21  $title->method( 'getNamespace' )
22  ->willReturn( $ns );
23 
24  return $title;
25  }
26 
33  public function testConstruction() {
34  $handler = new MainSlotRoleHandler( [] );
35  $this->assertSame( 'main', $handler->getRole() );
36  $this->assertSame( 'slot-name-main', $handler->getNameMessageKey() );
37 
38  $hints = $handler->getOutputLayoutHints();
39  $this->assertArrayHasKey( 'display', $hints );
40  $this->assertArrayHasKey( 'region', $hints );
41  $this->assertArrayHasKey( 'placement', $hints );
42  }
43 
47  public function testFetDefaultModel() {
49 
50  // For the main handler, the namespace determins the default model
51  $titleMain = $this->makeTitleObject( NS_MAIN );
52  $this->assertSame( CONTENT_MODEL_WIKITEXT, $handler->getDefaultModel( $titleMain ) );
53 
54  $title100 = $this->makeTitleObject( 100 );
55  $this->assertSame( CONTENT_MODEL_TEXT, $handler->getDefaultModel( $title100 ) );
56  }
57 
61  public function testIsAllowedModel() {
62  $handler = new MainSlotRoleHandler( [] );
63 
64  // For the main handler, (nearly) all models are allowed
65  $title = $this->makeTitleObject( NS_MAIN );
66  $this->assertTrue( $handler->isAllowedModel( CONTENT_MODEL_WIKITEXT, $title ) );
67  $this->assertTrue( $handler->isAllowedModel( CONTENT_MODEL_TEXT, $title ) );
68  }
69 
73  public function testSupportsArticleCount() {
74  $handler = new MainSlotRoleHandler( [] );
75 
76  $this->assertTrue( $handler->supportsArticleCount() );
77  }
78 
79 }
Revision\MainSlotRoleHandler
A SlotRoleHandler for the main slot.
Definition: MainSlotRoleHandler.php:41
MediaWiki\Tests\Revision
Definition: FallbackSlotRoleHandlerTest.php:3
MediaWiki\Tests\Revision\MainSlotRoleHandlerTest\testSupportsArticleCount
testSupportsArticleCount()
\MediaWiki\Revision\MainSlotRoleHandler::supportsArticleCount()
Definition: MainSlotRoleHandlerTest.php:73
CONTENT_MODEL_WIKITEXT
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:235
MediaWiki\Tests\Revision\MainSlotRoleHandlerTest\makeTitleObject
makeTitleObject( $ns)
Definition: MainSlotRoleHandlerTest.php:15
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
NS_MAIN
const NS_MAIN
Definition: Defines.php:64
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
$handler
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves $handler
Definition: hooks.txt:780
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
MediaWiki\Tests\Revision\MainSlotRoleHandlerTest\testConstruction
testConstruction()
\MediaWiki\Revision\MainSlotRoleHandler::__construct \MediaWiki\Revision\MainSlotRoleHandler::getRole...
Definition: MainSlotRoleHandlerTest.php:33
MediaWiki\Tests\Revision\MainSlotRoleHandlerTest\testFetDefaultModel
testFetDefaultModel()
\MediaWiki\Revision\MainSlotRoleHandler::getDefaultModel()
Definition: MainSlotRoleHandlerTest.php:47
MediaWiki\Tests\Revision\MainSlotRoleHandlerTest
\MediaWiki\Revision\MainSlotRoleHandler
Definition: MainSlotRoleHandlerTest.php:13
Title
Represents a title within MediaWiki.
Definition: Title.php:40
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
CONTENT_MODEL_TEXT
const CONTENT_MODEL_TEXT
Definition: Defines.php:238
MediaWiki\Tests\Revision\MainSlotRoleHandlerTest\testIsAllowedModel
testIsAllowedModel()
\MediaWiki\Revision\MainSlotRoleHandler::isAllowedModel()
Definition: MainSlotRoleHandlerTest.php:61