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