Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\node\Functional;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\filter\Entity\FilterFormat;
|
Chris@0
|
6
|
Chris@0
|
7 /**
|
Chris@0
|
8 * Ensures that data added to nodes by other modules appears in RSS feeds.
|
Chris@0
|
9 *
|
Chris@0
|
10 * Create a node, enable the node_test module to ensure that extra data is
|
Chris@0
|
11 * added to the node's renderable array, then verify that the data appears on
|
Chris@0
|
12 * the site-wide RSS feed at rss.xml.
|
Chris@0
|
13 *
|
Chris@0
|
14 * @group node
|
Chris@0
|
15 */
|
Chris@0
|
16 class NodeRSSContentTest extends NodeTestBase {
|
Chris@0
|
17
|
Chris@0
|
18 /**
|
Chris@0
|
19 * Enable a module that implements hook_node_view().
|
Chris@0
|
20 *
|
Chris@0
|
21 * @var array
|
Chris@0
|
22 */
|
Chris@0
|
23 public static $modules = ['node_test', 'views'];
|
Chris@0
|
24
|
Chris@0
|
25 protected function setUp() {
|
Chris@0
|
26 parent::setUp();
|
Chris@0
|
27
|
Chris@0
|
28 // Use bypass node access permission here, because the test class uses
|
Chris@0
|
29 // hook_grants_alter() to deny access to everyone on node_access
|
Chris@0
|
30 // queries.
|
Chris@0
|
31 $user = $this->drupalCreateUser(['bypass node access', 'access content', 'create article content']);
|
Chris@0
|
32 $this->drupalLogin($user);
|
Chris@0
|
33 }
|
Chris@0
|
34
|
Chris@0
|
35 /**
|
Chris@0
|
36 * Ensures that a new node includes the custom data when added to an RSS feed.
|
Chris@0
|
37 */
|
Chris@0
|
38 public function testNodeRSSContent() {
|
Chris@0
|
39 // Create a node.
|
Chris@0
|
40 $node = $this->drupalCreateNode(['type' => 'article', 'promote' => 1]);
|
Chris@0
|
41
|
Chris@0
|
42 $this->drupalGet('rss.xml');
|
Chris@0
|
43
|
Chris@0
|
44 // Check that content added in 'rss' view mode appear in RSS feed.
|
Chris@0
|
45 $rss_only_content = t('Extra data that should appear only in the RSS feed for node @nid.', ['@nid' => $node->id()]);
|
Chris@0
|
46 $this->assertText($rss_only_content, 'Node content designated for RSS appear in RSS feed.');
|
Chris@0
|
47
|
Chris@0
|
48 // Check that content added in view modes other than 'rss' doesn't
|
Chris@0
|
49 // appear in RSS feed.
|
Chris@0
|
50 $non_rss_content = t('Extra data that should appear everywhere except the RSS feed for node @nid.', ['@nid' => $node->id()]);
|
Chris@0
|
51 $this->assertNoText($non_rss_content, 'Node content not designed for RSS does not appear in RSS feed.');
|
Chris@0
|
52
|
Chris@0
|
53 // Check that extra RSS elements and namespaces are added to RSS feed.
|
Chris@0
|
54 $test_element = '<testElement>' . t('Value of testElement RSS element for node @nid.', ['@nid' => $node->id()]) . '</testElement>';
|
Chris@0
|
55 $test_ns = 'xmlns:drupaltest="http://example.com/test-namespace"';
|
Chris@0
|
56 $this->assertRaw($test_element, 'Extra RSS elements appear in RSS feed.');
|
Chris@0
|
57 $this->assertRaw($test_ns, 'Extra namespaces appear in RSS feed.');
|
Chris@0
|
58
|
Chris@0
|
59 // Check that content added in 'rss' view mode doesn't appear when
|
Chris@0
|
60 // viewing node.
|
Chris@0
|
61 $this->drupalGet('node/' . $node->id());
|
Chris@0
|
62 $this->assertNoText($rss_only_content, 'Node content designed for RSS does not appear when viewing node.');
|
Chris@0
|
63 }
|
Chris@0
|
64
|
Chris@0
|
65 /**
|
Chris@0
|
66 * Tests relative, root-relative, protocol-relative and absolute URLs.
|
Chris@0
|
67 */
|
Chris@0
|
68 public function testUrlHandling() {
|
Chris@0
|
69 // Only the plain_text text format is available by default, which escapes
|
Chris@0
|
70 // all HTML.
|
Chris@0
|
71 FilterFormat::create([
|
Chris@0
|
72 'format' => 'full_html',
|
Chris@0
|
73 'name' => 'Full HTML',
|
Chris@0
|
74 'filters' => [],
|
Chris@0
|
75 ])->save();
|
Chris@0
|
76
|
Chris@0
|
77 $defaults = [
|
Chris@0
|
78 'type' => 'article',
|
Chris@0
|
79 'promote' => 1,
|
Chris@0
|
80 ];
|
Chris@0
|
81 $this->drupalCreateNode($defaults + [
|
Chris@0
|
82 'body' => [
|
Chris@0
|
83 'value' => '<p><a href="' . file_url_transform_relative(file_create_url('public://root-relative')) . '">Root-relative URL</a></p>',
|
Chris@0
|
84 'format' => 'full_html',
|
Chris@0
|
85 ],
|
Chris@0
|
86 ]);
|
Chris@0
|
87 $protocol_relative_url = substr(file_create_url('public://protocol-relative'), strlen(\Drupal::request()->getScheme() . ':'));
|
Chris@0
|
88 $this->drupalCreateNode($defaults + [
|
Chris@0
|
89 'body' => [
|
Chris@0
|
90 'value' => '<p><a href="' . $protocol_relative_url . '">Protocol-relative URL</a></p>',
|
Chris@0
|
91 'format' => 'full_html',
|
Chris@0
|
92 ],
|
Chris@0
|
93 ]);
|
Chris@0
|
94 $absolute_url = file_create_url('public://absolute');
|
Chris@0
|
95 $this->drupalCreateNode($defaults + [
|
Chris@0
|
96 'body' => [
|
Chris@0
|
97 'value' => '<p><a href="' . $absolute_url . '">Absolute URL</a></p>',
|
Chris@0
|
98 'format' => 'full_html',
|
Chris@0
|
99 ],
|
Chris@0
|
100 ]);
|
Chris@0
|
101
|
Chris@0
|
102 $this->drupalGet('rss.xml');
|
Chris@0
|
103 $this->assertRaw(file_create_url('public://root-relative'), 'Root-relative URL is transformed to absolute.');
|
Chris@0
|
104 $this->assertRaw($protocol_relative_url, 'Protocol-relative URL is left untouched.');
|
Chris@0
|
105 $this->assertRaw($absolute_url, 'Absolute URL is left untouched.');
|
Chris@0
|
106 }
|
Chris@0
|
107
|
Chris@0
|
108 }
|