3 namespace Drupal\Tests\node\Functional;
5 use Drupal\Component\Utility\Html;
8 * Tests the node/{node} page.
11 * @see \Drupal\node\Controller\NodeController
13 class NodeViewTest extends NodeTestBase {
16 * Tests the html head links.
18 public function testHtmlHeadLinks() {
19 $node = $this->drupalCreateNode();
21 $this->drupalGet($node->urlInfo());
23 $result = $this->xpath('//link[@rel = "canonical"]');
24 $this->assertEqual($result[0]->getAttribute('href'), $node->url());
26 // Link relations are checked for access for anonymous users.
27 $result = $this->xpath('//link[@rel = "version-history"]');
28 $this->assertFalse($result, 'Version history not present for anonymous users without access.');
30 $result = $this->xpath('//link[@rel = "edit-form"]');
31 $this->assertFalse($result, 'Edit form not present for anonymous users without access.');
33 $this->drupalLogin($this->createUser(['access content']));
34 $this->drupalGet($node->urlInfo());
36 $result = $this->xpath('//link[@rel = "canonical"]');
37 $this->assertEqual($result[0]->getAttribute('href'), $node->url());
39 // Link relations are present regardless of access for authenticated users.
40 $result = $this->xpath('//link[@rel = "version-history"]');
41 $this->assertEqual($result[0]->getAttribute('href'), $node->url('version-history'));
43 $result = $this->xpath('//link[@rel = "edit-form"]');
44 $this->assertEqual($result[0]->getAttribute('href'), $node->url('edit-form'));
46 // Give anonymous users access to edit the node. Do this through the UI to
47 // ensure caches are handled properly.
48 $this->drupalLogin($this->rootUser);
50 'anonymous[edit own ' . $node->bundle() . ' content]' => TRUE
52 $this->drupalPostForm('admin/people/permissions', $edit, 'Save permissions');
53 $this->drupalLogout();
55 // Anonymous user's should now see the edit-form link but not the
56 // version-history link.
57 $this->drupalGet($node->urlInfo());
58 $result = $this->xpath('//link[@rel = "canonical"]');
59 $this->assertEqual($result[0]->getAttribute('href'), $node->url());
61 $result = $this->xpath('//link[@rel = "version-history"]');
62 $this->assertFalse($result, 'Version history not present for anonymous users without access.');
64 $result = $this->xpath('//link[@rel = "edit-form"]');
65 $this->assertEqual($result[0]->getAttribute('href'), $node->url('edit-form'));
69 * Tests the Link header.
71 public function testLinkHeader() {
72 $node = $this->drupalCreateNode();
75 '<' . Html::escape($node->url('canonical')) . '>; rel="canonical"',
76 '<' . Html::escape($node->url('canonical'), ['alias' => TRUE]) . '>; rel="shortlink"',
77 '<' . Html::escape($node->url('revision')) . '>; rel="revision"',
80 $this->drupalGet($node->urlInfo());
82 $links = $this->drupalGetHeaders()['Link'];
83 $this->assertEqual($links, $expected);
87 * Tests that we store and retrieve multi-byte UTF-8 characters correctly.
89 public function testMultiByteUtf8() {
91 $this->assertTrue(mb_strlen($title, 'utf-8') < strlen($title), 'Title has multi-byte characters.');
92 $node = $this->drupalCreateNode(['title' => $title]);
93 $this->drupalGet($node->urlInfo());
94 $result = $this->xpath('//span[contains(@class, "field--name-title")]');
95 $this->assertEqual($result[0]->getText(), $title, 'The passed title was returned.');