TestCase::expectDeprecation() is deprecated in PHPUnit 10, use mediawiki own MediaWikiTestCaseTrait::expectDeprecationAndContinue() for this case. This avoids the trigger_error call and isolate the deprecation check into MWDebug class. The continue part is also helpful in StubGlobalUserTest, where after the first deprecation access more code exists, that was not executed as PhpUnit 9 converts deprecations to exceptions. In RCFeedTest the exception needs to be catched as the code proceed after the deprecation notice is emitted. Bug: T342110 Change-Id: Iecf827bec0d5215fd21bbb20b84caf928ee108a0
149 lines
4.4 KiB
PHP
149 lines
4.4 KiB
PHP
<?php
|
|
|
|
use MediaWiki\User\UserIdentityValue;
|
|
use Wikimedia\Assert\PreconditionException;
|
|
|
|
/**
|
|
* @coversDefaultClass \MediaWiki\User\UserIdentityValue
|
|
*/
|
|
class UserIdentityValueTest extends MediaWikiUnitTestCase {
|
|
|
|
/**
|
|
* @covers ::getActorId
|
|
*/
|
|
public function testGetActorIdLocalUIVForeignParam() {
|
|
$foreignWikiId = 'Foreign Wiki';
|
|
$user = new UserIdentityValue( 0, 'TestUserName', UserIdentityValue::LOCAL );
|
|
|
|
$this->expectDeprecationAndContinue( '/Use of MediaWiki\\\\User\\\\UserIdentityValue::getActorId was deprecated in MediaWiki 1\.36/' );
|
|
$this->assertSame( 0, $user->getActorId( $foreignWikiId ) );
|
|
}
|
|
|
|
/**
|
|
* @covers ::getActorId
|
|
*/
|
|
public function testGetActorIdDeprecated() {
|
|
$user = new UserIdentityValue( 0, 'TestUserName' );
|
|
|
|
$this->expectDeprecationAndContinue( '/Use of MediaWiki\\\\User\\\\UserIdentityValue::getActorId was deprecated in MediaWiki 1\.36/' );
|
|
$this->assertSame( 0, $user->getActorId() );
|
|
}
|
|
|
|
/**
|
|
* @covers ::getActorId
|
|
*/
|
|
public function testGetActorIdLocalUIVNoParam() {
|
|
$this->filterDeprecated( '/UserIdentityValue::getActorId was deprecated/' );
|
|
$user = new UserIdentityValue( 0, 'TestUserName', UserIdentityValue::LOCAL );
|
|
|
|
$this->assertSame( 0, $user->getActorId() );
|
|
}
|
|
|
|
/**
|
|
* @covers ::getActorId
|
|
*/
|
|
public function testGetActorIdLocalUIVLocalParam() {
|
|
$this->filterDeprecated( '/UserIdentityValue::getActorId was deprecated/' );
|
|
$user = new UserIdentityValue( 0, 'TestUserName', UserIdentityValue::LOCAL );
|
|
|
|
$this->assertSame( 0, $user->getActorId( UserIdentityValue::LOCAL ) );
|
|
}
|
|
|
|
/**
|
|
* @covers ::getActorId
|
|
*/
|
|
public function testGetActorIdForeignUIVForeignParam() {
|
|
$this->filterDeprecated( '/UserIdentityValue::getActorId was deprecated/' );
|
|
$foreignWikiId = 'Foreign Wiki';
|
|
$user = new UserIdentityValue( 0, 'TestUserName', $foreignWikiId );
|
|
|
|
$this->assertSame( 0, $user->getActorId( $foreignWikiId ) );
|
|
}
|
|
|
|
/**
|
|
* @return Generator
|
|
*/
|
|
public static function provideWikiIds() {
|
|
yield [ UserIdentityValue::LOCAL ];
|
|
yield [ 'Foreign Wiki' ];
|
|
}
|
|
|
|
/**
|
|
* @covers ::getWikiId
|
|
* @dataProvider provideWikiIds
|
|
* @param string|false $wikiId
|
|
*/
|
|
public function testGetWiki( $wikiId ) {
|
|
$user = new UserIdentityValue( 0, 'TestUserName', $wikiId );
|
|
$this->assertSame( $wikiId, $user->getWikiId() );
|
|
}
|
|
|
|
/**
|
|
* @covers ::assertWiki
|
|
*/
|
|
public function testAssertWikiLocalUIV() {
|
|
$foreignWikiId = 'Foreign Wiki';
|
|
$user = new UserIdentityValue( 0, 'TestUserName', UserIdentityValue::LOCAL );
|
|
|
|
$user->assertWiki( UserIdentityValue::LOCAL );
|
|
$this->assertTrue( true, 'User is for same wiki' );
|
|
|
|
$this->expectException( PreconditionException::class );
|
|
$user->assertWiki( $foreignWikiId );
|
|
}
|
|
|
|
/**
|
|
* @covers ::assertWiki
|
|
*/
|
|
public function testAssertWikiForeignUIV() {
|
|
$foreignWikiId = 'Foreign Wiki';
|
|
$user = new UserIdentityValue( 0, 'TestUserName', $foreignWikiId );
|
|
|
|
$user->assertWiki( $foreignWikiId );
|
|
$this->assertTrue( true, 'User is for same wiki' );
|
|
|
|
$this->expectException( PreconditionException::class );
|
|
$user->assertWiki( UserIdentityValue::LOCAL );
|
|
}
|
|
|
|
/**
|
|
* @covers \MediaWiki\User\UserIdentityValue::newAnonymous
|
|
*/
|
|
public function testNewAnonymous() {
|
|
$user = UserIdentityValue::newAnonymous( 'TEST', 'acmewiki' );
|
|
$this->assertFalse( $user->isRegistered() );
|
|
$this->assertSame( 'TEST', $user->getName() );
|
|
$this->assertSame( 0, $user->getId( 'acmewiki' ) );
|
|
$this->assertSame( 'acmewiki', $user->getWikiId() );
|
|
}
|
|
|
|
/**
|
|
* @covers \MediaWiki\User\UserIdentityValue::newRegistered
|
|
*/
|
|
public function testNewRegistered() {
|
|
$user = UserIdentityValue::newRegistered( 1, 'TEST', 'acmewiki' );
|
|
$this->assertTrue( $user->isRegistered() );
|
|
$this->assertSame( 'TEST', $user->getName() );
|
|
$this->assertSame( 1, $user->getId( 'acmewiki' ) );
|
|
$this->assertSame( 'acmewiki', $user->getWikiId() );
|
|
}
|
|
|
|
/**
|
|
* @covers \MediaWiki\User\UserIdentityValue::newRegistered
|
|
*/
|
|
public function testNewRegistered_invalid() {
|
|
$this->expectException( InvalidArgumentException::class );
|
|
UserIdentityValue::newRegistered( 0, 'TEST', 'acmewiki' );
|
|
}
|
|
|
|
/**
|
|
* @covers \MediaWiki\User\UserIdentityValue::newExternal
|
|
*/
|
|
public function testNewExternal() {
|
|
$user = UserIdentityValue::newExternal( 'imported', 'TEST', 'acmewiki' );
|
|
$this->assertFalse( $user->isRegistered() );
|
|
$this->assertSame( 'imported>TEST', $user->getName() );
|
|
$this->assertSame( 0, $user->getId( 'acmewiki' ) );
|
|
$this->assertSame( 'acmewiki', $user->getWikiId() );
|
|
}
|
|
}
|