$this->assertEquals( $orig->getSha1(), $rev->getSha1() );
}
+ /**
+ * @covers Revision::getRecentChange
+ */
+ public function testGetRecentChange() {
+ $rev = $this->testPage->getRevision();
+ $recentChange = $rev->getRecentChange();
+
+ // Make sure various attributes look right / the correct entry has been retrieved.
+ $this->assertEquals( $rev->getTimestamp(), $recentChange->getAttribute( 'rc_timestamp' ) );
+ $this->assertEquals(
+ $rev->getTitle()->getNamespace(),
+ $recentChange->getAttribute( 'rc_namespace' )
+ );
+ $this->assertEquals(
+ $rev->getTitle()->getDBkey(),
+ $recentChange->getAttribute( 'rc_title' )
+ );
+ $this->assertEquals( $rev->getUser(), $recentChange->getAttribute( 'rc_user' ) );
+ $this->assertEquals( $rev->getUserText(), $recentChange->getAttribute( 'rc_user_text' ) );
+ $this->assertEquals( $rev->getComment(), $recentChange->getAttribute( 'rc_comment' ) );
+ $this->assertEquals( $rev->getPage(), $recentChange->getAttribute( 'rc_cur_id' ) );
+ $this->assertEquals( $rev->getId(), $recentChange->getAttribute( 'rc_this_oldid' ) );
+ }
+
/**
* @covers Revision::insertOn
*/
$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 )
+ );
+
+ // Fallback to $wgUser
+ $this->setMwGlobals(
+ 'wgUser',
+ $user
+ );
+ $this->assertSame(
+ $expected,
+ Revision::userCanBitfield( $bitField, $field, null, $title )
+ );
+ }
+
+ public function provideUserCan() {
+ yield [ 0, 0, [], true ];
+ // Bitfields match, user has no permissions
+ yield [ Revision::DELETED_TEXT, Revision::DELETED_TEXT, [], false ];
+ yield [ Revision::DELETED_COMMENT, Revision::DELETED_COMMENT, [], false ];
+ yield [ Revision::DELETED_USER, Revision::DELETED_USER, [], false ];
+ yield [ Revision::DELETED_RESTRICTED, Revision::DELETED_RESTRICTED, [], false ];
+ // Bitfields match, user (admin) does have permissions
+ yield [ Revision::DELETED_TEXT, Revision::DELETED_TEXT, [ 'sysop' ], true ];
+ yield [ Revision::DELETED_COMMENT, Revision::DELETED_COMMENT, [ 'sysop' ], true ];
+ yield [ Revision::DELETED_USER, Revision::DELETED_USER, [ 'sysop' ], true ];
+ // Bitfields match, user (admin) does not have permissions
+ yield [ Revision::DELETED_RESTRICTED, Revision::DELETED_RESTRICTED, [ 'sysop' ], false ];
+ // Bitfields match, user (oversight) does have permissions
+ yield [ Revision::DELETED_RESTRICTED, Revision::DELETED_RESTRICTED, [ 'oversight' ], true ];
+ }
+
+ /**
+ * @dataProvider provideUserCan
+ * @covers Revision::userCan
+ */
+ public function testUserCan( $bitField, $field, $userGroups, $expected ) {
+ $this->setMwGlobals(
+ 'wgGroupPermissions',
+ [
+ 'sysop' => [
+ 'deletedtext' => true,
+ 'deletedhistory' => true,
+ ],
+ 'oversight' => [
+ 'viewsuppressed' => true,
+ 'suppressrevision' => true,
+ ],
+ ]
+ );
+ $user = $this->getTestUser( $userGroups )->getUser();
+ $revision = new Revision( [ 'deleted' => $bitField ] );
+
+ $this->assertSame(
+ $expected,
+ $revision->userCan( $field, $user )
+ );
+ }
+
}