<?php
namespace Drupal\file\Tests;
class FileFieldRSSContentTest extends FileFieldTestBase {
public static function getInfo() {
return array(
'name' => 'File field RSS content',
'description' => 'Ensure that files added to nodes appear correctly in RSS feeds.',
'group' => 'File',
);
}
function testFileFieldRSSContent() {
$field_name = strtolower($this
->randomName());
$type_name = 'article';
$field_settings = array(
'display_field' => '1',
'display_default' => '1',
);
$instance_settings = array(
'description_field' => '1',
);
$widget_settings = array();
$this
->createFileField($field_name, $type_name, $field_settings, $instance_settings, $widget_settings);
$field = field_info_field($field_name);
$instance = field_info_instance('node', $field_name, $type_name);
$this
->drupalGet("admin/structure/types/manage/{$type_name}/display");
$edit = array(
"view_modes_custom[rss]" => '1',
);
$this
->drupalPost(NULL, $edit, t('Save'));
$this
->drupalGet("admin/structure/types/manage/{$type_name}/display/rss");
$edit = array(
"fields[{$field_name}][type]" => 'file_rss_enclosure',
);
$this
->drupalPost(NULL, $edit, t('Save'));
$node = $this
->drupalCreateNode(array(
'type' => $type_name,
'promote' => 1,
));
$test_file = $this
->getTestFile('text');
$nid = $this
->uploadNodeFile($test_file, $field_name, $node->nid);
$node = node_load($nid, TRUE);
$node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
$this
->drupalGet('rss.xml');
$uploaded_filename = str_replace('public://', '', $node_file->uri);
$test_element = array(
'key' => 'enclosure',
'value' => "",
'attributes' => array(
'url' => url("{$this->public_files_directory}/{$uploaded_filename}", array(
'absolute' => TRUE,
)),
'length' => $node_file->filesize,
'type' => $node_file->filemime,
),
);
$this
->assertRaw(format_xml_elements(array(
$test_element,
)), 'File field RSS enclosure is displayed when viewing the RSS feed.');
}
}