function DisplayFeedTest::testFeedFieldOutput

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Functional/Plugin/DisplayFeedTest.php \Drupal\Tests\views\Functional\Plugin\DisplayFeedTest::testFeedFieldOutput()
  2. 8.9.x core/modules/views/tests/src/Functional/Plugin/DisplayFeedTest.php \Drupal\Tests\views\Functional\Plugin\DisplayFeedTest::testFeedFieldOutput()
  3. 10 core/modules/views/tests/src/Functional/Plugin/DisplayFeedTest.php \Drupal\Tests\views\Functional\Plugin\DisplayFeedTest::testFeedFieldOutput()

Tests the rendered output for fields display.

File

core/modules/views/tests/src/Functional/Plugin/DisplayFeedTest.php, line 119

Class

DisplayFeedTest
Tests the feed display plugin.

Namespace

Drupal\Tests\views\Functional\Plugin

Code

public function testFeedFieldOutput() : void {
    $this->drupalCreateContentType([
        'type' => 'page',
    ]);
    // Verify a title with HTML entities is properly escaped.
    $node_title = 'This "cool" & "neat" article\'s title';
    $node = $this->drupalCreateNode([
        'title' => $node_title,
        'body' => [
            0 => [
                'value' => 'A paragraph',
                'format' => filter_default_format(),
            ],
        ],
    ]);
    // Create an alias to verify that outbound processing runs on the link and
    // ensure that the node actually contains that.
    $this->createPathAlias('/node/' . $node->id(), '/the-article-alias');
    $node_link = $node->toUrl()
        ->setAbsolute()
        ->toString();
    $this->assertStringContainsString('/the-article-alias', $node_link);
    $this->drupalGet('test-feed-display-fields.xml');
    $this->assertEquals($node_title, $this->getSession()
        ->getDriver()
        ->getText('//item/title'));
    $this->assertEquals($node_link, $this->getSession()
        ->getDriver()
        ->getText('//item/link'));
    // Verify HTML is properly escaped in the description field.
    $this->assertSession()
        ->responseContains('<p>A paragraph</p>');
    // Change the display to use the nid field, which is rewriting output as
    // 'node/{{ nid }}' and make sure things are still working.
    $view = Views::getView('test_display_feed');
    $display =& $view->storage
        ->getDisplay('feed_2');
    $display['display_options']['row']['options']['link_field'] = 'nid';
    $view->save();
    $this->drupalGet('test-feed-display-fields.xml');
    $this->assertEquals($node_title, $this->getSession()
        ->getDriver()
        ->getText('//item/title'));
    $this->assertEquals($node_link, $this->getSession()
        ->getDriver()
        ->getText('//item/link'));
}

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