You are here

class ContentTranslationModuleInstallTest in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/content_translation/tests/src/Kernel/ContentTranslationModuleInstallTest.php \Drupal\Tests\content_translation\Kernel\ContentTranslationModuleInstallTest
  2. 9 core/modules/content_translation/tests/src/Kernel/ContentTranslationModuleInstallTest.php \Drupal\Tests\content_translation\Kernel\ContentTranslationModuleInstallTest

Tests content translation for modules that provide translatable bundles.

@group content_translation

Hierarchy

Expanded class hierarchy of ContentTranslationModuleInstallTest

File

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

Namespace

Drupal\Tests\content_translation\Kernel
View source
class ContentTranslationModuleInstallTest extends KernelTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'content_translation',
    'content_translation_test',
    'entity_test',
    'language',
    'user',
  ];

  /**
   * The content translation manager.
   *
   * @var \Drupal\content_translation\ContentTranslationManagerInterface
   */
  protected $contentTranslationManager;

  /**
   * The language code of the source language for this test.
   *
   * @var string
   */
  protected $sourceLangcode = 'en';

  /**
   * The language code of the translation language for this test.
   *
   * @var string
   */
  protected $translationLangcode = 'af';

  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $this
      ->installEntitySchema('entity_test_with_bundle');
    ConfigurableLanguage::createFromLangcode($this->translationLangcode)
      ->save();
    $this->contentTranslationManager = $this->container
      ->get('content_translation.manager');
  }

  /**
   * Tests that content translation fields are created upon module installation.
   */
  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());
  }

}

Members