| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\User\UserIdentityValue; |
| 4 |
use Wikimedia\Assert\PreconditionException; |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
class UserIdentityValueTest extends MediaWikiUnitTestCase { |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
public function testGetActorIdLocalUIVForeignParam() { |
| 15 |
$foreignWikiId = 'Foreign Wiki'; |
| 16 |
$user = new UserIdentityValue( 0, 'TestUserName', UserIdentityValue::LOCAL ); |
| 17 |
|
| 18 |
$this->expectDeprecationAndContinue( '/Use of MediaWiki\\\\User\\\\UserIdentityValue::getActorId was deprecated in MediaWiki 1\.36/' ); |
| 19 |
$this->assertSame( 0, $user->getActorId( $foreignWikiId ) ); |
| 20 |
} |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
public function testGetActorIdDeprecated() { |
| 26 |
$user = new UserIdentityValue( 0, 'TestUserName' ); |
| 27 |
|
| 28 |
$this->expectDeprecationAndContinue( '/Use of MediaWiki\\\\User\\\\UserIdentityValue::getActorId was deprecated in MediaWiki 1\.36/' ); |
| 29 |
$this->assertSame( 0, $user->getActorId() ); |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public function testGetActorIdLocalUIVNoParam() { |
| 36 |
$this->filterDeprecated( '/UserIdentityValue::getActorId was deprecated/' ); |
| 37 |
$user = new UserIdentityValue( 0, 'TestUserName', UserIdentityValue::LOCAL ); |
| 38 |
|
| 39 |
$this->assertSame( 0, $user->getActorId() ); |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
public function testGetActorIdLocalUIVLocalParam() { |
| 46 |
$this->filterDeprecated( '/UserIdentityValue::getActorId was deprecated/' ); |
| 47 |
$user = new UserIdentityValue( 0, 'TestUserName', UserIdentityValue::LOCAL ); |
| 48 |
|
| 49 |
$this->assertSame( 0, $user->getActorId( UserIdentityValue::LOCAL ) ); |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
public function testGetActorIdForeignUIVForeignParam() { |
| 56 |
$this->filterDeprecated( '/UserIdentityValue::getActorId was deprecated/' ); |
| 57 |
$foreignWikiId = 'Foreign Wiki'; |
| 58 |
$user = new UserIdentityValue( 0, 'TestUserName', $foreignWikiId ); |
| 59 |
|
| 60 |
$this->assertSame( 0, $user->getActorId( $foreignWikiId ) ); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
public static function provideWikiIds() { |
| 67 |
yield [ UserIdentityValue::LOCAL ]; |
| 68 |
yield [ 'Foreign Wiki' ]; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
public function testGetWiki( $wikiId ) { |
| 77 |
$user = new UserIdentityValue( 0, 'TestUserName', $wikiId ); |
| 78 |
$this->assertSame( $wikiId, $user->getWikiId() ); |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
public function testAssertWikiLocalUIV() { |
| 85 |
$foreignWikiId = 'Foreign Wiki'; |
| 86 |
$user = new UserIdentityValue( 0, 'TestUserName', UserIdentityValue::LOCAL ); |
| 87 |
|
| 88 |
$user->assertWiki( UserIdentityValue::LOCAL ); |
| 89 |
$this->assertTrue( true, 'User is for same wiki' ); |
| 90 |
|
| 91 |
$this->expectException( PreconditionException::class ); |
| 92 |
$user->assertWiki( $foreignWikiId ); |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
public function testAssertWikiForeignUIV() { |
| 99 |
$foreignWikiId = 'Foreign Wiki'; |
| 100 |
$user = new UserIdentityValue( 0, 'TestUserName', $foreignWikiId ); |
| 101 |
|
| 102 |
$user->assertWiki( $foreignWikiId ); |
| 103 |
$this->assertTrue( true, 'User is for same wiki' ); |
| 104 |
|
| 105 |
$this->expectException( PreconditionException::class ); |
| 106 |
$user->assertWiki( UserIdentityValue::LOCAL ); |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
public function testNewAnonymous() { |
| 113 |
$user = UserIdentityValue::newAnonymous( 'TEST', 'acmewiki' ); |
| 114 |
$this->assertFalse( $user->isRegistered() ); |
| 115 |
$this->assertSame( 'TEST', $user->getName() ); |
| 116 |
$this->assertSame( 0, $user->getId( 'acmewiki' ) ); |
| 117 |
$this->assertSame( 'acmewiki', $user->getWikiId() ); |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
public function testNewRegistered() { |
| 124 |
$user = UserIdentityValue::newRegistered( 1, 'TEST', 'acmewiki' ); |
| 125 |
$this->assertTrue( $user->isRegistered() ); |
| 126 |
$this->assertSame( 'TEST', $user->getName() ); |
| 127 |
$this->assertSame( 1, $user->getId( 'acmewiki' ) ); |
| 128 |
$this->assertSame( 'acmewiki', $user->getWikiId() ); |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
public function testNewRegistered_invalid() { |
| 135 |
$this->expectException( InvalidArgumentException::class ); |
| 136 |
UserIdentityValue::newRegistered( 0, 'TEST', 'acmewiki' ); |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
public function testNewExternal() { |
| 143 |
$user = UserIdentityValue::newExternal( 'imported', 'TEST', 'acmewiki' ); |
| 144 |
$this->assertFalse( $user->isRegistered() ); |
| 145 |
$this->assertSame( 'imported>TEST', $user->getName() ); |
| 146 |
$this->assertSame( 0, $user->getId( 'acmewiki' ) ); |
| 147 |
$this->assertSame( 'acmewiki', $user->getWikiId() ); |
| 148 |
} |
| 149 |
} |