7 * @author Thiemo Mättig
11 class ActionTest
extends MediaWikiTestCase
{
13 protected function setUp() {
16 $this->setMwGlobals( 'wgActions', array(
19 'string' => 'NamedDummyAction',
20 'callable' => array( $this, 'dummyActionCallback' ),
21 'object' => new InstantiatedDummyAction( $this->getPage(), $this->getContext() ),
25 private function getPage() {
26 return WikiPage
::factory( Title
::makeTitle( 0, 'Title' ) );
29 private function getContext() {
30 return new DerivativeContext( RequestContext
::getMain() );
33 public function actionProvider() {
35 array( 'dummy', 'DummyAction' ),
36 array( 'string', 'NamedDummyAction' ),
37 array( 'callable', 'CalledDummyAction' ),
38 array( 'object', 'InstantiatedDummyAction' ),
40 // Capitalization is ignored
41 array( 'STRING', 'NamedDummyAction' ),
43 // Null and non-existing values
44 array( 'null', null ),
45 array( 'undeclared', null ),
52 * @dataProvider actionProvider
53 * @param string $requestedAction
54 * @param string|null $expected
56 public function testActionExists( $requestedAction, $expected ) {
57 $exists = Action
::exists( $requestedAction );
59 $this->assertEquals( isset( $expected ), $exists );
63 * @dataProvider actionProvider
64 * @param string $requestedAction
65 * @param string|null $expected
67 public function testGetActionName( $requestedAction, $expected ) {
68 $context = $this->getContext();
69 $context->setWikiPage( $this->getPage() );
70 $context->setRequest( new FauxRequest( array( 'action' => $requestedAction ) ) );
72 $actionName = Action
::getActionName( $context );
74 $this->assertEquals( isset( $expected ) ?
$expected : 'nosuchaction', $actionName );
78 * @dataProvider actionProvider
79 * @param string $requestedAction
80 * @param string|null $expected
82 public function testActionFactory( $requestedAction, $expected ) {
83 $action = Action
::factory( $requestedAction, $this->getPage(), $this->getContext() );
85 $this->assertType( isset( $expected ) ?
$expected : 'null', $action );
88 public function dummyActionCallback() {
89 return new CalledDummyAction( $this->getPage(), $this->getContext() );
94 class DummyAction
extends Action
{
96 public function getName() {
97 return get_called_class();
100 public function show() { }
102 public function execute() { }
106 class NamedDummyAction
extends DummyAction
{ }
108 class CalledDummyAction
extends DummyAction
{ }
110 class InstantiatedDummyAction
extends DummyAction
{ }