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
;
11 * Test that runs against all core actions to make sure that
12 * creating an instance of the action works
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' )
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( [
49 $this->getServiceContainer()->getObjectFactory(),
50 $this->createHookContainer(),
51 $this->getServiceContainer()->getContentHandlerFactory()
53 ->onlyMethods( [ 'getArticle' ] )
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() );
66 $factory->getActionInfo( 'missing', $article ),
67 'No ActionInfo should be returned for an unknown action'
70 $factory->getActionInfo( 'disabled', $article ),
71 'No ActionInfo should be returned for a disabled action'
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' );
85 $factory->getActionInfo( 'edit', $article ),
86 'Special pages do not support actions'
89 $factory->getAction( 'edit', $article, $context ),
90 'Special pages do not support actions'