You are here

public function DisplayFeedTest::testFeedOutput in Zircon Profile 8.0

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

Tests the rendered output.

File

core/modules/views/src/Tests/Plugin/DisplayFeedTest.php, line 46
Contains \Drupal\views\Tests\Plugin\DisplayFeedTest.

Class

DisplayFeedTest
Tests the feed display plugin.

Namespace

Drupal\views\Tests\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(),
      ],
    ],
  ]);

  // Test the site name setting.
  $site_name = $this
    ->randomMachineName();
  $this
    ->config('system.site')
    ->set('name', $site_name)
    ->save();
  $this
    ->drupalGet('test-feed-display.xml');
  $result = $this
    ->xpath('//title');
  $this
    ->assertEqual($result[0], $site_name, 'The site title is used for the feed title.');
  $this
    ->assertEqual($result[1], $node_title, 'Node title with HTML entities displays correctly.');

  // Verify HTML is properly escaped in the description field.
  $this
    ->assertRaw('<p>A paragraph</p>');
  $view = $this->container
    ->get('entity.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');
  $result = $this
    ->xpath('//title');
  $this
    ->assertEqual($result[0], 'test_display_feed', 'The display title is used for the feed 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
    ->assertTrue(strpos($feed_icon[0]['href'], 'test-feed-display.xml'), '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]['href'];
  $this
    ->assertEqual($icon_href, $page_url . '/feed', 'The feed icon was found.');
  $link_href = $this
    ->cssSelect('link[type = "application/rss+xml"][href *= "test-feed-icon"]')[0]['href'];
  $this
    ->assertEqual($link_href, $page_url . '/feed', 'The RSS link was found.');
  $feed_link = simplexml_load_string($this
    ->drupalGet($icon_href))->channel->link;
  $this
    ->assertEqual($feed_link, $page_url, 'The channel link was found.');
}