You are here

public function DisplayFeedTest::testFeedFieldOutput in Drupal 9

Same name and namespace in other branches
  1. 8 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
    ->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'));
}