use MediaWiki\Block\Restriction\PageRestriction;
use MediaWiki\Block\Restriction\NamespaceRestriction;
+use MediaWiki\Block\SystemBlock;
use MediaWiki\MediaWikiServices;
use MediaWiki\User\UserIdentityValue;
use Wikimedia\TestingAccessWrapper;
}
/**
+ * @covers User::isRegistered
* @covers User::isLoggedIn
* @covers User::isAnon
*/
public function testLoggedIn() {
$user = $this->getMutableTestUser()->getUser();
+ $this->assertTrue( $user->isRegistered() );
$this->assertTrue( $user->isLoggedIn() );
$this->assertFalse( $user->isAnon() );
// Non-existent users are perceived as anonymous
$user = User::newFromName( 'UTNonexistent' );
+ $this->assertFalse( $user->isRegistered() );
$this->assertFalse( $user->isLoggedIn() );
$this->assertTrue( $user->isAnon() );
$user = new User;
+ $this->assertFalse( $user->isRegistered() );
$this->assertFalse( $user->isLoggedIn() );
$this->assertTrue( $user->isAnon() );
}
$request->setIP( '10.20.30.40' );
$setSessionUser( $wgUser, $request );
$block = $wgUser->getBlock();
- $this->assertInstanceOf( Block::class, $block );
+ $this->assertInstanceOf( SystemBlock::class, $block );
$this->assertSame( 'wgSoftBlockRanges', $block->getSystemBlockType() );
// Make sure the block is really soft
$this->assertSame( 'Bogus', $test->getName() );
$this->assertSame( 654321, $test->getActorId() );
+ // Loading remote user by name from remote wiki should succeed
+ $test = User::newFromAnyId( null, 'Bogus', null, 'foo' );
+ $this->assertSame( 0, $test->getId() );
+ $this->assertSame( 'Bogus', $test->getName() );
+ $this->assertSame( 0, $test->getActorId() );
+ $test = User::newFromAnyId( 123456, 'Bogus', 654321, 'foo' );
+ $this->assertSame( 0, $test->getId() );
+ $this->assertSame( 0, $test->getActorId() );
+
// Exceptional cases
try {
User::newFromAnyId( null, null, null );
$this->fail( 'Expected exception not thrown' );
} catch ( InvalidArgumentException $ex ) {
}
+
+ // Loading remote user by id from remote wiki should fail
+ try {
+ User::newFromAnyId( 123456, null, 654321, 'foo' );
+ $this->fail( 'Expected exception not thrown' );
+ } catch ( InvalidArgumentException $ex ) {
+ }
}
/**
$updater->setContent( 'main', $content );
return $updater->saveRevision( CommentStoreComment::newUnsavedComment( $comment ) );
}
+
+ /**
+ * @covers User::idFromName
+ */
+ public function testExistingIdFromName() {
+ $this->assertTrue(
+ array_key_exists( $this->user->getName(), User::$idCacheByName ),
+ 'Test user should already be in the id cache.'
+ );
+ $this->assertSame(
+ $this->user->getId(), User::idFromName( $this->user->getName() ),
+ 'Id is correctly retreived from the cache.'
+ );
+ $this->assertSame(
+ $this->user->getId(), User::idFromName( $this->user->getName(), User::READ_LATEST ),
+ 'Id is correctly retreived from the database.'
+ );
+ }
+
+ /**
+ * @covers User::idFromName
+ */
+ public function testNonExistingIdFromName() {
+ $this->assertFalse(
+ array_key_exists( 'NotExisitngUser', User::$idCacheByName ),
+ 'Non exisitng user should not be in the id cache.'
+ );
+ $this->assertSame( null, User::idFromName( 'NotExisitngUser' ) );
+ $this->assertTrue(
+ array_key_exists( 'NotExisitngUser', User::$idCacheByName ),
+ 'Username will be cached when requested once.'
+ );
+ $this->assertSame( null, User::idFromName( 'NotExisitngUser' ) );
+ }
}