public function FileFieldDisplayTest::testDescToggle in Drupal 8
Same name and namespace in other branches
- 9 core/modules/file/tests/src/Functional/FileFieldDisplayTest.php \Drupal\Tests\file\Functional\FileFieldDisplayTest::testDescToggle()
- 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 151
Class
- FileFieldDisplayTest
- Tests the display of file fields in node and views.
Namespace
Drupal\Tests\file\FunctionalCode
public function testDescToggle() {
$type_name = 'test';
$field_type = 'file';
$field_name = strtolower($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
->drupalPostForm('admin/structure/types/add', $edit, t('Save and manage fields'));
$edit = [
'new_storage_type' => $field_type,
'field_name' => $field_name,
'label' => $this
->randomString(),
];
$this
->drupalPostForm('/admin/structure/types/manage/' . $type_name . '/fields/add-field', $edit, t('Save and continue'));
$this
->drupalPostForm(NULL, [], t('Save field settings'));
// Ensure the description field is selected on the field instance settings
// form. That's what this test is all about.
$edit = [
'settings[description_field]' => TRUE,
];
$this
->drupalPostForm(NULL, $edit, t('Save settings'));
// 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
->drupalPostForm('node/add/' . $type_name, $edit, t('Save'));
$node = $this
->drupalGetNodeByTitle($title);
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->assertText(t('The description may be used as the label of the link to the file.'));
}