Merge "Fixed spacing"
[lhc/web/wiklou.git] / tests / phpunit / includes / actions / ActionTest.php
1 <?php
2
3 /**
4 * @covers Action
5 *
6 * @licence GNU GPL v2+
7 * @author Thiemo Mättig
8 *
9 * @group Action
10 */
11 class ActionTest extends MediaWikiTestCase {
12
13 protected function setUp() {
14 parent::setUp();
15
16 $this->setMwGlobals( 'wgActions', array(
17 'null' => null,
18 'dummy' => true,
19 'string' => 'NamedDummyAction',
20 'declared' => 'NonExistingClassName',
21 'callable' => array( $this, 'dummyActionCallback' ),
22 'object' => new InstantiatedDummyAction( $this->getPage(), $this->getContext() ),
23 ) );
24 }
25
26 private function getPage() {
27 return WikiPage::factory( Title::makeTitle( 0, 'Title' ) );
28 }
29
30 private function getContext() {
31 return new DerivativeContext( RequestContext::getMain() );
32 }
33
34 public function actionProvider() {
35 return array(
36 array( 'dummy', 'DummyAction' ),
37 array( 'string', 'NamedDummyAction' ),
38 array( 'callable', 'CalledDummyAction' ),
39 array( 'object', 'InstantiatedDummyAction' ),
40
41 // Capitalization is ignored
42 array( 'STRING', 'NamedDummyAction' ),
43
44 // Null and non-existing values
45 array( 'null', null ),
46 array( 'undeclared', null ),
47 array( '', null ),
48 array( null, null ),
49 );
50 }
51
52 /**
53 * @dataProvider actionProvider
54 * @param string $requestedAction
55 * @param string|null $expected
56 */
57 public function testActionExists( $requestedAction, $expected ) {
58 $exists = Action::exists( $requestedAction );
59
60 $this->assertEquals( isset( $expected ), $exists );
61 }
62
63 public function testActionExists_doesNotRequireInstantiation() {
64 // The method is not supposed to check if the action can be instantiated.
65 $exists = Action::exists( 'declared' );
66
67 $this->assertTrue( $exists );
68 }
69
70 /**
71 * @dataProvider actionProvider
72 * @param string $requestedAction
73 * @param string|null $expected
74 */
75 public function testGetActionName( $requestedAction, $expected ) {
76 $context = $this->getContext();
77 $context->setWikiPage( $this->getPage() );
78 $context->setRequest( new FauxRequest( array( 'action' => $requestedAction ) ) );
79
80 $actionName = Action::getActionName( $context );
81
82 $this->assertEquals( isset( $expected ) ? $expected : 'nosuchaction', $actionName );
83 }
84
85 /**
86 * @dataProvider actionProvider
87 * @param string $requestedAction
88 * @param string|null $expected
89 */
90 public function testActionFactory( $requestedAction, $expected ) {
91 $action = Action::factory( $requestedAction, $this->getPage(), $this->getContext() );
92
93 $this->assertType( isset( $expected ) ? $expected : 'null', $action );
94 }
95
96 public function dummyActionCallback() {
97 return new CalledDummyAction( $this->getPage(), $this->getContext() );
98 }
99
100 }
101
102 class DummyAction extends Action {
103
104 public function getName() {
105 return get_called_class();
106 }
107
108 public function show() {
109 }
110
111 public function execute() {
112 }
113 }
114
115 class NamedDummyAction extends DummyAction {
116 }
117
118 class CalledDummyAction extends DummyAction {
119 }
120
121 class InstantiatedDummyAction extends DummyAction {
122 }