You are here

public function ManageFieldsFunctionalTest::testHelpDescriptions in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php \Drupal\Tests\field_ui\Functional\ManageFieldsFunctionalTest::testHelpDescriptions()
  2. 10 core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php \Drupal\Tests\field_ui\Functional\ManageFieldsFunctionalTest::testHelpDescriptions()

Tests that help descriptions render valid HTML.

File

core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php, line 777

Class

ManageFieldsFunctionalTest
Tests the Field UI "Manage fields" screen.

Namespace

Drupal\Tests\field_ui\Functional

Code

public function testHelpDescriptions() {

  // Create an image field
  FieldStorageConfig::create([
    'field_name' => 'field_image',
    'entity_type' => 'node',
    'type' => 'image',
  ])
    ->save();
  FieldConfig::create([
    'field_name' => 'field_image',
    'entity_type' => 'node',
    'label' => 'Image',
    'bundle' => 'article',
  ])
    ->save();
  \Drupal::service('entity_display.repository')
    ->getFormDisplay('node', 'article')
    ->setComponent('field_image')
    ->save();
  $edit = [
    'description' => '<strong>Test with an upload field.',
  ];
  $this
    ->drupalGet('admin/structure/types/manage/article/fields/node.article.field_image');
  $this
    ->submitForm($edit, 'Save settings');

  // Check that hook_field_widget_single_element_form_alter() does believe
  // this is the default value form.
  $this
    ->drupalGet('admin/structure/types/manage/article/fields/node.article.field_tags');
  $this
    ->assertSession()
    ->pageTextContains('From hook_field_widget_single_element_form_alter(): Default form is true.');
  $edit = [
    'description' => '<em>Test with a non upload field.',
  ];
  $this
    ->drupalGet('admin/structure/types/manage/article/fields/node.article.field_tags');
  $this
    ->submitForm($edit, 'Save settings');
  $this
    ->drupalGet('node/add/article');
  $this
    ->assertSession()
    ->responseContains('<strong>Test with an upload field.</strong>');
  $this
    ->assertSession()
    ->responseContains('<em>Test with a non upload field.</em>');
}