You are here

public function FormTest::testLabelOnMultiValueFields in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/field/src/Tests/FormTest.php \Drupal\field\Tests\FormTest::testLabelOnMultiValueFields()

Tests the form display of the label for multi-value fields.

File

core/modules/field/src/Tests/FormTest.php, line 663
Contains \Drupal\field\Tests\FormTest.

Class

FormTest
Tests field form handling.

Namespace

Drupal\field\Tests

Code

public function testLabelOnMultiValueFields() {
  $user = $this
    ->drupalCreateUser([
    'administer entity_test content',
  ]);
  $this
    ->drupalLogin($user);
  FieldStorageConfig::create([
    'entity_type' => 'entity_test_base_field_display',
    'field_name' => 'foo',
    'type' => 'text',
    'cardinality' => FieldStorageConfig::CARDINALITY_UNLIMITED,
  ])
    ->save();
  FieldConfig::create([
    'entity_type' => 'entity_test_base_field_display',
    'bundle' => 'bar',
    'field_name' => 'foo',
    // Set a dangerous label to test XSS filtering.
    'label' => "<script>alert('a configurable field');</script>",
  ])
    ->save();
  EntityFormDisplay::create([
    'targetEntityType' => 'entity_test_base_field_display',
    'bundle' => 'bar',
    'mode' => 'default',
  ])
    ->setComponent('foo', [
    'type' => 'text_textfield',
  ])
    ->enable()
    ->save();
  $entity = EntityTestBaseFieldDisplay::create([
    'type' => 'bar',
  ]);
  $entity
    ->save();
  $this
    ->drupalGet('entity_test_base_field_display/manage/' . $entity
    ->id());
  $this
    ->assertResponse(200);
  $this
    ->assertText('A field with multiple values');

  // Test if labels were XSS filtered.
  $this
    ->assertEscaped("<script>alert('a configurable field');</script>");
}