You are here

function NodeRSSContentTest::testNodeRSSContent in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/node/src/Tests/NodeRSSContentTest.php \Drupal\node\Tests\NodeRSSContentTest::testNodeRSSContent()

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

File

core/modules/node/src/Tests/NodeRSSContentTest.php, line 41
Contains \Drupal\node\Tests\NodeRSSContentTest.

Class

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

Namespace

Drupal\node\Tests

Code

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 = '<testElement>' . t('Value of testElement RSS element for node @nid.', array(
    '@nid' => $node
      ->id(),
  )) . '</testElement>';
  $test_ns = 'xmlns:drupaltest="http://example.com/test-namespace"';
  $this
    ->assertRaw($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.');
}