/**
  * Tests RSS enclosure formatter display for RSS feeds.
  */
 function testFileFieldRSSContent()
 {
     $field_name = strtolower($this->randomMachineName());
     $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, 'node', $type_name, $field_settings, $instance_settings, $widget_settings);
     // RSS display must be added manually.
     $this->drupalGet("admin/structure/types/manage/{$type_name}/display");
     $edit = array("display_modes_custom[rss]" => '1');
     $this->drupalPostForm(NULL, $edit, t('Save'));
     // Change the format to 'RSS enclosure'.
     $this->drupalGet("admin/structure/types/manage/{$type_name}/display/rss");
     $edit = array("fields[{$field_name}][type]" => 'file_rss_enclosure');
     $this->drupalPostForm(NULL, $edit, t('Save'));
     // Create a new node with a file field set. Promote to frontpage
     // needs to be set so this node will appear in the RSS feed.
     $node = $this->drupalCreateNode(array('type' => $type_name, 'promote' => 1));
     $test_file = $this->getTestFile('text');
     // Create a new node with the uploaded file.
     $nid = $this->uploadNodeFile($test_file, $field_name, $node->id());
     // Get the uploaded file from the node.
     $node = node_load($nid, TRUE);
     $node_file = file_load($node->{$field_name}->target_id);
     // Check that the RSS enclosure appears in the RSS feed.
     $this->drupalGet('rss.xml');
     $uploaded_filename = str_replace('public://', '', $node_file->getFileUri());
     $test_element = array('key' => 'enclosure', 'value' => "", 'attributes' => array('url' => url("{$this->public_files_directory}/{$uploaded_filename}", array('absolute' => TRUE)), 'length' => $node_file->getSize(), 'type' => $node_file->getMimeType()));
     $this->assertRaw(format_xml_elements(array($test_element)), 'File field RSS enclosure is displayed when viewing the RSS feed.');
 }
Пример #2
0
 /**
  * Tests that terms added to nodes are displayed in core RSS feed.
  *
  * Create a node and assert that taxonomy terms appear in rss.xml.
  */
 function testTaxonomyRss()
 {
     // Create two taxonomy terms.
     $term1 = $this->createTerm($this->vocabulary);
     // RSS display must be added manually.
     $this->drupalGet("admin/structure/types/manage/article/display");
     $edit = array("display_modes_custom[rss]" => '1');
     $this->drupalPostForm(NULL, $edit, t('Save'));
     // Change the format to 'RSS category'.
     $this->drupalGet("admin/structure/types/manage/article/display/rss");
     $edit = array("fields[taxonomy_" . $this->vocabulary->id() . "][type]" => 'taxonomy_term_reference_rss_category');
     $this->drupalPostForm(NULL, $edit, t('Save'));
     // Post an article.
     $edit = array();
     $edit['title[0][value]'] = $this->randomMachineName();
     $edit[$this->field_name . '[]'] = $term1->id();
     $this->drupalPostForm('node/add/article', $edit, t('Save'));
     // Check that the term is displayed when the RSS feed is viewed.
     $this->drupalGet('rss.xml');
     $test_element = array('key' => 'category', 'value' => $term1->getName(), 'attributes' => array('domain' => $term1->url('canonical', array('absolute' => TRUE))));
     $this->assertRaw(format_xml_elements(array($test_element)), 'Term is displayed when viewing the rss feed.');
     // Test that the feed page exists for the term.
     $this->drupalGet("taxonomy/term/{$term1->id()}/feed");
     $this->assertRaw('<rss version="2.0"', "Feed page is RSS.");
 }
