You are here

public function ConfigTranslationUiTest::testNodeFieldTranslation in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php \Drupal\Tests\config_translation\Functional\ConfigTranslationUiTest::testNodeFieldTranslation()
  2. 9 core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php \Drupal\Tests\config_translation\Functional\ConfigTranslationUiTest::testNodeFieldTranslation()

Tests field translation for node fields.

File

core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php, line 1057

Class

ConfigTranslationUiTest
Translate settings and entities to various languages.

Namespace

Drupal\Tests\config_translation\Functional

Code

public function testNodeFieldTranslation() {
  NodeType::create([
    'type' => 'article',
    'name' => 'Article',
  ])
    ->save();
  $field_name = 'translatable_field';
  $field_storage = FieldStorageConfig::create([
    'field_name' => $field_name,
    'entity_type' => 'node',
    'type' => 'text',
  ]);
  $field_storage
    ->setSetting('translatable_storage_setting', 'translatable_storage_setting');
  $field_storage
    ->save();
  $field = FieldConfig::create([
    'field_name' => $field_name,
    'entity_type' => 'node',
    'bundle' => 'article',
  ]);
  $field
    ->save();
  $this
    ->drupalLogin($this->translatorUser);
  $this
    ->drupalGet("/entity_test/structure/article/fields/node.article.{$field_name}/translate");
  $this
    ->clickLink('Add');
  $form_values = [
    'translation[config_names][field.field.node.article.translatable_field][description]' => 'FR Help text.',
    'translation[config_names][field.field.node.article.translatable_field][label]' => 'FR label',
  ];
  $this
    ->submitForm($form_values, 'Save translation');
  $this
    ->assertSession()
    ->pageTextContains('Successfully saved French translation.');

  // Check that the translations are saved.
  $this
    ->clickLink('Add');
  $this
    ->assertSession()
    ->responseContains('FR label');
}