Merge "mediawiki.content.json: Remove file and author annotations"
[mediawiki.git] / tests / phpunit / includes / actions / ActionFactoryIntegrationTest.php
blob5046c2dc405453488f640837291f83bf80dcbf84
1 <?php
3 use MediaWiki\Actions\ActionFactory;
4 use MediaWiki\Context\IContextSource;
5 use MediaWiki\Context\RequestContext;
6 use MediaWiki\MediaWikiServices;
7 use MediaWiki\Title\Title;
8 use Psr\Log\NullLogger;
10 /**
11 * Test that runs against all core actions to make sure that
12 * creating an instance of the action works
14 * @coversNothing
15 * @group Database
17 class ActionFactoryIntegrationTest extends MediaWikiIntegrationTestCase {
19 public function testActionFactoryServiceWiring() {
20 $services = MediaWikiServices::getInstance();
21 $actionFactory = $services->getActionFactory();
22 $context = RequestContext::getMain();
23 $article = Article::newFromTitle( Title::makeTitle( NS_MAIN, 'ActionFactoryServiceWiringTest' ), $context );
25 $actionSpecs = ( new ReflectionClassConstant( ActionFactory::class, 'CORE_ACTIONS' ) )->getValue();
26 foreach ( $actionSpecs as $action => $_ ) {
27 $this->assertInstanceOf( Action::class, $actionFactory->getAction( $action, $article, $context ) );
31 public function testGetActionInfo() {
32 $article = $this->createMock( Article::class );
33 $article->method( 'getActionOverrides' )
34 ->willReturn( [] );
35 $theAction = $this->createMock( Action::class );
36 $theAction->method( 'getName' )->willReturn( 'test' );
37 $theAction->method( 'getRestriction' )->willReturn( 'testing' );
38 $theAction->method( 'needsReadRights' )->willReturn( true );
39 $theAction->method( 'requiresWrite' )->willReturn( true );
40 $theAction->method( 'requiresUnblock' )->willReturn( true );
42 $factory = $this->getMockBuilder( ActionFactory::class )
43 ->setConstructorArgs( [
45 'view' => $theAction,
46 'disabled' => false,
48 new NullLogger(),
49 $this->getServiceContainer()->getObjectFactory(),
50 $this->createHookContainer(),
51 $this->getServiceContainer()->getContentHandlerFactory()
52 ] )
53 ->onlyMethods( [ 'getArticle' ] )
54 ->getMock();
56 $info = $factory->getActionInfo( 'view', $article );
57 $this->assertIsObject( $info );
59 $this->assertSame( 'test', $info->getName() );
60 $this->assertSame( 'testing', $info->getRestriction() );
61 $this->assertTrue( $info->needsReadRights() );
62 $this->assertTrue( $info->requiresWrite() );
63 $this->assertTrue( $info->requiresUnblock() );
65 $this->assertNull(
66 $factory->getActionInfo( 'missing', $article ),
67 'No ActionInfo should be returned for an unknown action'
69 $this->assertNull(
70 $factory->getActionInfo( 'disabled', $article ),
71 'No ActionInfo should be returned for a disabled action'
75 /**
76 * Regression test for T348451
78 public function testActionForSpecialPage() {
79 $context = $this->createMock( IContextSource::class );
80 $factory = $this->getServiceContainer()->getActionFactory();
82 $article = Title::makeTitle( NS_SPECIAL, 'Blankpage' );
84 $this->assertNull(
85 $factory->getActionInfo( 'edit', $article ),
86 'Special pages do not support actions'
88 $this->assertNull(
89 $factory->getAction( 'edit', $article, $context ),
90 'Special pages do not support actions'