Just methods where adding "static" to the declaration was enough, I didn't do anything with providers that used $this. Initially by search and replace. There were many mistakes which I found mostly by running the PHPStorm inspection which searches for $this usage in a static method. Later I used the PHPStorm "make static" action which avoids the more obvious mistakes. Bug: T332865 Change-Id: I47ed6692945607dfa5c139d42edbd934fa4f3a36
85 lines
2 KiB
PHP
85 lines
2 KiB
PHP
<?php
|
|
|
|
class UserGroupMembershipTest extends MediaWikiIntegrationTestCase {
|
|
|
|
protected function setUp(): void {
|
|
parent::setUp();
|
|
|
|
$this->setGroupPermissions(
|
|
[
|
|
'unittesters' => [
|
|
'runtest' => true,
|
|
],
|
|
'testwriters' => [
|
|
'writetest' => true,
|
|
]
|
|
]
|
|
);
|
|
}
|
|
|
|
public static function provideInstantiationValidation() {
|
|
return [
|
|
[ 1, null, null, 1, null, null ],
|
|
[ 1, 'test', null, 1, 'test', null ],
|
|
[ 1, 'test', '12345', 1, 'test', '12345' ]
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideInstantiationValidation
|
|
* @covers UserGroupMembership
|
|
*/
|
|
public function testInstantiation( $userId, $group, $expiry, $userId_, $group_, $expiry_ ) {
|
|
$ugm = new UserGroupMembership( $userId, $group, $expiry );
|
|
$this->assertSame(
|
|
$userId_,
|
|
$ugm->getUserId()
|
|
);
|
|
$this->assertSame(
|
|
$group_,
|
|
$ugm->getGroup()
|
|
);
|
|
$this->assertSame(
|
|
$expiry_,
|
|
$ugm->getExpiry()
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @covers UserGroupMembership::equals
|
|
*/
|
|
public function testComparison() {
|
|
$ugm1 = new UserGroupMembership( 1, 'test', '67890' );
|
|
$ugm2 = new UserGroupMembership( 1, 'test', '67890' );
|
|
$ugm3 = new UserGroupMembership( 1, 'fail', '67890' );
|
|
$ugm4 = new UserGroupMembership( 1, 'fail', '12345' );
|
|
$this->assertTrue( $ugm1->equals( $ugm2 ) );
|
|
$this->assertTrue( $ugm2->equals( $ugm1 ) );
|
|
$this->assertFalse( $ugm1->equals( $ugm3 ) );
|
|
$this->assertFalse( $ugm2->equals( $ugm3 ) );
|
|
$this->assertFalse( $ugm3->equals( $ugm1 ) );
|
|
// Ensure expiry is ignored
|
|
$this->assertTrue( $ugm3->equals( $ugm4 ) );
|
|
}
|
|
|
|
/**
|
|
* @covers UserGroupMembership::isExpired
|
|
*/
|
|
public function testIsExpired() {
|
|
$ts = wfTimestamp( TS_MW, time() - 100 );
|
|
$ugm = new UserGroupMembership( 1, null, $ts );
|
|
$this->assertTrue(
|
|
$ugm->isExpired()
|
|
);
|
|
$ts = wfTimestamp( TS_MW, time() + 100 );
|
|
$ugm = new UserGroupMembership( 1, null, $ts );
|
|
$this->assertFalse(
|
|
$ugm->isExpired()
|
|
);
|
|
$ugm = new UserGroupMembership( 1, null, null );
|
|
$this->assertFalse(
|
|
$ugm->isExpired()
|
|
);
|
|
}
|
|
|
|
}
|