diff --git a/core/modules/file/src/Tests/FileFieldDisplayTest.php b/core/modules/file/src/Tests/FileFieldDisplayTest.php index b25b514..76477ef 100644 --- a/core/modules/file/src/Tests/FileFieldDisplayTest.php +++ b/core/modules/file/src/Tests/FileFieldDisplayTest.php @@ -4,6 +4,7 @@ use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\file\Entity\File; +use Drupal\node\Entity\Node; /** * Tests the display of file fields in node and views. @@ -173,4 +174,49 @@ function testDescToggle() { $this->assertText(t('The description may be used as the label of the link to the file.')); } + /** + * Tests description display of File Field. + */ + function testDescriptionDefaultFileFieldDisplay() { + $field_name = strtolower($this->randomMachineName()); + $type_name = 'article'; + $field_storage_settings = array( + 'display_field' => '1', + 'display_default' => '1', + 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, + ); + $field_settings = array( + 'description_field' => '1', + ); + $widget_settings = array(); + $this->createFileField($field_name, 'node', $type_name, $field_storage_settings, $field_settings, $widget_settings); + + $test_file = $this->getTestFile('text'); + + // Create a new node with the uploaded file. + $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); + + // Add file description. + $description = 'This is the test file description'; + $this->drupalPostForm("node/$nid/edit", [$field_name . '[0][description]' => $description], t('Save and keep published')); + + // Load uncached node. + \Drupal::entityTypeManager()->getStorage('node')->resetCache([$nid]); + $node = Node::load($nid); + + // Test default formatter. + $this->drupalGet('node/' . $nid); + $this->assertFieldByXPath('//a[@href="' . $node->{$field_name}->entity->url() . '"]', $description); + + // Change formatter to "Table of files". + $display = \Drupal::entityTypeManager()->getStorage('entity_view_display')->load('node.' . $type_name . '.default'); + $display->setComponent($field_name, array( + 'label' => 'hidden', + 'type' => 'file_table', + ))->save(); + + $this->drupalGet('node/' . $nid); + $this->assertFieldByXPath('//a[@href="' . $node->{$field_name}->entity->url() . '"]', $description); + } + }