protected function CommerceMigrateCoreTestTrait::assertUserEntity in Commerce Migrate 3.0.x
Same name and namespace in other branches
- 8.2 tests/src/Kernel/CommerceMigrateCoreTestTrait.php \Drupal\Tests\commerce_migrate\Kernel\CommerceMigrateCoreTestTrait::assertUserEntity()
- 3.1.x tests/src/Kernel/CommerceMigrateCoreTestTrait.php \Drupal\Tests\commerce_migrate\Kernel\CommerceMigrateCoreTestTrait::assertUserEntity()
Asserts various aspects of a user account.
Parameters
string $id: The user ID.
string $label: The username.
string $mail: The user's email address.
string $password: The password for this user.
int $login: The last login time.
bool $blocked: Whether or not the account is blocked.
string $langcode: The user account's language code.
string $timezone: The user account's timezone name.
string $init: The user's initial email address.
string[] $roles: Role IDs the user account is expected to have.
1 call to CommerceMigrateCoreTestTrait::assertUserEntity()
- UserTest::testUser in modules/
magento/ tests/ src/ Kernel/ Migrate/ magento2/ UserTest.php - Test attribute migration.
File
- tests/
src/ Kernel/ CommerceMigrateCoreTestTrait.php, line 163
Class
- CommerceMigrateCoreTestTrait
- Helper function to test migrations.
Namespace
Drupal\Tests\commerce_migrate\KernelCode
protected function assertUserEntity($id, $label, $mail, $password, $login, $blocked, $langcode, $timezone, $init, array $roles) {
/** @var \Drupal\user\UserInterface $user */
$user = User::load($id);
$this
->assertTrue($user instanceof UserInterface);
$this
->assertSame($label, $user
->label());
$this
->assertSame($mail, $user
->getEmail());
$this
->assertSame($password, $user
->getPassword());
$this
->assertSame($login, $user
->getLastLoginTime());
$this
->assertNotSame($blocked, $user
->isBlocked());
// Ensure the user's langcode, preferred_langcode and
// preferred_admin_langcode are valid.
// $user->getPreferredLangcode() might fallback to default language if the
// user preferred language is not configured on the site. We just want to
// test if the value was imported correctly.
$language_manager = $this->container
->get('language_manager');
$default_langcode = $language_manager
->getDefaultLanguage()
->getId();
if ($langcode == '') {
$this
->assertSame('en', $user->langcode->value);
$this
->assertSame($default_langcode, $user->preferred_langcode->value);
$this
->assertSame($default_langcode, $user->preferred_admin_langcode->value);
}
elseif ($language_manager
->getLanguage($langcode) === NULL) {
$this
->assertSame($default_langcode, $user->langcode->value);
$this
->assertSame($default_langcode, $user->preferred_langcode->value);
$this
->assertSame($default_langcode, $user->preferred_admin_langcode->value);
}
else {
$this
->assertSame($langcode, $user->langcode->value);
$this
->assertSame($langcode, $user->preferred_langcode->value);
$this
->assertSame($langcode, $user->preferred_admin_langcode->value);
}
$this
->assertSame($timezone, $user
->getTimeZone());
$this
->assertSame($init, $user
->getInitialEmail());
$this
->assertSame($roles, $user
->getRoles());
}