1ebd9083d1addf89fdceb7d08f169af9766271a6
[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 'callable' => array( $this, 'dummyActionCallback' ),
21 'object' => new InstantiatedDummyAction( $this->getPage(), $this->getContext() ),
22 ) );
23 }
24
25 private function getPage() {
26 return WikiPage::factory( Title::makeTitle( 0, 'Title' ) );
27 }
28
29 private function getContext() {
30 return new DerivativeContext( RequestContext::getMain() );
31 }
32
33 public function actionProvider() {
34 return array(
35 array( 'dummy', 'DummyAction' ),
36 array( 'string', 'NamedDummyAction' ),
37 array( 'callable', 'CalledDummyAction' ),
38 array( 'object', 'InstantiatedDummyAction' ),
39
40 // Capitalization is ignored
41 array( 'STRING', 'NamedDummyAction' ),
42
43 // Null and non-existing values
44 array( 'null', null ),
45 array( 'undeclared', null ),
46 array( '', null ),
47 array( null, null ),
48 );
49 }
50
51 /**
52 * @dataProvider actionProvider
53 * @param string $requestedAction
54 * @param string|null $expected
55 */
56 public function testActionExists( $requestedAction, $expected ) {
57 $exists = Action::exists( $requestedAction );
58
59 $this->assertEquals( isset( $expected ), $exists );
60 }
61
62 /**
63 * @dataProvider actionProvider
64 * @param string $requestedAction
65 * @param string|null $expected
66 */
67 public function testGetActionName( $requestedAction, $expected ) {
68 $context = $this->getContext();
69 $context->setWikiPage( $this->getPage() );
70 $context->setRequest( new FauxRequest( array( 'action' => $requestedAction ) ) );
71
72 $actionName = Action::getActionName( $context );
73
74 $this->assertEquals( isset( $expected ) ? $expected : 'nosuchaction', $actionName );
75 }
76
77 /**
78 * @dataProvider actionProvider
79 * @param string $requestedAction
80 * @param string|null $expected
81 */
82 public function testActionFactory( $requestedAction, $expected ) {
83 $action = Action::factory( $requestedAction, $this->getPage(), $this->getContext() );
84
85 $this->assertType( isset( $expected ) ? $expected : 'null', $action );
86 }
87
88 public function dummyActionCallback() {
89 return new CalledDummyAction( $this->getPage(), $this->getContext() );
90 }
91
92 }
93
94 class DummyAction extends Action {
95
96 public function getName() {
97 return get_called_class();
98 }
99
100 public function show() { }
101
102 public function execute() { }
103
104 }
105
106 class NamedDummyAction extends DummyAction { }
107
108 class CalledDummyAction extends DummyAction { }
109
110 class InstantiatedDummyAction extends DummyAction { }