You are here

public function DisplayFeedTest::testFeedOutput in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Functional/Plugin/DisplayFeedTest.php \Drupal\Tests\views\Functional\Plugin\DisplayFeedTest::testFeedOutput()
  2. 9 core/modules/views/tests/src/Functional/Plugin/DisplayFeedTest.php \Drupal\Tests\views\Functional\Plugin\DisplayFeedTest::testFeedOutput()

Tests the rendered output.

File

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

Class

DisplayFeedTest
Tests the feed display plugin.

Namespace

Drupal\Tests\views\Functional\Plugin

Code

public function testFeedOutput() {
  $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(),
      ],
    ],
  ]);
  $node_link = $node
    ->toUrl()
    ->setAbsolute()
    ->toString();

  // Test the site name setting.
  $site_name = $this
    ->randomMachineName();
  $frontpage_url = Url::fromRoute('<front>')
    ->setAbsolute()
    ->toString();
  $this
    ->config('system.site')
    ->set('name', $site_name)
    ->save();
  $this
    ->drupalGet('test-feed-display.xml');
  $this
    ->assertEquals($site_name, $this
    ->getSession()
    ->getDriver()
    ->getText('//channel/title'));
  $this
    ->assertEquals($frontpage_url, $this
    ->getSession()
    ->getDriver()
    ->getText('//channel/link'));
  $this
    ->assertEquals('Copyright 2019 Dries Buytaert', $this
    ->getSession()
    ->getDriver()
    ->getText('//channel/copyright'));
  $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('&lt;p&gt;A paragraph&lt;/p&gt;');
  $view = $this->container
    ->get('entity_type.manager')
    ->getStorage('view')
    ->load('test_display_feed');
  $display =& $view
    ->getDisplay('feed_1');
  $display['display_options']['sitename_title'] = 0;
  $view
    ->save();
  $this
    ->drupalGet('test-feed-display.xml');
  $this
    ->assertEquals('test_display_feed', $this
    ->getSession()
    ->getDriver()
    ->getText('//channel/title'));

  // Add a block display and attach the feed.
  $view
    ->getExecutable()
    ->newDisplay('block', NULL, 'test');
  $display =& $view
    ->getDisplay('feed_1');
  $display['display_options']['displays']['test'] = 'test';
  $view
    ->save();

  // Test the feed display adds a feed icon to the block display.
  $this
    ->drupalPlaceBlock('views_block:test_display_feed-test');
  $this
    ->drupalGet('<front>');
  $feed_icon = $this
    ->cssSelect('div.view-id-test_display_feed a.feed-icon');
  $this
    ->assertStringContainsString('test-feed-display.xml', $feed_icon[0]
    ->getAttribute('href'), 'The feed icon was found.');

  // Test feed display attached to page display with arguments.
  $this
    ->drupalGet('test-feed-icon/' . $node
    ->id());
  $page_url = $this
    ->getUrl();
  $icon_href = $this
    ->cssSelect('a.feed-icon[href *= "test-feed-icon"]')[0]
    ->getAttribute('href');
  $this
    ->assertEquals($page_url . '/feed', $icon_href, 'The feed icon was found.');
  $link_href = $this
    ->cssSelect('link[type = "application/rss+xml"][href *= "test-feed-icon"]')[0]
    ->getAttribute('href');
  $this
    ->assertEquals($page_url . '/feed', $link_href, 'The RSS link was found.');
  $this
    ->drupalGet($icon_href);
  $this
    ->assertEquals($frontpage_url, $this
    ->getSession()
    ->getDriver()
    ->getText('//channel/link'));
}