function MediaReferenceFieldHelpTest::testFieldCreationHelpText

Same name in other branches
  1. 8.9.x core/modules/media/tests/src/FunctionalJavascript/MediaReferenceFieldHelpTest.php \Drupal\Tests\media\FunctionalJavascript\MediaReferenceFieldHelpTest::testFieldCreationHelpText()
  2. 10 core/modules/media/tests/src/FunctionalJavascript/MediaReferenceFieldHelpTest.php \Drupal\Tests\media\FunctionalJavascript\MediaReferenceFieldHelpTest::testFieldCreationHelpText()
  3. 11.x core/modules/media/tests/src/FunctionalJavascript/MediaReferenceFieldHelpTest.php \Drupal\Tests\media\FunctionalJavascript\MediaReferenceFieldHelpTest::testFieldCreationHelpText()

Tests our custom help texts when creating a field.

See also

media_form_field_ui_field_storage_add_form_alter()

File

core/modules/media/tests/src/FunctionalJavascript/MediaReferenceFieldHelpTest.php, line 24

Class

MediaReferenceFieldHelpTest
Tests related to media reference fields.

Namespace

Drupal\Tests\media\FunctionalJavascript

Code

public function testFieldCreationHelpText() {
    $assert_session = $this->assertSession();
    $page = $this->getSession()
        ->getPage();
    $type = $this->drupalCreateContentType([
        'type' => 'foo',
    ]);
    $this->drupalGet("/admin/structure/types/manage/{$type->id()}/fields/add-field");
    $field_types = [
        'file',
        'image',
        'field_ui:entity_reference:media',
    ];
    $description_ids = array_map(function ($item) {
        return '#edit-description-' . Html::cleanCssIdentifier($item);
    }, $field_types);
    // Choose a boolean field, none of the description containers should be
    // visible.
    $assert_session->optionExists('edit-new-storage-type', 'boolean');
    $page->selectFieldOption('edit-new-storage-type', 'boolean');
    foreach ($description_ids as $description_id) {
        $this->assertFalse($assert_session->elementExists('css', $description_id)
            ->isVisible());
    }
    // Select each of the file, image, and media fields and verify their
    // descriptions are now visible and match the expected text.
    $help_text = 'Use Media reference fields for most files, images, audio, videos, and remote media. Use File or Image reference fields when creating your own media types, or for legacy files and images created before enabling the Media module.';
    foreach ($field_types as $field_name) {
        $assert_session->optionExists('edit-new-storage-type', $field_name);
        $page->selectFieldOption('edit-new-storage-type', $field_name);
        $field_description_element = $assert_session->elementExists('css', '#edit-description-' . Html::cleanCssIdentifier($field_name));
        $this->assertTrue($field_description_element->isVisible());
        $this->assertSame($help_text, $field_description_element->getText());
    }
}

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