jenkins-bot has submitted this change and it was merged. Change subject: Add more test cases to ActionTest ......................................................................
Add more test cases to ActionTest 1. The 'dummy' test case already tested ucfirst(), but strtolower() was not tested. The new 'DUMMY' tests fixes that. 2. Add a new test where the requested action is false. 3. Refactored the dummy builder a bit to make it easier to reuse. Change-Id: Id7d9adac064b307b04bf6accb83ffd7f217a857c --- M tests/phpunit/includes/actions/ActionTest.php 1 file changed, 21 insertions(+), 15 deletions(-) Approvals: Hoo man: Looks good to me, approved jenkins-bot: Verified diff --git a/tests/phpunit/includes/actions/ActionTest.php b/tests/phpunit/includes/actions/ActionTest.php index 0c67db7..1297af3 100644 --- a/tests/phpunit/includes/actions/ActionTest.php +++ b/tests/phpunit/includes/actions/ActionTest.php @@ -13,22 +13,27 @@ protected function setUp() { parent::setUp(); + $context = $this->getContext(); $this->setMwGlobals( 'wgActions', array( 'null' => null, 'dummy' => true, 'string' => 'NamedDummyAction', 'declared' => 'NonExistingClassName', 'callable' => array( $this, 'dummyActionCallback' ), - 'object' => new InstantiatedDummyAction( $this->getPage(), $this->getContext() ), + 'object' => new InstantiatedDummyAction( $context->getWikiPage(), $context ), ) ); } - private function getPage() { - return WikiPage::factory( Title::makeTitle( 0, 'Title' ) ); - } + private function getContext( $requestedAction = null ) { + $request = new FauxRequest( array( 'action' => $requestedAction ) ); - private function getContext() { - return new DerivativeContext( RequestContext::getMain() ); + $page = WikiPage::factory( Title::makeTitle( 0, 'Title' ) ); + + $context = new DerivativeContext( RequestContext::getMain() ); + $context->setRequest( $request ); + $context->setWikiPage( $page ); + + return $context; } public function actionProvider() { @@ -39,6 +44,7 @@ array( 'object', 'InstantiatedDummyAction' ), // Capitalization is ignored + array( 'DUMMY', 'DummyAction' ), array( 'STRING', 'NamedDummyAction' ), // Null and non-existing values @@ -46,6 +52,7 @@ array( 'undeclared', null ), array( '', null ), array( null, null ), + array( false, null ), ); } @@ -57,7 +64,7 @@ public function testActionExists( $requestedAction, $expected ) { $exists = Action::exists( $requestedAction ); - $this->assertEquals( isset( $expected ), $exists ); + $this->assertSame( $expected !== null, $exists ); } public function testActionExists_doesNotRequireInstantiation() { @@ -73,13 +80,10 @@ * @param string|null $expected */ public function testGetActionName( $requestedAction, $expected ) { - $context = $this->getContext(); - $context->setWikiPage( $this->getPage() ); - $context->setRequest( new FauxRequest( array( 'action' => $requestedAction ) ) ); - + $context = $this->getContext( $requestedAction ); $actionName = Action::getActionName( $context ); - $this->assertEquals( isset( $expected ) ? $expected : 'nosuchaction', $actionName ); + $this->assertEquals( $expected ?: 'nosuchaction', $actionName ); } /** @@ -88,13 +92,15 @@ * @param string|null $expected */ public function testActionFactory( $requestedAction, $expected ) { - $action = Action::factory( $requestedAction, $this->getPage(), $this->getContext() ); + $context = $this->getContext(); + $action = Action::factory( $requestedAction, $context->getWikiPage(), $context ); - $this->assertType( isset( $expected ) ? $expected : 'null', $action ); + $this->assertType( $expected ?: 'null', $action ); } public function dummyActionCallback() { - return new CalledDummyAction( $this->getPage(), $this->getContext() ); + $context = $this->getContext(); + return new CalledDummyAction( $context->getWikiPage(), $context ); } } -- To view, visit https://gerrit.wikimedia.org/r/147043 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Id7d9adac064b307b04bf6accb83ffd7f217a857c Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de> Gerrit-Reviewer: Addshore <addshorew...@gmail.com> Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de> Gerrit-Reviewer: Hoo man <h...@online.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits