You are here

public function StyleOpmlTest::testOpmlOutput in Drupal 9

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

Tests the rendered output.

File

core/modules/views/tests/src/Functional/Plugin/StyleOpmlTest.php, line 49

Class

StyleOpmlTest
Tests the OPML feed style plugin.

Namespace

Drupal\Tests\views\Functional\Plugin

Code

public function testOpmlOutput() {

  // Create a test feed.
  $values = [
    'title' => $this
      ->randomMachineName(10),
    'url' => 'http://example.com/rss.xml',
    'refresh' => '900',
  ];
  $feed = $this->container
    ->get('entity_type.manager')
    ->getStorage('aggregator_feed')
    ->create($values);
  $feed
    ->save();
  $this
    ->drupalGet('test-feed-opml-style');
  $outline = $this
    ->getSession()
    ->getDriver()
    ->find('//outline[1]')[0];
  $this
    ->assertEquals('rss', $outline
    ->getAttribute('type'));
  $this
    ->assertEquals($feed
    ->label(), $outline
    ->getAttribute('text'));
  $this
    ->assertEquals($feed
    ->getUrl(), $outline
    ->getAttribute('xmlUrl'));
  $view = $this->container
    ->get('entity_type.manager')
    ->getStorage('view')
    ->load('test_style_opml');
  $display =& $view
    ->getDisplay('feed_1');
  $display['display_options']['row']['options']['type_field'] = 'link';
  $display['display_options']['row']['options']['url_field'] = 'url';
  $view
    ->save();
  $this
    ->drupalGet('test-feed-opml-style');
  $outline = $this
    ->getSession()
    ->getDriver()
    ->find('//outline[1]')[0];
  $this
    ->assertEquals('link', $outline
    ->getAttribute('type'));
  $this
    ->assertEquals($feed
    ->label(), $outline
    ->getAttribute('text'));
  $this
    ->assertEquals($feed
    ->getUrl(), $outline
    ->getAttribute('url'));

  // xmlUrl should not be present when type is link.
  $this
    ->assertNull($outline
    ->getAttribute('xmlUrl'));
}