function FileFieldDisplayTest::testDescToggle

Same name and namespace in other branches
  1. 9 core/modules/file/tests/src/Functional/FileFieldDisplayTest.php \Drupal\Tests\file\Functional\FileFieldDisplayTest::testDescToggle()
  2. 8.9.x core/modules/file/tests/src/Functional/FileFieldDisplayTest.php \Drupal\Tests\file\Functional\FileFieldDisplayTest::testDescToggle()
  3. 10 core/modules/file/tests/src/Functional/FileFieldDisplayTest.php \Drupal\Tests\file\Functional\FileFieldDisplayTest::testDescToggle()

Tests description toggle for field instance configuration.

File

core/modules/file/tests/src/Functional/FileFieldDisplayTest.php, line 162

Class

FileFieldDisplayTest
Tests the display of file fields in node and views.

Namespace

Drupal\Tests\file\Functional

Code

public function testDescToggle() : void {
    $type_name = 'test';
    $field_type = 'file';
    $field_name = $this->randomMachineName();
    // Use the UI to add a new content type that also contains a file field.
    $edit = [
        'name' => $type_name,
        'type' => $type_name,
    ];
    $this->drupalGet('admin/structure/types/add');
    $this->submitForm($edit, 'Save and manage fields');
    $field_edit = [
        'settings[description_field]' => TRUE,
    ];
    $this->fieldUIAddNewField('/admin/structure/types/manage/' . $type_name, $field_name, $this->randomString(), $field_type, [], $field_edit);
    // Add a node of our new type and upload a file to it.
    $file = current($this->drupalGetTestFiles('text'));
    $title = $this->randomString();
    $edit = [
        'title[0][value]' => $title,
        'files[field_' . $field_name . '_0]' => \Drupal::service('file_system')->realpath($file->uri),
    ];
    $this->drupalGet('node/add/' . $type_name);
    $this->submitForm($edit, 'Save');
    $node = $this->drupalGetNodeByTitle($title);
    $this->drupalGet('node/' . $node->id() . '/edit');
    $this->assertSession()
        ->pageTextContains('The description may be used as the label of the link to the file.');
}

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