7 * @author Thiemo Mättig
11 class ActionTest
extends MediaWikiTestCase
{
13 protected function setUp() {
16 $this->setMwGlobals( 'wgActions', array(
19 'string' => 'NamedDummyAction',
20 'declared' => 'NonExistingClassName',
21 'callable' => array( $this, 'dummyActionCallback' ),
22 'object' => new InstantiatedDummyAction( $this->getPage(), $this->getContext() ),
26 private function getPage() {
27 return WikiPage
::factory( Title
::makeTitle( 0, 'Title' ) );
30 private function getContext() {
31 return new DerivativeContext( RequestContext
::getMain() );
34 public function actionProvider() {
36 array( 'dummy', 'DummyAction' ),
37 array( 'string', 'NamedDummyAction' ),
38 array( 'callable', 'CalledDummyAction' ),
39 array( 'object', 'InstantiatedDummyAction' ),
41 // Capitalization is ignored
42 array( 'STRING', 'NamedDummyAction' ),
44 // Null and non-existing values
45 array( 'null', null ),
46 array( 'undeclared', null ),
53 * @dataProvider actionProvider
54 * @param string $requestedAction
55 * @param string|null $expected
57 public function testActionExists( $requestedAction, $expected ) {
58 $exists = Action
::exists( $requestedAction );
60 $this->assertEquals( isset( $expected ), $exists );
63 public function testActionExists_doesNotRequireInstantiation() {
64 // The method is not supposed to check if the action can be instantiated.
65 $exists = Action
::exists( 'declared' );
67 $this->assertTrue( $exists );
71 * @dataProvider actionProvider
72 * @param string $requestedAction
73 * @param string|null $expected
75 public function testGetActionName( $requestedAction, $expected ) {
76 $context = $this->getContext();
77 $context->setWikiPage( $this->getPage() );
78 $context->setRequest( new FauxRequest( array( 'action' => $requestedAction ) ) );
80 $actionName = Action
::getActionName( $context );
82 $this->assertEquals( isset( $expected ) ?
$expected : 'nosuchaction', $actionName );
86 * @dataProvider actionProvider
87 * @param string $requestedAction
88 * @param string|null $expected
90 public function testActionFactory( $requestedAction, $expected ) {
91 $action = Action
::factory( $requestedAction, $this->getPage(), $this->getContext() );
93 $this->assertType( isset( $expected ) ?
$expected : 'null', $action );
96 public function dummyActionCallback() {
97 return new CalledDummyAction( $this->getPage(), $this->getContext() );
102 class DummyAction
extends Action
{
104 public function getName() {
105 return get_called_class();
108 public function show() {
111 public function execute() {
115 class NamedDummyAction
extends DummyAction
{
118 class CalledDummyAction
extends DummyAction
{
121 class InstantiatedDummyAction
extends DummyAction
{