function NodeTranslationUITest::testDetailsTitleIsNotEscaped

Same name in other branches
  1. 9 core/modules/node/tests/src/Functional/NodeTranslationUITest.php \Drupal\Tests\node\Functional\NodeTranslationUITest::testDetailsTitleIsNotEscaped()
  2. 8.9.x core/modules/node/tests/src/Functional/NodeTranslationUITest.php \Drupal\Tests\node\Functional\NodeTranslationUITest::testDetailsTitleIsNotEscaped()
  3. 11.x core/modules/node/tests/src/Functional/NodeTranslationUITest.php \Drupal\Tests\node\Functional\NodeTranslationUITest::testDetailsTitleIsNotEscaped()

Tests title is not escaped (but XSS-filtered) for details form element.

File

core/modules/node/tests/src/Functional/NodeTranslationUITest.php, line 557

Class

NodeTranslationUITest
Tests the Node Translation UI.

Namespace

Drupal\Tests\node\Functional

Code

public function testDetailsTitleIsNotEscaped() : void {
    // Create an image field.
    \Drupal::service('module_installer')->install([
        'image',
    ]);
    FieldStorageConfig::create([
        'entity_type' => 'node',
        'field_name' => 'field_image',
        'type' => 'image',
    ])->save();
    FieldConfig::create([
        'entity_type' => 'node',
        'field_name' => 'field_image',
        'bundle' => 'article',
        'translatable' => TRUE,
    ])->save();
    $this->drupalLogin($this->administrator);
    // Make the image field a multi-value field in order to display a
    // details form element.
    $edit = [
        'field_storage[subform][cardinality_number]' => 2,
    ];
    $this->drupalGet('admin/structure/types/manage/article/fields/node.article.field_image');
    $this->submitForm($edit, 'Save');
    // Enable the display of the image field.
    EntityFormDisplay::load('node.article.default')->setComponent('field_image', [
        'region' => 'content',
    ])
        ->save();
    // Make the image field non-translatable.
    static::setFieldTranslatable('node', 'article', 'field_image', FALSE);
    // Create a node.
    $nid = $this->createEntity([
        'title' => 'Node with multi-value image field en title',
    ], 'en');
    // Add a French translation and assert the title markup is not escaped.
    $this->drupalGet("node/{$nid}/translations/add/en/fr");
    $markup = 'Image <span class="translation-entity-all-languages">(all languages)</span>';
    $this->assertSession()
        ->assertNoEscaped($markup);
    $this->assertSession()
        ->responseContains($markup);
}

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