From 0e24c6a44d70697312ceda8dc333b41e993e1e4a Mon Sep 17 00:00:00 2001 From: David Barratt Date: Tue, 19 Feb 2019 22:18:14 -0500 Subject: [PATCH] Add tests to ensure that retrieved actions match passed in restrictions This is a theoretical issue where a passed in restriction does not match the retrieved actions. There are no actions like this in MediaWiki core or known extensions, but since the possibility exists, tests should exist to prevent the issue before it happens. Bug: T213220 Change-Id: I58da016768a3ee958baa2a25b8177a9e667fa955 --- .../phpunit/includes/TitlePermissionTest.php | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/tests/phpunit/includes/TitlePermissionTest.php b/tests/phpunit/includes/TitlePermissionTest.php index cb5e1f8a79..cac5d6b2ee 100644 --- a/tests/phpunit/includes/TitlePermissionTest.php +++ b/tests/phpunit/includes/TitlePermissionTest.php @@ -1030,4 +1030,54 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $this->assertEquals( [], $this->title->getUserPermissionsErrors( 'purge', $this->user ) ); } + + /** + * @covers Title::checkUserBlock + * + * Tests to determine that the passed in permission does not get mixed up with + * an action of the same name. + */ + public function testUserBlockAction() { + global $wgLang; + + $tester = $this->getMockBuilder( Action::class ) + ->disableOriginalConstructor() + ->getMock(); + $tester->method( 'getName' ) + ->willReturn( 'tester' ); + $tester->method( 'getRestriction' ) + ->willReturn( 'test' ); + $tester->method( 'requiresUnblock' ) + ->willReturn( false ); + + $this->setMwGlobals( [ + 'wgActions' => [ + 'tester' => $tester, + ], + 'wgGroupPermissions' => [ + '*' => [ + 'tester' => true, + ], + ], + ] ); + + $now = time(); + $this->user->mBlockedby = $this->user->getName(); + $this->user->mBlock = new Block( [ + 'address' => '127.0.8.1', + 'by' => $this->user->getId(), + 'reason' => 'no reason given', + 'timestamp' => $now, + 'auto' => false, + 'expiry' => 'infinity', + ] ); + + $errors = [ [ 'blockedtext', + '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1', + 'Useruser', null, 'infinite', '127.0.8.1', + $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ] ]; + + $this->assertEquals( $errors, + $this->title->getUserPermissionsErrors( 'tester', $this->user ) ); + } } -- 2.20.1