function ContentTranslationWorkflowsTest::setupEntity

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

Creates a test entity and translate it.

Parameters

Drupal\User\UserInterface|null $user: (optional) The entity owner.

2 calls to ContentTranslationWorkflowsTest::setupEntity()
ContentTranslationWorkflowsTest::setUp in core/modules/content_translation/tests/src/Functional/ContentTranslationWorkflowsTest.php
ContentTranslationWorkflowsTest::testWorkflows in core/modules/content_translation/tests/src/Functional/ContentTranslationWorkflowsTest.php
Tests simple and editorial translation workflows.

File

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

Class

ContentTranslationWorkflowsTest
Tests the content translation workflows for the test entity.

Namespace

Drupal\Tests\content_translation\Functional

Code

protected function setupEntity(UserInterface $user = NULL) {
    $default_langcode = $this->langcodes[0];
    // Create a test entity.
    $user = $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);
    // Create a translation that is not published to test view access.
    $this->drupalLogin($this->translator);
    $add_translation_url = Url::fromRoute("entity.{$this->entityTypeId}.content_translation_add", [
        $this->entityTypeId => $id,
        'source' => $default_langcode,
        'target' => $this->langcodes[2],
    ]);
    $edit = [
        'name[0][value]' => 'translation name',
        'content_translation[status]' => FALSE,
    ];
    $this->drupalGet($add_translation_url);
    $this->submitForm($edit, 'Save');
    $storage->resetCache([
        $id,
    ]);
    $this->entity = $storage->load($id);
    $this->rebuildContainer();
}

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