2021-01-27 04:25:24 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
use MediaWiki\User\UserIdentityValue;
|
|
|
|
|
use Wikimedia\Assert\PreconditionException;
|
|
|
|
|
|
2021-02-06 00:54:54 +00:00
|
|
|
/**
|
|
|
|
|
* @coversDefaultClass \MediaWiki\User\UserIdentityValue
|
|
|
|
|
*/
|
2021-01-27 04:25:24 +00:00
|
|
|
class UserIdentityValueTest extends MediaWikiUnitTestCase {
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-06 00:54:54 +00:00
|
|
|
* @covers ::getActorId
|
2021-01-27 04:25:24 +00:00
|
|
|
*/
|
2021-02-15 18:58:09 +00:00
|
|
|
public function testGetActorIdLocalUIVForeignParam() {
|
|
|
|
|
$foreignWikiId = 'Foreign Wiki';
|
|
|
|
|
$user = new UserIdentityValue( 0, 'TestUserName', UserIdentityValue::LOCAL );
|
2021-01-27 04:25:24 +00:00
|
|
|
|
2021-02-15 18:58:09 +00:00
|
|
|
$this->expectDeprecation();
|
|
|
|
|
$this->assertSame( 0, $user->getActorId( $foreignWikiId ) );
|
2021-01-27 04:25:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-06 00:54:54 +00:00
|
|
|
* @covers ::getActorId
|
2021-01-27 04:25:24 +00:00
|
|
|
*/
|
2021-02-15 18:58:09 +00:00
|
|
|
public function testGetActorIdDeprecated() {
|
|
|
|
|
$user = new UserIdentityValue( 0, 'TestUserName' );
|
2021-01-27 04:25:24 +00:00
|
|
|
|
|
|
|
|
$this->expectDeprecation();
|
2021-02-15 18:58:09 +00:00
|
|
|
$this->assertSame( 0, $user->getActorId() );
|
2021-01-27 04:25:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-06 00:54:54 +00:00
|
|
|
* @covers ::getActorId
|
2021-01-27 04:25:24 +00:00
|
|
|
*/
|
2021-02-15 18:58:09 +00:00
|
|
|
public function testGetActorIdLocalUIVNoParam() {
|
|
|
|
|
$this->filterDeprecated( '/UserIdentityValue::getActorId was deprecated/' );
|
|
|
|
|
$user = new UserIdentityValue( 0, 'TestUserName', UserIdentityValue::LOCAL );
|
2021-01-27 04:25:24 +00:00
|
|
|
|
2021-02-15 18:58:09 +00:00
|
|
|
$this->assertSame( 0, $user->getActorId() );
|
2021-01-27 04:25:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-06 00:54:54 +00:00
|
|
|
* @covers ::getActorId
|
2021-01-27 04:25:24 +00:00
|
|
|
*/
|
2021-02-15 18:58:09 +00:00
|
|
|
public function testGetActorIdLocalUIVLocalParam() {
|
|
|
|
|
$this->filterDeprecated( '/UserIdentityValue::getActorId was deprecated/' );
|
|
|
|
|
$user = new UserIdentityValue( 0, 'TestUserName', UserIdentityValue::LOCAL );
|
2021-01-27 04:25:24 +00:00
|
|
|
|
2021-02-15 18:58:09 +00:00
|
|
|
$this->assertSame( 0, $user->getActorId( UserIdentityValue::LOCAL ) );
|
2021-01-27 04:25:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-06 00:54:54 +00:00
|
|
|
* @covers ::getActorId
|
2021-01-27 04:25:24 +00:00
|
|
|
*/
|
|
|
|
|
public function testGetActorIdForeignUIVForeignParam() {
|
2021-02-15 18:58:09 +00:00
|
|
|
$this->filterDeprecated( '/UserIdentityValue::getActorId was deprecated/' );
|
2021-01-27 04:25:24 +00:00
|
|
|
$foreignWikiId = 'Foreign Wiki';
|
2021-02-15 18:58:09 +00:00
|
|
|
$user = new UserIdentityValue( 0, 'TestUserName', $foreignWikiId );
|
2021-01-27 04:25:24 +00:00
|
|
|
|
2021-02-15 18:58:09 +00:00
|
|
|
$this->assertSame( 0, $user->getActorId( $foreignWikiId ) );
|
2021-01-27 04:25:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return Generator
|
|
|
|
|
*/
|
|
|
|
|
public function provideWikiIds() {
|
|
|
|
|
yield [ UserIdentityValue::LOCAL ];
|
|
|
|
|
yield [ 'Foreign Wiki' ];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-06 00:54:54 +00:00
|
|
|
* @covers ::getWikiId
|
2021-01-27 04:25:24 +00:00
|
|
|
* @dataProvider provideWikiIds
|
|
|
|
|
* @param string|false $wikiId
|
|
|
|
|
*/
|
|
|
|
|
public function testGetWiki( $wikiId ) {
|
2021-02-15 18:58:09 +00:00
|
|
|
$user = new UserIdentityValue( 0, 'TestUserName', $wikiId );
|
2021-01-27 04:25:24 +00:00
|
|
|
$this->assertSame( $wikiId, $user->getWikiId() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-06 00:54:54 +00:00
|
|
|
* @covers ::assertWiki
|
2021-01-27 04:25:24 +00:00
|
|
|
*/
|
|
|
|
|
public function testAssertWikiLocalUIV() {
|
|
|
|
|
$foreignWikiId = 'Foreign Wiki';
|
2021-02-15 18:58:09 +00:00
|
|
|
$user = new UserIdentityValue( 0, 'TestUserName', UserIdentityValue::LOCAL );
|
2021-01-27 04:25:24 +00:00
|
|
|
|
|
|
|
|
$user->assertWiki( UserIdentityValue::LOCAL );
|
|
|
|
|
$this->assertTrue( true, 'User is for same wiki' );
|
|
|
|
|
|
|
|
|
|
$this->expectException( PreconditionException::class );
|
|
|
|
|
$user->assertWiki( $foreignWikiId );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-06 00:54:54 +00:00
|
|
|
* @covers ::assertWiki
|
2021-01-27 04:25:24 +00:00
|
|
|
*/
|
|
|
|
|
public function testAssertWikiForeignUIV() {
|
|
|
|
|
$foreignWikiId = 'Foreign Wiki';
|
2021-02-15 18:58:09 +00:00
|
|
|
$user = new UserIdentityValue( 0, 'TestUserName', $foreignWikiId );
|
2021-01-27 04:25:24 +00:00
|
|
|
|
|
|
|
|
$user->assertWiki( $foreignWikiId );
|
|
|
|
|
$this->assertTrue( true, 'User is for same wiki' );
|
|
|
|
|
|
|
|
|
|
$this->expectException( PreconditionException::class );
|
|
|
|
|
$user->assertWiki( UserIdentityValue::LOCAL );
|
|
|
|
|
}
|
2021-05-05 18:13:13 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @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() );
|
|
|
|
|
}
|
2021-01-27 04:25:24 +00:00
|
|
|
}
|