You are here

public function DisplayFeedTest::testDisabledFeed in Drupal 8

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

Tests that nothing is output when the feed display is disabled.

File

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

Class

DisplayFeedTest
Tests the feed display plugin.

Namespace

Drupal\Tests\views\Functional\Plugin

Code

public function testDisabledFeed() {
  $this
    ->drupalCreateContentType([
    'type' => 'page',
  ]);
  $this
    ->drupalCreateNode();

  // Ensure that the feed_1 display is attached to the page_1 display.
  $view = Views::getView('test_attached_disabled');
  $view
    ->setDisplay('page_1');
  $attached_displays = $view->display_handler
    ->getAttachedDisplays();
  $this
    ->assertContains('feed_1', $attached_displays, 'The feed display is attached to the page display.');

  // Check that the rss header is output on the page display.
  $this
    ->drupalGet('/test-attached-disabled');
  $feed_header = $this
    ->xpath('//link[@rel="alternate"]');
  $this
    ->assertEqual($feed_header[0]
    ->getAttribute('type'), 'application/rss+xml', 'The feed link has the type application/rss+xml.');
  $this
    ->assertStringContainsString('test-attached-disabled.xml', $feed_header[0]
    ->getAttribute('href'), 'Page display contains the correct feed URL.');

  // Disable the feed display.
  $view->displayHandlers
    ->get('feed_1')
    ->setOption('enabled', FALSE);
  $view
    ->save();

  // Ensure there is no link rel present on the page.
  $this
    ->drupalGet('/test-attached-disabled');
  $result = $this
    ->xpath('//link[@rel="alternate"]');
  $this
    ->assertTrue(empty($result), 'Page display does not contain a feed header.');

  // Ensure the feed attachment returns 'Not found'.
  $this
    ->drupalGet('/test-attached-disabled.xml');
  $this
    ->assertSession()
    ->statusCodeEquals(404);
}