From 392955def19f0c13e62ee29b2626d7ef4f44d64f Mon Sep 17 00:00:00 2001 From: addshore Date: Fri, 10 Nov 2017 15:50:16 +0000 Subject: [PATCH] Tests for Revision::userCanBitfield Bug: T180210 Change-Id: Idf7e9d0f05b967b2fc083e6a70e9411b53390ed7 --- tests/phpunit/includes/RevisionDbTestBase.php | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/tests/phpunit/includes/RevisionDbTestBase.php b/tests/phpunit/includes/RevisionDbTestBase.php index 1149307d92..f5a3c10371 100644 --- a/tests/phpunit/includes/RevisionDbTestBase.php +++ b/tests/phpunit/includes/RevisionDbTestBase.php @@ -1246,4 +1246,62 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase { $this->assertRevEquals( $rev, $cache->get( $key ) ); } + public function provideUserCanBitfield() { + yield [ 0, 0, [], null, true ]; + // Bitfields match, user has no permissions + yield [ Revision::DELETED_TEXT, Revision::DELETED_TEXT, [], null, false ]; + yield [ Revision::DELETED_COMMENT, Revision::DELETED_COMMENT, [], null, false ]; + yield [ Revision::DELETED_USER, Revision::DELETED_USER, [], null, false ]; + yield [ Revision::DELETED_RESTRICTED, Revision::DELETED_RESTRICTED, [], null, false ]; + // Bitfields match, user (admin) does have permissions + yield [ Revision::DELETED_TEXT, Revision::DELETED_TEXT, [ 'sysop' ], null, true ]; + yield [ Revision::DELETED_COMMENT, Revision::DELETED_COMMENT, [ 'sysop' ], null, true ]; + yield [ Revision::DELETED_USER, Revision::DELETED_USER, [ 'sysop' ], null, true ]; + // Bitfields match, user (admin) does not have permissions + yield [ Revision::DELETED_RESTRICTED, Revision::DELETED_RESTRICTED, [ 'sysop' ], null, false ]; + // Bitfields match, user (oversight) does have permissions + yield [ Revision::DELETED_RESTRICTED, Revision::DELETED_RESTRICTED, [ 'oversight' ], null, true ]; + // Check permissions using the title + yield [ + Revision::DELETED_TEXT, + Revision::DELETED_TEXT, + [ 'sysop' ], + Title::newFromText( __METHOD__ ), + true, + ]; + yield [ + Revision::DELETED_TEXT, + Revision::DELETED_TEXT, + [], + Title::newFromText( __METHOD__ ), + false, + ]; + } + + /** + * @dataProvider provideUserCanBitfield + * @covers Revision::userCanBitfield + */ + public function testUserCanBitfield( $bitField, $field, $userGroups, $title, $expected ) { + $this->setMwGlobals( + 'wgGroupPermissions', + [ + 'sysop' => [ + 'deletedtext' => true, + 'deletedhistory' => true, + ], + 'oversight' => [ + 'viewsuppressed' => true, + 'suppressrevision' => true, + ], + ] + ); + $user = $this->getTestUser( $userGroups )->getUser(); + + $this->assertSame( + $expected, + Revision::userCanBitfield( $bitField, $field, $user, $title ) + ); + } + } -- 2.20.1