wiki.techinc.nl/tests/phpunit/unit/includes/user/UserIdentityValueTest.php
daniel fed7f0b179 Remove $actor field from UsererIdentityValue
Code that needs to store an actor ID in the database to
represent a UserIdentity, or needs to construct a UserIdentity based on
an actor ID loaded from the database, should use the ActorNormalization
service.

Note: The getActorId() method is removed from the UserIdentity interface,
but all concrete classes continue to support it for now.
UsererIdentityValue::getActorId() is hard deprecated and should
be removed in 1.37. It always returns 0.
User::getActorId() is not deprecated at this point.

Bug: T274179
Depends-On: Id2b3ddf6a2a7cdf90f8936a69148d2cce6fde237
Change-Id: I9925906d11e47efaec3c1f48d5cb3f9896a982c1
2021-04-13 18:18:06 +00:00

109 lines
2.9 KiB
PHP

<?php
use MediaWiki\User\UserIdentityValue;
use Wikimedia\Assert\PreconditionException;
/**
* @covers \MediaWiki\DAO\WikiAwareEntityTrait
* @coversDefaultClass \MediaWiki\User\UserIdentityValue
*/
class UserIdentityValueTest extends MediaWikiUnitTestCase {
/**
* @covers ::getActorId
*/
public function testGetActorIdLocalUIVForeignParam() {
$foreignWikiId = 'Foreign Wiki';
$user = new UserIdentityValue( 0, 'TestUserName', UserIdentityValue::LOCAL );
$this->expectDeprecation();
$this->assertSame( 0, $user->getActorId( $foreignWikiId ) );
}
/**
* @covers ::getActorId
*/
public function testGetActorIdDeprecated() {
$user = new UserIdentityValue( 0, 'TestUserName' );
$this->expectDeprecation();
$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 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 );
}
}