From: jenkins-bot Date: Fri, 27 Sep 2019 18:38:16 +0000 (+0000) Subject: Merge "Fix permission check on protection log" X-Git-Tag: 1.34.0-rc.0~69 X-Git-Url: http://git.cyclocoop.org/?a=commitdiff_plain;h=f725f4182a7b44a311761207cd95541c33f6abd7;hp=72e141a5e33417a3f4bcb18cf8a862634bda9bee;p=lhc%2Fweb%2Fwiklou.git Merge "Fix permission check on protection log" --- diff --git a/includes/logging/ProtectLogFormatter.php b/includes/logging/ProtectLogFormatter.php index 6e3b26b17f..81d9aa2e45 100644 --- a/includes/logging/ProtectLogFormatter.php +++ b/includes/logging/ProtectLogFormatter.php @@ -101,7 +101,7 @@ class ProtectLogFormatter extends LogFormatter { ]; // Show change protection link - if ( !MediaWikiServices::getInstance() + if ( MediaWikiServices::getInstance() ->getPermissionManager() ->userHasRight( $this->context->getUser(), 'protect' ) ) { diff --git a/tests/phpunit/includes/logging/ProtectLogFormatterTest.php b/tests/phpunit/includes/logging/ProtectLogFormatterTest.php index 1c076cab04..7feaa93022 100644 --- a/tests/phpunit/includes/logging/ProtectLogFormatterTest.php +++ b/tests/phpunit/includes/logging/ProtectLogFormatterTest.php @@ -428,4 +428,46 @@ class ProtectLogFormatterTest extends LogFormatterTestCase { public function testMoveProtLogDatabaseRows( $row, $extra ) { $this->doTestLogFormatter( $row, $extra ); } + + public function provideGetActionLinks() { + yield [ + [ 'protect' ], + true + ]; + yield [ + [], + false + ]; + } + + /** + * @param string[] $permissions + * @param bool $shouldMatch + * @dataProvider provideGetActionLinks + * @covers ProtectLogFormatter::getActionLinks + */ + public function testGetActionLinks( array $permissions, $shouldMatch ) { + RequestContext::resetMain(); + $user = $this->getTestUser()->getUser(); + $this->overrideUserPermissions( $user, $permissions ); + $row = $this->expandDatabaseRow( [ + 'type' => 'protect', + 'action' => 'unprotect', + 'comment' => 'unprotect comment', + 'namespace' => NS_MAIN, + 'title' => 'ProtectPage', + 'params' => [], + ], false ); + $context = new RequestContext(); + $context->setUser( $user ); + $formatter = LogFormatter::newFromRow( $row ); + $formatter->setContext( $context ); + if ( $shouldMatch ) { + $this->assertStringMatchesFormat( + '%Aaction=protect%A', $formatter->getActionLinks() ); + } else { + $this->assertStringNotMatchesFormat( + '%Aaction=protect%A', $formatter->getActionLinks() ); + } + } }