29 'wgGroupPermissions' => [
39 $this->userNoGroups =
new User;
40 $this->userNoGroups->
setName(
'NoGroups' );
41 $this->userNoGroups->addToDatabase();
43 $this->userTester =
new User;
44 $this->userTester->
setName(
'Tester' );
45 $this->userTester->addToDatabase();
46 $this->userTester->addGroup(
'unittesters' );
47 $this->expiryTime =
wfTimestamp( TS_MW, time() + 100500 );
48 $this->userTester->addGroup(
'testwriters', $this->expiryTime );
60 $this->assertTrue( $ugm->insert() );
61 $user->clearInstanceCache();
62 $this->assertContains(
'unittesters', $user->getGroups() );
63 $this->assertArrayHasKey(
'unittesters', $user->getGroupMemberships() );
64 $this->assertTrue( $user->isAllowed(
'runtest' ) );
68 $this->assertFalse( $ugm->insert() );
71 $this->assertTrue( $ugm->insert( 2 ) );
72 $user->clearInstanceCache();
73 $this->assertContains(
'unittesters', $user->getGroups() );
74 $this->assertArrayHasKey(
'unittesters', $user->getGroupMemberships() );
75 $this->assertTrue( $user->isAllowed(
'runtest' ) );
79 $user->clearInstanceCache();
80 $this->assertThat( $user->getGroups(),
81 $this->logicalNot( $this->contains(
'unittesters' ) ) );
82 $this->assertThat( $user->getGroupMemberships(),
83 $this->logicalNot( $this->arrayHasKey(
'unittesters' ) ) );
84 $this->assertFalse( $user->isAllowed(
'runtest' ) );
87 $this->assertContains(
'unittesters', $user->getFormerGroups() );
103 $ugms = UserGroupMembership::getMembershipsForUser( $this->userNoGroups->getId() );
104 $this->assertEmpty( $ugms );
107 $testerUserId = $this->userTester->getId();
108 $ugms = UserGroupMembership::getMembershipsForUser( $testerUserId );
109 $this->assertCount( 2, $ugms );
113 $expectedGroups = [
'unittesters',
'testwriters' ];
115 foreach ( $expectedGroups as $group ) {
116 $this->assertArrayHasKey( $group, $ugms );
117 $this->assertEquals( $ugms[$group]->getUserId(), $testerUserId );
118 $this->assertEquals( $ugms[$group]->getGroup(), $group );
120 if ( $group ===
'unittesters' ) {
121 $this->assertNull( $ugms[$group]->getExpiry() );
122 } elseif ( $group ===
'testwriters' ) {
123 $this->assertEquals( $ugms[$group]->getExpiry(), $this->expiryTime );
135 $ugm = UserGroupMembership::getMembership( $this->userNoGroups->getId(),
'sysop' );
136 $this->assertFalse( $ugm );
139 $ugm = UserGroupMembership::getMembership( $this->userNoGroups->getId(),
'user' );
140 $this->assertFalse( $ugm );
143 $ugm = UserGroupMembership::getMembership( $this->userTester->getId(),
'sysop' );
144 $this->assertFalse( $ugm );
147 $ugm = UserGroupMembership::getMembership( $this->userTester->getId(),
'unittesters' );
148 $this->assertInstanceOf( UserGroupMembership::class, $ugm );
149 $this->assertEquals( $ugm->getUserId(), $this->userTester->getId() );
150 $this->assertEquals( $ugm->getGroup(),
'unittesters' );
151 $this->assertNull( $ugm->getExpiry() );