Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\node\Functional;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Component\Utility\Html;
|
Chris@0
|
6
|
Chris@0
|
7 /**
|
Chris@0
|
8 * Tests the node/{node} page.
|
Chris@0
|
9 *
|
Chris@0
|
10 * @group node
|
Chris@0
|
11 * @see \Drupal\node\Controller\NodeController
|
Chris@0
|
12 */
|
Chris@0
|
13 class NodeViewTest extends NodeTestBase {
|
Chris@0
|
14
|
Chris@0
|
15 /**
|
Chris@0
|
16 * Tests the html head links.
|
Chris@0
|
17 */
|
Chris@0
|
18 public function testHtmlHeadLinks() {
|
Chris@0
|
19 $node = $this->drupalCreateNode();
|
Chris@0
|
20
|
Chris@18
|
21 $this->drupalGet($node->toUrl());
|
Chris@0
|
22
|
Chris@0
|
23 $result = $this->xpath('//link[@rel = "canonical"]');
|
Chris@18
|
24 $this->assertEqual($result[0]->getAttribute('href'), $node->toUrl()->setAbsolute()->toString());
|
Chris@0
|
25
|
Chris@0
|
26 // Link relations are checked for access for anonymous users.
|
Chris@0
|
27 $result = $this->xpath('//link[@rel = "version-history"]');
|
Chris@0
|
28 $this->assertFalse($result, 'Version history not present for anonymous users without access.');
|
Chris@0
|
29
|
Chris@0
|
30 $result = $this->xpath('//link[@rel = "edit-form"]');
|
Chris@0
|
31 $this->assertFalse($result, 'Edit form not present for anonymous users without access.');
|
Chris@0
|
32
|
Chris@0
|
33 $this->drupalLogin($this->createUser(['access content']));
|
Chris@18
|
34 $this->drupalGet($node->toUrl());
|
Chris@0
|
35
|
Chris@0
|
36 $result = $this->xpath('//link[@rel = "canonical"]');
|
Chris@18
|
37 $this->assertEqual($result[0]->getAttribute('href'), $node->toUrl()->setAbsolute()->toString());
|
Chris@0
|
38
|
Chris@0
|
39 // Link relations are present regardless of access for authenticated users.
|
Chris@0
|
40 $result = $this->xpath('//link[@rel = "version-history"]');
|
Chris@18
|
41 $this->assertEqual($result[0]->getAttribute('href'), $node->toUrl('version-history')->setAbsolute()->toString());
|
Chris@0
|
42
|
Chris@0
|
43 $result = $this->xpath('//link[@rel = "edit-form"]');
|
Chris@18
|
44 $this->assertEqual($result[0]->getAttribute('href'), $node->toUrl('edit-form')->setAbsolute()->toString());
|
Chris@0
|
45
|
Chris@0
|
46 // Give anonymous users access to edit the node. Do this through the UI to
|
Chris@0
|
47 // ensure caches are handled properly.
|
Chris@0
|
48 $this->drupalLogin($this->rootUser);
|
Chris@0
|
49 $edit = [
|
Chris@17
|
50 'anonymous[edit own ' . $node->bundle() . ' content]' => TRUE,
|
Chris@0
|
51 ];
|
Chris@0
|
52 $this->drupalPostForm('admin/people/permissions', $edit, 'Save permissions');
|
Chris@0
|
53 $this->drupalLogout();
|
Chris@0
|
54
|
Chris@0
|
55 // Anonymous user's should now see the edit-form link but not the
|
Chris@0
|
56 // version-history link.
|
Chris@18
|
57 $this->drupalGet($node->toUrl());
|
Chris@0
|
58 $result = $this->xpath('//link[@rel = "canonical"]');
|
Chris@18
|
59 $this->assertEqual($result[0]->getAttribute('href'), $node->toUrl()->setAbsolute()->toString());
|
Chris@0
|
60
|
Chris@0
|
61 $result = $this->xpath('//link[@rel = "version-history"]');
|
Chris@0
|
62 $this->assertFalse($result, 'Version history not present for anonymous users without access.');
|
Chris@0
|
63
|
Chris@0
|
64 $result = $this->xpath('//link[@rel = "edit-form"]');
|
Chris@18
|
65 $this->assertEqual($result[0]->getAttribute('href'), $node->toUrl('edit-form')->setAbsolute()->toString());
|
Chris@0
|
66 }
|
Chris@0
|
67
|
Chris@0
|
68 /**
|
Chris@0
|
69 * Tests the Link header.
|
Chris@0
|
70 */
|
Chris@0
|
71 public function testLinkHeader() {
|
Chris@0
|
72 $node = $this->drupalCreateNode();
|
Chris@0
|
73
|
Chris@0
|
74 $expected = [
|
Chris@18
|
75 '<' . Html::escape($node->toUrl('canonical')->setAbsolute()->toString()) . '>; rel="canonical"',
|
Chris@18
|
76 '<' . Html::escape($node->toUrl('canonical')->setAbsolute()->toString(), ['alias' => TRUE]) . '>; rel="shortlink"',
|
Chris@18
|
77 '<' . Html::escape($node->toUrl('revision')->setAbsolute()->toString()) . '>; rel="revision"',
|
Chris@0
|
78 ];
|
Chris@0
|
79
|
Chris@18
|
80 $this->drupalGet($node->toUrl());
|
Chris@0
|
81
|
Chris@0
|
82 $links = $this->drupalGetHeaders()['Link'];
|
Chris@0
|
83 $this->assertEqual($links, $expected);
|
Chris@0
|
84 }
|
Chris@0
|
85
|
Chris@0
|
86 /**
|
Chris@0
|
87 * Tests that we store and retrieve multi-byte UTF-8 characters correctly.
|
Chris@0
|
88 */
|
Chris@0
|
89 public function testMultiByteUtf8() {
|
Chris@0
|
90 $title = '🐝';
|
Chris@0
|
91 $this->assertTrue(mb_strlen($title, 'utf-8') < strlen($title), 'Title has multi-byte characters.');
|
Chris@0
|
92 $node = $this->drupalCreateNode(['title' => $title]);
|
Chris@18
|
93 $this->drupalGet($node->toUrl());
|
Chris@0
|
94 $result = $this->xpath('//span[contains(@class, "field--name-title")]');
|
Chris@0
|
95 $this->assertEqual($result[0]->getText(), $title, 'The passed title was returned.');
|
Chris@0
|
96 }
|
Chris@0
|
97
|
Chris@0
|
98 }
|