function ConfigTranslationUiTest::testNodeFieldTranslation

Same name in other branches
  1. 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 1041

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->drupalPostForm(NULL, $form_values, 'Save translation');
    $this->assertText('Successfully saved French translation.');
    // Check that the translations are saved.
    $this->clickLink('Add');
    $this->assertRaw('FR label');
}

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