function RssFieldsTest::testRssFields

Same name and namespace in other branches
  1. 10 core/modules/views/tests/src/Kernel/Plugin/RssFieldsTest.php \Drupal\Tests\views\Kernel\Plugin\RssFieldsTest::testRssFields()

Tests correct processing of RSS fields.

This overlaps with \Drupal\Tests\views\Functional\Plugin\DisplayFeedTest to ensure that root-relative links also work in a scenario without subdirectory.

File

core/modules/views/tests/src/Kernel/Plugin/RssFieldsTest.php, line 52

Class

RssFieldsTest
Tests <a href="/api/drupal/core%21modules%21views%21src%21Plugin%21views%21row%21RssFields.php/class/RssFields/11.x" title="Renders an RSS item based on fields." class="local">\Drupal\views\Plugin\views\row\RssFields</a>.

Namespace

Drupal\Tests\views\Kernel\Plugin

Code

public function testRssFields() : void {
    $this->setUpCurrentUser([], [
        'access content',
    ]);
    $date = '1975-05-18';
    $node = $this->createNode([
        'type' => 'article',
        'title' => 'Article title',
        'created' => strtotime($date),
        'body' => [
            0 => [
                'value' => 'A paragraph',
                'format' => filter_default_format(),
            ],
        ],
    ]);
    $node_url = $node->toUrl()
        ->setAbsolute()
        ->toString();
    $renderer = $this->container
        ->get('renderer');
    $view = Views::getView('test_display_feed');
    $output = $view->preview('feed_2');
    $output = (string) $renderer->renderRoot($output);
    $this->assertStringContainsString('<link>' . $node_url . '</link>', $output);
    $this->assertStringContainsString('<pubDate>' . $date . '</pubDate>', $output);
}

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