function DisplayFeedTest::testFeedFieldOutput

Same name in other branches
  1. 9 core/modules/views/tests/src/Functional/Plugin/DisplayFeedTest.php \Drupal\Tests\views\Functional\Plugin\DisplayFeedTest::testFeedFieldOutput()
  2. 10 core/modules/views/tests/src/Functional/Plugin/DisplayFeedTest.php \Drupal\Tests\views\Functional\Plugin\DisplayFeedTest::testFeedFieldOutput()
  3. 11.x 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 114

Class

DisplayFeedTest
Tests the feed display plugin.

Namespace

Drupal\Tests\views\Functional\Plugin

Code

public function testFeedFieldOutput() {
    $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->assertRaw('<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.