function MediaReferenceFieldHelpTest::testFieldCreationHelpText

Same name in other branches
  1. 9 core/modules/media/tests/src/FunctionalJavascript/MediaReferenceFieldHelpTest.php \Drupal\Tests\media\FunctionalJavascript\MediaReferenceFieldHelpTest::testFieldCreationHelpText()
  2. 8.9.x 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 32

Class

MediaReferenceFieldHelpTest
Tests related to media reference fields.

Namespace

Drupal\Tests\media\FunctionalJavascript

Code

public function testFieldCreationHelpText() : void {
    $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_groups = [
        'file_upload',
        'field_ui:entity_reference:media',
    ];
    $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 installing the Media module.';
    // Choose a boolean field, none of the description containers should be
    // visible.
    $assert_session->elementExists('css', "[name='new_storage_type'][value='boolean']");
    $page->find('css', "[name='new_storage_type'][value='boolean']")
        ->getParent()
        ->click();
    $page->pressButton('Continue');
    $assert_session->pageTextNotContains($help_text);
    $page->pressButton('Back');
    // Select each of the Reference, File upload field groups and verify their
    // descriptions are now visible and match the expected text.
    foreach ($field_groups as $field_group) {
        $assert_session->elementExists('css', "[name='new_storage_type'][value='{$field_group}']");
        $page->find('css', "[name='new_storage_type'][value='{$field_group}']")
            ->getParent()
            ->click();
        $page->pressButton('Continue');
        $assert_session->pageTextContains($help_text);
        $page->pressButton('Back');
    }
}

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