You are here

protected function ContentTranslationContextualLinksTest::setUp in Drupal 10

Same name in this branch
  1. 10 core/modules/content_translation/tests/src/Functional/ContentTranslationContextualLinksTest.php \Drupal\Tests\content_translation\Functional\ContentTranslationContextualLinksTest::setUp()
  2. 10 core/modules/content_translation/tests/src/FunctionalJavascript/ContentTranslationContextualLinksTest.php \Drupal\Tests\content_translation\FunctionalJavascript\ContentTranslationContextualLinksTest::setUp()
Same name and namespace in other branches
  1. 8 core/modules/content_translation/tests/src/Functional/ContentTranslationContextualLinksTest.php \Drupal\Tests\content_translation\Functional\ContentTranslationContextualLinksTest::setUp()
  2. 9 core/modules/content_translation/tests/src/Functional/ContentTranslationContextualLinksTest.php \Drupal\Tests\content_translation\Functional\ContentTranslationContextualLinksTest::setUp()

File

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

Class

ContentTranslationContextualLinksTest
Tests that contextual links are available for content translation.

Namespace

Drupal\Tests\content_translation\Functional

Code

protected function setUp() : void {
  parent::setUp();

  // Set up an additional language.
  $this->langcodes = [
    \Drupal::languageManager()
      ->getDefaultLanguage()
      ->getId(),
    'es',
  ];
  ConfigurableLanguage::createFromLangcode('es')
    ->save();

  // Create a content type.
  $this->bundle = $this
    ->randomMachineName();
  $this->contentType = $this
    ->drupalCreateContentType([
    'type' => $this->bundle,
  ]);

  // Add a field to the content type. The field is not yet translatable.
  FieldStorageConfig::create([
    'field_name' => 'field_test_text',
    'entity_type' => 'node',
    'type' => 'text',
    'cardinality' => 1,
  ])
    ->save();
  FieldConfig::create([
    'entity_type' => 'node',
    'field_name' => 'field_test_text',
    'bundle' => $this->bundle,
    'label' => 'Test text-field',
  ])
    ->save();
  $this->container
    ->get('entity_display.repository')
    ->getFormDisplay('node', $this->bundle)
    ->setComponent('field_test_text', [
    'type' => 'text_textfield',
    'weight' => 0,
  ])
    ->save();

  // Create a translator user.
  $permissions = [
    'access contextual links',
    'administer nodes',
    "edit any {$this->bundle} content",
    'translate any entity',
  ];
  $this->translator = $this
    ->drupalCreateUser($permissions);
}