Пример #3
0
 /**
  * Ensures that a new node includes the custom data when added to an RSS feed.
  */
 function testNodeRSSContent()
 {
     // Create a node.
     $node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
     $this->drupalGet('rss.xml');
     // Check that content added in 'rss' view mode appear in RSS feed.
     $rss_only_content = t('Extra data that should appear only in the RSS feed for node !nid.', array('!nid' => $node->id()));
     $this->assertText($rss_only_content, 'Node content designated for RSS appear in RSS feed.');
     // Check that content added in view modes other than 'rss' doesn't
     // appear in RSS feed.
     $non_rss_content = t('Extra data that should appear everywhere except the RSS feed for node !nid.', array('!nid' => $node->id()));
     $this->assertNoText($non_rss_content, 'Node content not designed for RSS does not appear in RSS feed.');
     // Check that extra RSS elements and namespaces are added to RSS feed.
     $test_element = array('key' => 'testElement', 'value' => t('Value of testElement RSS element for node !nid.', array('!nid' => $node->id())));
     $test_ns = 'xmlns:drupaltest="http://example.com/test-namespace"';
     $this->assertRaw(format_xml_elements(array($test_element)), 'Extra RSS elements appear in RSS feed.');
     $this->assertRaw($test_ns, 'Extra namespaces appear in RSS feed.');
     // Check that content added in 'rss' view mode doesn't appear when
     // viewing node.
     $this->drupalGet('node/' . $node->id());
     $this->assertNoText($rss_only_content, 'Node content designed for RSS does not appear when viewing node.');
 }
Пример #4
0
 /**
  * Tests that terms added to nodes are displayed in core RSS feed.
  *
  * Create a node and assert that taxonomy terms appear in rss.xml.
  */
 function testTaxonomyRss()
 {
     // Create two taxonomy terms.
     $term1 = $this->createTerm($this->vocabulary);
     // RSS display must be added manually.
     $this->drupalGet("admin/structure/types/manage/article/display");
     $edit = array("display_modes_custom[rss]" => '1');
     $this->drupalPostForm(NULL, $edit, t('Save'));
     // Change the format to 'RSS category'.
     $this->drupalGet("admin/structure/types/manage/article/display/rss");
     $edit = array("fields[taxonomy_" . $this->vocabulary->id() . "][type]" => 'entity_reference_rss_category');
     $this->drupalPostForm(NULL, $edit, t('Save'));
     // Post an article.
     $edit = array();
     $edit['title[0][value]'] = $this->randomMachineName();
     $edit[$this->fieldName . '[]'] = $term1->id();
     $this->drupalPostForm('node/add/article', $edit, t('Save'));
     // Check that the term is displayed when the RSS feed is viewed.
     $this->drupalGet('rss.xml');
     $test_element = array('key' => 'category', 'value' => $term1->getName(), 'attributes' => array('domain' => $term1->url('canonical', array('absolute' => TRUE))));
     $this->assertRaw(format_xml_elements(array($test_element)), 'Term is displayed when viewing the rss feed.');
     // Test that the feed page exists for the term.
     $this->drupalGet("taxonomy/term/{$term1->id()}/feed");
     $this->assertRaw('<rss version="2.0"', "Feed page is RSS.");
     // Check that the "Exception value" is disabled by default.
     $this->drupalGet('taxonomy/term/all/feed');
     $this->assertResponse(404);
     // Set the exception value to 'all'.
     $view = Views::getView('taxonomy_term');
     $arguments = $view->getDisplay()->getOption('arguments');
     $arguments['tid']['exception']['value'] = 'all';
     $view->getDisplay()->overrideOption('arguments', $arguments);
     $view->storage->save();
     // Check the article is shown in the feed.
     $node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
     $raw_xml = format_xml_elements([['key' => 'title', 'value' => $node->label()]]);
     $this->drupalGet('taxonomy/term/all/feed');
     $this->assertRaw($raw_xml);
     // Unpublish the article and check that it is not shown in the feed.
     $node->setPublished(FALSE)->save();
     $this->drupalGet('taxonomy/term/all/feed');
     $this->assertNoRaw($raw_xml);
 }
Пример #5
0
/**
* Default theme function for all RSS rows.  Gives us a node variable to use in views templates.
*/
function phptemplate_preprocess_views_view_row_rss(&$vars)
{
    $view =& $vars['view'];
    $options =& $vars['options'];
    $item =& $vars['row'];
    // Use the [id] of the returned results to determine the nid in [results]
    $result =& $vars['view']->result;
    $id =& $vars['id'];
    $node = node_load($result[$id - 1]->nid);
    $vars['title'] = check_plain($item->title);
    $vars['link'] = check_url($item->link);
    $vars['description'] = check_plain($item->description);
    //$vars['description'] = check_plain($node->teaser);
    $vars['node'] = $node;
    $vars['item_elements'] = empty($item->elements) ? '' : format_xml_elements($item->elements);
}