1 node.test NodeRSSContentTestCase::testNodeRSSContent()

Ensures that a new node includes the custom data when added to an RSS feed.

File

core/modules/node/tests/node.test, line 1453
Tests for node.module.

Class

NodeRSSContentTestCase
Ensures that data added to nodes by other modules appears in RSS feeds.

Code

function testNodeRSSContent() {
  // Create a node.
  $node = $this->backdropCreateNode(array('type' => 'post', 'promote' => 1));

  $this->backdropGet('rss.xml');

  // Check that content added in 'rss' display 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->nid));
  $this->assertText($rss_only_content, 'Node content designated for RSS appear in RSS feed.');

  // Check that it renders just the xml of the feed not the html.
  $this->assertNoRaw('<!DOCTYPE html>', 'Node content in the feed is just XML not HTML.');

  // Check that content added in display 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->nid));
  $this->assertNoText($non_rss_content, "Node content not designed for RSS doesn't 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->nid)),
  );
  $test_ns = 'xmlns:backdroptest="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' display mode doesn't appear when
  // viewing node.
  $this->backdropGet("node/$node->nid");
  $this->assertNoText($rss_only_content, "Node content designed for RSS doesn't appear when viewing node.");

  // Check that the node feed page does not try to interpret additional path
  // components as arguments for node_feed() and returns default content.
  $this->backdropGet('rss.xml/' . $this->randomName() . '/' . $this->randomName());
  $this->assertText($rss_only_content, 'Ignore page arguments when delivering rss.xml.');
}