You are here

protected function ContentTranslationWorkflowsTest::setupEntity in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/content_translation/tests/src/Functional/ContentTranslationWorkflowsTest.php \Drupal\Tests\content_translation\Functional\ContentTranslationWorkflowsTest::setupEntity()

Creates a test entity and translate it.

1 call to ContentTranslationWorkflowsTest::setupEntity()
ContentTranslationWorkflowsTest::setUp in core/modules/content_translation/tests/src/Functional/ContentTranslationWorkflowsTest.php

File

core/modules/content_translation/tests/src/Functional/ContentTranslationWorkflowsTest.php, line 64

Class

ContentTranslationWorkflowsTest
Tests the content translation workflows for the test entity.

Namespace

Drupal\Tests\content_translation\Functional

Code

protected function setupEntity() {
  $default_langcode = $this->langcodes[0];

  // Create a test entity.
  $user = $this
    ->drupalCreateUser();
  $values = [
    'name' => $this
      ->randomMachineName(),
    'user_id' => $user
      ->id(),
    $this->fieldName => [
      [
        'value' => $this
          ->randomMachineName(16),
      ],
    ],
  ];
  $id = $this
    ->createEntity($values, $default_langcode);
  $storage = $this->container
    ->get('entity_type.manager')
    ->getStorage($this->entityTypeId);
  $storage
    ->resetCache([
    $id,
  ]);
  $this->entity = $storage
    ->load($id);

  // Create a translation.
  $this
    ->drupalLogin($this->translator);
  $add_translation_url = Url::fromRoute("entity.{$this->entityTypeId}.content_translation_add", [
    $this->entityTypeId => $this->entity
      ->id(),
    'source' => $default_langcode,
    'target' => $this->langcodes[2],
  ]);
  $this
    ->drupalPostForm($add_translation_url, [], t('Save'));
  $this
    ->rebuildContainer();
}