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
149 lines
4.2 KiB
PHP
149 lines
4.2 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->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 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() );
|
|
}
|
|
}
|