26 'wgGroupPermissions' => [
36 $this->userNoGroups =
new User;
37 $this->userNoGroups->
setName(
'NoGroups' );
38 $this->userNoGroups->addToDatabase();
40 $this->userTester =
new User;
41 $this->userTester->
setName(
'Tester' );
42 $this->userTester->addToDatabase();
43 $this->userTester->addGroup(
'unittesters' );
44 $this->expiryTime =
wfTimestamp( TS_MW, time() + 100500 );
45 $this->userTester->addGroup(
'testwriters', $this->expiryTime );
57 $this->assertTrue( $ugm->insert() );
58 $user->clearInstanceCache();
59 $this->assertContains(
'unittesters', $user->getGroups() );
60 $this->assertArrayHasKey(
'unittesters', $user->getGroupMemberships() );
61 $this->assertTrue( $user->isAllowed(
'runtest' ) );
65 $this->assertFalse( $ugm->insert() );
68 $this->assertTrue( $ugm->insert( 2 ) );
69 $user->clearInstanceCache();
70 $this->assertContains(
'unittesters', $user->getGroups() );
71 $this->assertArrayHasKey(
'unittesters', $user->getGroupMemberships() );
72 $this->assertTrue( $user->isAllowed(
'runtest' ) );
76 $user->clearInstanceCache();
77 $this->assertThat( $user->getGroups(),
78 $this->logicalNot( $this->contains(
'unittesters' ) ) );
79 $this->assertThat( $user->getGroupMemberships(),
80 $this->logicalNot( $this->arrayHasKey(
'unittesters' ) ) );
81 $this->assertFalse( $user->isAllowed(
'runtest' ) );
84 $this->assertContains(
'unittesters', $user->getFormerGroups() );
101 $this->assertEmpty( $ugms );
104 $testerUserId = $this->userTester->getId();
106 $this->assertCount( 2, $ugms );
110 $expectedGroups = [
'unittesters',
'testwriters' ];
112 foreach ( $expectedGroups as $group ) {
113 $this->assertArrayHasKey( $group, $ugms );
114 $this->assertEquals( $ugms[$group]->getUserId(), $testerUserId );
115 $this->assertEquals( $ugms[$group]->getGroup(), $group );
117 if ( $group ===
'unittesters' ) {
118 $this->assertNull( $ugms[$group]->getExpiry() );
119 } elseif ( $group ===
'testwriters' ) {
120 $this->assertEquals( $ugms[$group]->getExpiry(), $this->expiryTime );
133 $this->assertFalse( $ugm );
137 $this->assertFalse( $ugm );
141 $this->assertFalse( $ugm );
145 $this->assertInstanceOf( UserGroupMembership::class, $ugm );
146 $this->assertEquals( $ugm->getUserId(), $this->userTester->getId() );
147 $this->assertEquals( $ugm->getGroup(),
'unittesters' );
148 $this->assertNull( $ugm->getExpiry() );
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
testAddAndRemoveGroups()
UserGroupMembership::insert UserGroupMembership::delete.
addUserTesterToExpiredGroup()
string $expiryTime
The timestamp, in TS_MW format, of the expiry of $userTester's membership in the 'testwriters' group.
testGetMembership()
UserGroupMembership::getMembership.
User $userTester
Belongs to the 'unittesters' group indefinitely, and the 'testwriters' group with expiry.
testGetMembershipsForUser()
UserGroupMembership::getMembershipsForUser.
User $userNoGroups
Belongs to no groups.
Represents a "user group membership" – a specific instance of a user belonging to a group.
static getMembershipsForUser( $userId, IDatabase $db=null)
Returns UserGroupMembership objects for all the groups a user currently belongs to.
static getMembership( $userId, $group, IDatabase $db=null)
Returns a UserGroupMembership object that pertains to the given user and group, or false if the user ...
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
setName( $str)
Set the user name.