From b287ec2cc649a96bb19c893c46f88734c6392204 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thiemo=20M=C3=A4ttig?= Date: Tue, 14 Oct 2014 16:31:43 +0200 Subject: [PATCH] Make an empty "?action=" parameter default to "view" When no action is given, e.g. in https://en.wikipedia.org/wiki/URL the action defaults to "view". Just like you called https://en.wikipedia.org/wiki/URL?action=view But when the action is empty, e.g. https://en.wikipedia.org/wiki/URL?action= you get an error message telling you that "the action specified" can not be "recognized". Wait, I did not "specified" an action. That's why I left the parameter empty. From the users point of view I expect the empty string to behave like null/undefined. This is a resubmit of I331924d without the problematic bits. Change-Id: I07847600bb24ae078276acf98e6eb244039414d7 --- includes/actions/Action.php | 2 +- tests/phpunit/includes/actions/ActionTest.php | 31 ++++++++++++++----- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/includes/actions/Action.php b/includes/actions/Action.php index 839d7b23e7..4208b3b49e 100644 --- a/includes/actions/Action.php +++ b/includes/actions/Action.php @@ -147,7 +147,7 @@ abstract class Action { // Trying to get a WikiPage for NS_SPECIAL etc. will result // in WikiPage::factory throwing "Invalid or virtual namespace -1 given." // For SpecialPages et al, default to action=view. - if ( !$context->canUseWikiPage() ) { + if ( $actionName === '' || !$context->canUseWikiPage() ) { return 'view'; } diff --git a/tests/phpunit/includes/actions/ActionTest.php b/tests/phpunit/includes/actions/ActionTest.php index 4a302920e1..75c5b500c1 100644 --- a/tests/phpunit/includes/actions/ActionTest.php +++ b/tests/phpunit/includes/actions/ActionTest.php @@ -56,8 +56,6 @@ class ActionTest extends MediaWikiTestCase { // Null and non-existing values [ 'null', null ], [ 'undeclared', null ], - [ '', null ], - [ false, null ], ]; } @@ -137,22 +135,39 @@ class ActionTest extends MediaWikiTestCase { $this->assertType( $expected ?: 'null', $action ); } - public function testNull_doesNotExist() { - $exists = Action::exists( null ); + public function emptyActionProvider() { + return [ + [ null ], + [ false ], + [ '' ], + ]; + } + + /** + * @dataProvider emptyActionProvider + */ + public function testEmptyAction_doesNotExist( $requestedAction ) { + $exists = Action::exists( $requestedAction ); $this->assertFalse( $exists ); } - public function testNull_defaultsToView() { - $context = $this->getContext( null ); + /** + * @dataProvider emptyActionProvider + */ + public function testEmptyAction_defaultsToView( $requestedAction ) { + $context = $this->getContext( $requestedAction ); $actionName = Action::getActionName( $context ); $this->assertEquals( 'view', $actionName ); } - public function testNull_canNotBeInstantiated() { + /** + * @dataProvider emptyActionProvider + */ + public function testEmptyAction_canNotBeInstantiated( $requestedAction ) { $page = $this->getPage(); - $action = Action::factory( null, $page ); + $action = Action::factory( $requestedAction, $page ); $this->assertNull( $action ); } -- 2.20.1