From: Thiemo Mättig Date: Fri, 27 Jun 2014 13:39:23 +0000 (+0200) Subject: Add ActionTest for static Action methods X-Git-Tag: 1.31.0-rc.0~14893^2 X-Git-Url: http://git.cyclocoop.org/%24href?a=commitdiff_plain;h=20a1087bd5bbbca11100606bca82e2892d5787c2;p=lhc%2Fweb%2Fwiklou.git Add ActionTest for static Action methods Change-Id: Ifea52280486b8aa29fbab42e4c7d3ea907849b52 --- diff --git a/tests/phpunit/includes/actions/ActionTest.php b/tests/phpunit/includes/actions/ActionTest.php new file mode 100644 index 0000000000..1ebd9083d1 --- /dev/null +++ b/tests/phpunit/includes/actions/ActionTest.php @@ -0,0 +1,110 @@ +setMwGlobals( 'wgActions', array( + 'null' => null, + 'dummy' => true, + 'string' => 'NamedDummyAction', + 'callable' => array( $this, 'dummyActionCallback' ), + 'object' => new InstantiatedDummyAction( $this->getPage(), $this->getContext() ), + ) ); + } + + private function getPage() { + return WikiPage::factory( Title::makeTitle( 0, 'Title' ) ); + } + + private function getContext() { + return new DerivativeContext( RequestContext::getMain() ); + } + + public function actionProvider() { + return array( + array( 'dummy', 'DummyAction' ), + array( 'string', 'NamedDummyAction' ), + array( 'callable', 'CalledDummyAction' ), + array( 'object', 'InstantiatedDummyAction' ), + + // Capitalization is ignored + array( 'STRING', 'NamedDummyAction' ), + + // Null and non-existing values + array( 'null', null ), + array( 'undeclared', null ), + array( '', null ), + array( null, null ), + ); + } + + /** + * @dataProvider actionProvider + * @param string $requestedAction + * @param string|null $expected + */ + public function testActionExists( $requestedAction, $expected ) { + $exists = Action::exists( $requestedAction ); + + $this->assertEquals( isset( $expected ), $exists ); + } + + /** + * @dataProvider actionProvider + * @param string $requestedAction + * @param string|null $expected + */ + public function testGetActionName( $requestedAction, $expected ) { + $context = $this->getContext(); + $context->setWikiPage( $this->getPage() ); + $context->setRequest( new FauxRequest( array( 'action' => $requestedAction ) ) ); + + $actionName = Action::getActionName( $context ); + + $this->assertEquals( isset( $expected ) ? $expected : 'nosuchaction', $actionName ); + } + + /** + * @dataProvider actionProvider + * @param string $requestedAction + * @param string|null $expected + */ + public function testActionFactory( $requestedAction, $expected ) { + $action = Action::factory( $requestedAction, $this->getPage(), $this->getContext() ); + + $this->assertType( isset( $expected ) ? $expected : 'null', $action ); + } + + public function dummyActionCallback() { + return new CalledDummyAction( $this->getPage(), $this->getContext() ); + } + +} + +class DummyAction extends Action { + + public function getName() { + return get_called_class(); + } + + public function show() { } + + public function execute() { } + +} + +class NamedDummyAction extends DummyAction { } + +class CalledDummyAction extends DummyAction { } + +class InstantiatedDummyAction extends DummyAction { }