comparison core/modules/views/src/Tests/Plugin/StyleOpmlTest.php @ 0:4c8ae668cc8c

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