7 * @author Thiemo Mättig
11 class ActionTest
extends MediaWikiTestCase
{
13 protected function setUp() {
16 $context = $this->getContext();
17 $this->setMwGlobals( 'wgActions', array(
20 'string' => 'NamedDummyAction',
21 'declared' => 'NonExistingClassName',
22 'callable' => array( $this, 'dummyActionCallback' ),
23 'object' => new InstantiatedDummyAction( $context->getWikiPage(), $context ),
27 private function getContext( $requestedAction = null ) {
28 $request = new FauxRequest( array( 'action' => $requestedAction ) );
30 $page = WikiPage
::factory( Title
::makeTitle( 0, 'Title' ) );
32 $context = new DerivativeContext( RequestContext
::getMain() );
33 $context->setRequest( $request );
34 $context->setWikiPage( $page );
39 public function actionProvider() {
41 array( 'dummy', 'DummyAction' ),
42 array( 'string', 'NamedDummyAction' ),
43 array( 'callable', 'CalledDummyAction' ),
44 array( 'object', 'InstantiatedDummyAction' ),
46 // Capitalization is ignored
47 array( 'DUMMY', 'DummyAction' ),
48 array( 'STRING', 'NamedDummyAction' ),
50 // Null and non-existing values
51 array( 'null', null ),
52 array( 'undeclared', null ),
60 * @dataProvider actionProvider
61 * @param string $requestedAction
62 * @param string|null $expected
64 public function testActionExists( $requestedAction, $expected ) {
65 $exists = Action
::exists( $requestedAction );
67 $this->assertSame( $expected !== null, $exists );
70 public function testActionExists_doesNotRequireInstantiation() {
71 // The method is not supposed to check if the action can be instantiated.
72 $exists = Action
::exists( 'declared' );
74 $this->assertTrue( $exists );
78 * @dataProvider actionProvider
79 * @param string $requestedAction
80 * @param string|null $expected
82 public function testGetActionName( $requestedAction, $expected ) {
83 $context = $this->getContext( $requestedAction );
84 $actionName = Action
::getActionName( $context );
86 $this->assertEquals( $expected ?
: 'nosuchaction', $actionName );
90 * @dataProvider actionProvider
91 * @param string $requestedAction
92 * @param string|null $expected
94 public function testActionFactory( $requestedAction, $expected ) {
95 $context = $this->getContext();
96 $action = Action
::factory( $requestedAction, $context->getWikiPage(), $context );
98 $this->assertType( $expected ?
: 'null', $action );
101 public function dummyActionCallback() {
102 $context = $this->getContext();
103 return new CalledDummyAction( $context->getWikiPage(), $context );
108 class DummyAction
extends Action
{
110 public function getName() {
111 return get_called_class();
114 public function show() {
117 public function execute() {
121 class NamedDummyAction
extends DummyAction
{
124 class CalledDummyAction
extends DummyAction
{
127 class InstantiatedDummyAction
extends DummyAction
{