Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / views / tests / src / Functional / Plugin / StyleOpmlTest.php
1 <?php
2
3 namespace Drupal\Tests\views\Functional\Plugin;
4
5 use Drupal\Tests\views\Functional\ViewTestBase;
6
7 /**
8  * Tests the OPML feed style plugin.
9  *
10  * @group views
11  * @see \Drupal\views\Plugin\views\style\Opml
12  */
13 class StyleOpmlTest extends ViewTestBase {
14
15   /**
16    * Views used by this test.
17    *
18    * @var array
19    */
20   public static $testViews = ['test_style_opml'];
21
22   /**
23    * Modules to enable.
24    *
25    * @var array
26    */
27   public static $modules = ['aggregator'];
28
29   /**
30    * {@inheritdoc}
31    */
32   protected function setUp($import_test_views = TRUE) {
33     parent::setUp($import_test_views);
34
35     $this->enableViewsTestModule();
36
37     $admin_user = $this->drupalCreateUser(['administer news feeds']);
38     $this->drupalLogin($admin_user);
39   }
40
41   /**
42    * Tests the rendered output.
43    */
44   public function testOpmlOutput() {
45     // Create a test feed.
46     $values = [
47       'title' => $this->randomMachineName(10),
48       'url' => 'http://example.com/rss.xml',
49       'refresh' => '900',
50     ];
51     $feed = $this->container->get('entity.manager')
52       ->getStorage('aggregator_feed')
53       ->create($values);
54     $feed->save();
55
56     $this->drupalGet('test-feed-opml-style');
57     $outline = $this->getSession()->getDriver()->find('//outline[1]')[0];
58     $this->assertEquals('rss', $outline->getAttribute('type'));
59     $this->assertEquals($feed->label(), $outline->getAttribute('text'));
60     $this->assertEquals($feed->getUrl(), $outline->getAttribute('xmlUrl'));
61
62     $view = $this->container->get('entity.manager')
63       ->getStorage('view')
64       ->load('test_style_opml');
65     $display = &$view->getDisplay('feed_1');
66     $display['display_options']['row']['options']['type_field'] = 'link';
67     $display['display_options']['row']['options']['url_field'] = 'url';
68     $view->save();
69
70     $this->drupalGet('test-feed-opml-style');
71     $outline = $this->getSession()->getDriver()->find('//outline[1]')[0];
72     $this->assertEquals('link', $outline->getAttribute('type'));
73     $this->assertEquals($feed->label(), $outline->getAttribute('text'));
74     $this->assertEquals($feed->getUrl(), $outline->getAttribute('url'));
75     // xmlUrl should not be present when type is link.
76     $this->assertNull($outline->getAttribute('xmlUrl'));
77   }
78
79 }