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() );
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.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
setName( $str)
Set the user name.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php