3 namespace Drupal\Tests\file\Functional;
5 use Drupal\file\Entity\File;
8 * Ensure that files added to nodes appear correctly in RSS feeds.
12 class FileFieldRSSContentTest extends FileFieldTestBase {
19 public static $modules = ['node', 'views'];
22 * Tests RSS enclosure formatter display for RSS feeds.
24 public function testFileFieldRSSContent() {
25 $node_storage = $this->container->get('entity.manager')->getStorage('node');
26 $field_name = strtolower($this->randomMachineName());
27 $type_name = 'article';
29 $this->createFileField($field_name, 'node', $type_name);
31 // RSS display must be added manually.
32 $this->drupalGet("admin/structure/types/manage/$type_name/display");
34 "display_modes_custom[rss]" => '1',
36 $this->drupalPostForm(NULL, $edit, t('Save'));
38 // Change the format to 'RSS enclosure'.
39 $this->drupalGet("admin/structure/types/manage/$type_name/display/rss");
41 "fields[$field_name][type]" => 'file_rss_enclosure',
42 "fields[$field_name][region]" => 'content',
44 $this->drupalPostForm(NULL, $edit, t('Save'));
46 // Create a new node with a file field set. Promote to frontpage
47 // needs to be set so this node will appear in the RSS feed.
48 $node = $this->drupalCreateNode(['type' => $type_name, 'promote' => 1]);
49 $test_file = $this->getTestFile('text');
51 // Create a new node with the uploaded file.
52 $nid = $this->uploadNodeFile($test_file, $field_name, $node->id());
54 // Get the uploaded file from the node.
55 $node_storage->resetCache([$nid]);
56 $node = $node_storage->load($nid);
57 $node_file = File::load($node->{$field_name}->target_id);
59 // Check that the RSS enclosure appears in the RSS feed.
60 $this->drupalGet('rss.xml');
61 $uploaded_filename = str_replace('public://', '', $node_file->getFileUri());
63 'enclosure[@url="%s"][@length="%s"][@type="%s"]',
64 file_create_url("public://$uploaded_filename", ['absolute' => TRUE]),
65 $node_file->getSize(),
66 $node_file->getMimeType()
68 $this->assertNotNull($this->getSession()->getDriver()->find('xpath', $selector), 'File field RSS enclosure is displayed when viewing the RSS feed.');