Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / includes / user / UserGroupMembershipTest.php
blob07828df6029e57917777aa041ae862a7fbff78eb
1 <?php
3 use MediaWiki\User\UserGroupMembership;
5 class UserGroupMembershipTest extends MediaWikiIntegrationTestCase {
7 protected function setUp(): void {
8 parent::setUp();
10 $this->setGroupPermissions(
12 'unittesters' => [
13 'runtest' => true,
15 'testwriters' => [
16 'writetest' => true,
22 public static function provideInstantiationValidation() {
23 return [
24 [ 1, null, null, 1, null, null ],
25 [ 1, 'test', null, 1, 'test', null ],
26 [ 1, 'test', '12345', 1, 'test', '12345' ]
30 /**
31 * @dataProvider provideInstantiationValidation
32 * @covers \MediaWiki\User\UserGroupMembership
34 public function testInstantiation( $userId, $group, $expiry, $userId_, $group_, $expiry_ ) {
35 $ugm = new UserGroupMembership( $userId, $group, $expiry );
36 $this->assertSame(
37 $userId_,
38 $ugm->getUserId()
40 $this->assertSame(
41 $group_,
42 $ugm->getGroup()
44 $this->assertSame(
45 $expiry_,
46 $ugm->getExpiry()
50 /**
51 * @covers \MediaWiki\User\UserGroupMembership::equals
53 public function testComparison() {
54 $ugm1 = new UserGroupMembership( 1, 'test', '67890' );
55 $ugm2 = new UserGroupMembership( 1, 'test', '67890' );
56 $ugm3 = new UserGroupMembership( 1, 'fail', '67890' );
57 $ugm4 = new UserGroupMembership( 1, 'fail', '12345' );
58 $this->assertTrue( $ugm1->equals( $ugm2 ) );
59 $this->assertTrue( $ugm2->equals( $ugm1 ) );
60 $this->assertFalse( $ugm1->equals( $ugm3 ) );
61 $this->assertFalse( $ugm2->equals( $ugm3 ) );
62 $this->assertFalse( $ugm3->equals( $ugm1 ) );
63 // Ensure expiry is ignored
64 $this->assertTrue( $ugm3->equals( $ugm4 ) );
67 /**
68 * @covers \MediaWiki\User\UserGroupMembership::isExpired
70 public function testIsExpired() {
71 $ts = wfTimestamp( TS_MW, time() - 100 );
72 $ugm = new UserGroupMembership( 1, null, $ts );
73 $this->assertTrue(
74 $ugm->isExpired()
76 $ts = wfTimestamp( TS_MW, time() + 100 );
77 $ugm = new UserGroupMembership( 1, null, $ts );
78 $this->assertFalse(
79 $ugm->isExpired()
81 $ugm = new UserGroupMembership( 1, null, null );
82 $this->assertFalse(
83 $ugm->isExpired()