define( 'NS_UNITTEST_TALK', 5601 );
use MediaWiki\MediaWikiServices;
+use MediaWiki\User\UserIdentityValue;
use Wikimedia\TestingAccessWrapper;
/**
];
}
- /**
- * Test, if for all rights a right- message exist,
- * which is used on Special:ListGroupRights as help text
- * Extensions and core
- *
- * @coversNothing
- */
- public function testAllRightsWithMessage() {
- // Getting all user rights, for core: User::$mCoreRights, for extensions: $wgAvailableRights
- $allRights = User::getAllRights();
- $allMessageKeys = Language::getMessageKeysFor( 'en' );
-
- $rightsWithMessage = [];
- foreach ( $allMessageKeys as $message ) {
- // === 0: must be at beginning of string (position 0)
- if ( strpos( $message, 'right-' ) === 0 ) {
- $rightsWithMessage[] = substr( $message, strlen( 'right-' ) );
- }
- }
-
- sort( $allRights );
- sort( $rightsWithMessage );
-
- $this->assertEquals(
- $allRights,
- $rightsWithMessage,
- 'Each user rights (core/extensions) has a corresponding right- message.'
- );
- }
-
/**
* Test User::editCount
* @group medium
}
}
+ /**
+ * @covers User::newFromIdentity
+ */
+ public function testNewFromIdentity() {
+ // Registered user
+ $user = $this->getTestUser()->getUser();
+
+ $this->assertSame( $user, User::newFromIdentity( $user ) );
+
+ // ID only
+ $identity = new UserIdentityValue( $user->getId(), '', 0 );
+ $result = User::newFromIdentity( $identity );
+ $this->assertInstanceOf( User::class, $result );
+ $this->assertSame( $user->getId(), $result->getId(), 'ID' );
+ $this->assertSame( $user->getName(), $result->getName(), 'Name' );
+ $this->assertSame( $user->getActorId(), $result->getActorId(), 'Actor' );
+
+ // Name only
+ $identity = new UserIdentityValue( 0, $user->getName(), 0 );
+ $result = User::newFromIdentity( $identity );
+ $this->assertInstanceOf( User::class, $result );
+ $this->assertSame( $user->getId(), $result->getId(), 'ID' );
+ $this->assertSame( $user->getName(), $result->getName(), 'Name' );
+ $this->assertSame( $user->getActorId(), $result->getActorId(), 'Actor' );
+
+ // Actor only
+ $identity = new UserIdentityValue( 0, '', $user->getActorId() );
+ $result = User::newFromIdentity( $identity );
+ $this->assertInstanceOf( User::class, $result );
+ $this->assertSame( $user->getId(), $result->getId(), 'ID' );
+ $this->assertSame( $user->getName(), $result->getName(), 'Name' );
+ $this->assertSame( $user->getActorId(), $result->getActorId(), 'Actor' );
+ }
+
/**
* @covers User::getBlockedStatus
* @covers User::getBlock