function MigrateUserTest::testUserEntityTranslations

Tests the Drupal 7 user entity translations to Drupal 8 migration.

File

core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserTest.php, line 225

Class

MigrateUserTest
Users migration.

Namespace

Drupal\Tests\user\Kernel\Migrate\d7

Code

public function testUserEntityTranslations() {
    $manager = $this->container
        ->get('content_translation.manager');
    // Get the user and its translations.
    $user = User::load(2);
    $user_fr = $user->getTranslation('fr');
    $user_is = $user->getTranslation('is');
    // Test that fields translated with Entity Translation are migrated.
    $this->assertSame('99', $user->field_integer->value);
    $this->assertSame('9', $user_fr->field_integer->value);
    $this->assertSame('1', $user_is->field_integer->value);
    // Test that the French translation metadata is correctly migrated.
    $metadata_fr = $manager->getTranslationMetadata($user_fr);
    $this->assertSame('en', $metadata_fr->getSource());
    $this->assertSame('1', $metadata_fr->getAuthor()->uid->value);
    $this->assertSame('1531663916', $metadata_fr->getCreatedTime());
    $this->assertFalse($metadata_fr->isOutdated());
    $this->assertFalse($metadata_fr->isPublished());
    // Test that the Icelandic translation metadata is correctly migrated.
    $metadata_is = $manager->getTranslationMetadata($user_is);
    $this->assertSame('en', $metadata_is->getSource());
    $this->assertSame('2', $metadata_is->getAuthor()->uid->value);
    $this->assertSame('1531663925', $metadata_is->getCreatedTime());
    $this->assertTrue($metadata_is->isOutdated());
    $this->assertTrue($metadata_is->isPublished());
    // Test that untranslatable properties are the same as the source language.
    $this->assertSame($user->label(), $user_fr->label());
    $this->assertSame($user->label(), $user_is->label());
    $this->assertSame($user->getEmail(), $user_fr->getEmail());
    $this->assertSame($user->getEmail(), $user_is->getEmail());
    $this->assertSame($user->getPassword(), $user_fr->getPassword());
    $this->assertSame($user->getPassword(), $user_is->getPassword());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.