function ContentTranslationModuleInstallTest::testFieldUpdates

Same name in other branches
  1. 8.9.x core/modules/content_translation/tests/src/Kernel/ContentTranslationModuleInstallTest.php \Drupal\Tests\content_translation\Kernel\ContentTranslationModuleInstallTest::testFieldUpdates()
  2. 10 core/modules/content_translation/tests/src/Kernel/ContentTranslationModuleInstallTest.php \Drupal\Tests\content_translation\Kernel\ContentTranslationModuleInstallTest::testFieldUpdates()
  3. 11.x core/modules/content_translation/tests/src/Kernel/ContentTranslationModuleInstallTest.php \Drupal\Tests\content_translation\Kernel\ContentTranslationModuleInstallTest::testFieldUpdates()

Tests that content translation fields are created upon module installation.

File

core/modules/content_translation/tests/src/Kernel/ContentTranslationModuleInstallTest.php, line 63

Class

ContentTranslationModuleInstallTest
Tests content translation for modules that provide translatable bundles.

Namespace

Drupal\Tests\content_translation\Kernel

Code

public function testFieldUpdates() {
    // The module ships a translatable bundle of the 'entity_test_with_bundle'
    // entity type.
    $this->installConfig([
        'content_translation_test',
    ]);
    $entity = EntityTestWithBundle::create([
        'type' => 'test',
        'langcode' => $this->sourceLangcode,
    ]);
    $entity->save();
    // Add a translation with some translation metadata.
    $translation = $entity->addTranslation($this->translationLangcode);
    $translation_metadata = $this->contentTranslationManager
        ->getTranslationMetadata($translation);
    $translation_metadata->setSource($this->sourceLangcode)
        ->setOutdated(TRUE);
    $translation->save();
    // Make sure the translation metadata has been saved correctly.
    $entity = EntityTestWithBundle::load($entity->id());
    $translation = $entity->getTranslation($this->translationLangcode);
    $translation_metadata = $this->contentTranslationManager
        ->getTranslationMetadata($translation);
    $this->assertSame($this->sourceLangcode, $translation_metadata->getSource());
    $this->assertTrue($translation_metadata->isOutdated());
}

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