From e2675eaeef2cb9be41b0a0ee30635f9f54a1ed26 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thiemo=20M=C3=A4ttig?= Date: Thu, 17 Jul 2014 10:08:49 +0200 Subject: [PATCH] Add tests for NULL to ActionTest NULL should default to 'view'. But both the exists check and the factory should fail when asked for a NULL action. Change-Id: I5751489eed890bb44101f2a4ef73002bff68b207 --- tests/phpunit/includes/actions/ActionTest.php | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/tests/phpunit/includes/actions/ActionTest.php b/tests/phpunit/includes/actions/ActionTest.php index 4eb30ec05a..6175ee6bd6 100644 --- a/tests/phpunit/includes/actions/ActionTest.php +++ b/tests/phpunit/includes/actions/ActionTest.php @@ -17,6 +17,7 @@ class ActionTest extends MediaWikiTestCase { $this->setMwGlobals( 'wgActions', array( 'null' => null, 'disabled' => false, + 'view' => true, 'dummy' => true, 'string' => 'NamedDummyAction', 'declared' => 'NonExistingClassName', @@ -25,14 +26,16 @@ class ActionTest extends MediaWikiTestCase { ) ); } + private function getPage() { + return WikiPage::factory( Title::makeTitle( 0, 'Title' ) ); + } + private function getContext( $requestedAction = null ) { $request = new FauxRequest( array( 'action' => $requestedAction ) ); - $page = WikiPage::factory( Title::makeTitle( 0, 'Title' ) ); - $context = new DerivativeContext( RequestContext::getMain() ); $context->setRequest( $request ); - $context->setWikiPage( $page ); + $context->setWikiPage( $this->getPage() ); return $context; } @@ -52,7 +55,6 @@ class ActionTest extends MediaWikiTestCase { array( 'null', null ), array( 'undeclared', null ), array( '', null ), - array( null, null ), array( false, null ), ); } @@ -99,6 +101,26 @@ class ActionTest extends MediaWikiTestCase { $this->assertType( $expected ?: 'null', $action ); } + public function testNull_doesNotExist() { + $exists = Action::exists( null ); + + $this->assertFalse( $exists ); + } + + public function testNull_defaultsToView() { + $context = $this->getContext( null ); + $actionName = Action::getActionName( $context ); + + $this->assertEquals( 'view', $actionName ); + } + + public function testNull_canNotBeInstantiated() { + $page = $this->getPage(); + $action = Action::factory( null, $page ); + + $this->assertNull( $action ); + } + public function testDisabledAction_exists() { $exists = Action::exists( 'disabled' ); @@ -113,8 +135,8 @@ class ActionTest extends MediaWikiTestCase { } public function testDisabledAction_factoryReturnsFalse() { - $context = $this->getContext( 'disabled' ); - $action = Action::factory( 'disabled', $context->getWikiPage(), $context ); + $page = $this->getPage(); + $action = Action::factory( 'disabled', $page ); $this->assertFalse( $action ); } -- 2.20.1