FileFieldRSSContentTest.php in Drupal 10
File
core/modules/file/tests/src/Functional/FileFieldRSSContentTest.php
View source
<?php
namespace Drupal\Tests\file\Functional;
use Drupal\file\Entity\File;
class FileFieldRSSContentTest extends FileFieldTestBase {
protected static $modules = [
'node',
'views',
];
protected $defaultTheme = 'stark';
public function testFileFieldRSSContent() {
$node_storage = $this->container
->get('entity_type.manager')
->getStorage('node');
$field_name = strtolower($this
->randomMachineName());
$type_name = 'article';
$this
->createFileField($field_name, 'node', $type_name);
$this
->drupalGet("admin/structure/types/manage/{$type_name}/display");
$edit = [
"display_modes_custom[rss]" => '1',
];
$this
->submitForm($edit, 'Save');
$this
->drupalGet("admin/structure/types/manage/{$type_name}/display/rss");
$edit = [
"fields[{$field_name}][type]" => 'file_rss_enclosure',
"fields[{$field_name}][region]" => 'content',
];
$this
->submitForm($edit, 'Save');
$node = $this
->drupalCreateNode([
'type' => $type_name,
'promote' => 1,
]);
$test_file = $this
->getTestFile('text');
$nid = $this
->uploadNodeFile($test_file, $field_name, $node
->id());
$node_storage
->resetCache([
$nid,
]);
$node = $node_storage
->load($nid);
$node_file = File::load($node->{$field_name}->target_id);
$this
->drupalGet('rss.xml');
$selector = sprintf('//enclosure[@url="%s" and @length="%s" and @type="%s"]', $node_file
->createFileUrl(FALSE), $node_file
->getSize(), $node_file
->getMimeType());
$this
->assertNotEmpty($this
->getSession()
->getDriver()
->find($selector), 'File field RSS enclosure is displayed when viewing the RSS feed.');
}
}