function NodeRSSContentTest::testNodeRSSContent

Same name in other branches
  1. 9 core/modules/node/tests/src/Functional/NodeRSSContentTest.php \Drupal\Tests\node\Functional\NodeRSSContentTest::testNodeRSSContent()
  2. 8.9.x core/modules/node/tests/src/Functional/NodeRSSContentTest.php \Drupal\Tests\node\Functional\NodeRSSContentTest::testNodeRSSContent()
  3. 11.x core/modules/node/tests/src/Functional/NodeRSSContentTest.php \Drupal\Tests\node\Functional\NodeRSSContentTest::testNodeRSSContent()

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

File

core/modules/node/tests/src/Functional/NodeRSSContentTest.php, line 52

Class

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

Namespace

Drupal\Tests\node\Functional

Code

public function testNodeRSSContent() : void {
    // Create a node.
    $node = $this->drupalCreateNode([
        'type' => 'article',
        'promote' => 1,
    ]);
    $this->drupalGet('rss.xml');
    // Check that content added in 'rss' view mode appear in RSS feed.
    $rss_only_content = 'Extra data that should appear only in the RSS feed for node ' . $node->id() . '.';
    $this->assertSession()
        ->responseContains($rss_only_content);
    // Check that content added in view modes other than 'rss' doesn't
    // appear in RSS feed.
    $non_rss_content = 'Extra data that should appear everywhere except the RSS feed for node ' . $node->id() . '.';
    $this->assertSession()
        ->responseNotContains($non_rss_content);
    // Check that extra RSS elements and namespaces are added to RSS feed.
    $test_element = "<testElement>Value of testElement RSS element for node {$node->id()}.</testElement>";
    $test_ns = 'xmlns:test="http://example.com/test-namespace"';
    $this->assertSession()
        ->responseContains($test_element);
    $this->assertSession()
        ->responseContains($test_ns);
    // Check that content added in 'rss' view mode doesn't appear when
    // viewing node.
    $this->drupalGet('node/' . $node->id());
    $this->assertSession()
        ->responseNotContains($rss_only_content);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.