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 );
146 $this->assertEquals( $ugm->getUserId(), $this->userTester->getId() );
147 $this->assertEquals( $ugm->getGroup(),
'unittesters' );
148 $this->assertNull( $ugm->getExpiry() );