Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/node/tests/src/Functional/NodeViewTest.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | a9cd425dd02b |
children |
comparison
equal
deleted
inserted
replaced
4:a9cd425dd02b | 5:12f9dff5fda9 |
---|---|
16 * Tests the html head links. | 16 * Tests the html head links. |
17 */ | 17 */ |
18 public function testHtmlHeadLinks() { | 18 public function testHtmlHeadLinks() { |
19 $node = $this->drupalCreateNode(); | 19 $node = $this->drupalCreateNode(); |
20 | 20 |
21 $this->drupalGet($node->urlInfo()); | 21 $this->drupalGet($node->toUrl()); |
22 | 22 |
23 $result = $this->xpath('//link[@rel = "canonical"]'); | 23 $result = $this->xpath('//link[@rel = "canonical"]'); |
24 $this->assertEqual($result[0]->getAttribute('href'), $node->url()); | 24 $this->assertEqual($result[0]->getAttribute('href'), $node->toUrl()->setAbsolute()->toString()); |
25 | 25 |
26 // Link relations are checked for access for anonymous users. | 26 // Link relations are checked for access for anonymous users. |
27 $result = $this->xpath('//link[@rel = "version-history"]'); | 27 $result = $this->xpath('//link[@rel = "version-history"]'); |
28 $this->assertFalse($result, 'Version history not present for anonymous users without access.'); | 28 $this->assertFalse($result, 'Version history not present for anonymous users without access.'); |
29 | 29 |
30 $result = $this->xpath('//link[@rel = "edit-form"]'); | 30 $result = $this->xpath('//link[@rel = "edit-form"]'); |
31 $this->assertFalse($result, 'Edit form not present for anonymous users without access.'); | 31 $this->assertFalse($result, 'Edit form not present for anonymous users without access.'); |
32 | 32 |
33 $this->drupalLogin($this->createUser(['access content'])); | 33 $this->drupalLogin($this->createUser(['access content'])); |
34 $this->drupalGet($node->urlInfo()); | 34 $this->drupalGet($node->toUrl()); |
35 | 35 |
36 $result = $this->xpath('//link[@rel = "canonical"]'); | 36 $result = $this->xpath('//link[@rel = "canonical"]'); |
37 $this->assertEqual($result[0]->getAttribute('href'), $node->url()); | 37 $this->assertEqual($result[0]->getAttribute('href'), $node->toUrl()->setAbsolute()->toString()); |
38 | 38 |
39 // Link relations are present regardless of access for authenticated users. | 39 // Link relations are present regardless of access for authenticated users. |
40 $result = $this->xpath('//link[@rel = "version-history"]'); | 40 $result = $this->xpath('//link[@rel = "version-history"]'); |
41 $this->assertEqual($result[0]->getAttribute('href'), $node->url('version-history')); | 41 $this->assertEqual($result[0]->getAttribute('href'), $node->toUrl('version-history')->setAbsolute()->toString()); |
42 | 42 |
43 $result = $this->xpath('//link[@rel = "edit-form"]'); | 43 $result = $this->xpath('//link[@rel = "edit-form"]'); |
44 $this->assertEqual($result[0]->getAttribute('href'), $node->url('edit-form')); | 44 $this->assertEqual($result[0]->getAttribute('href'), $node->toUrl('edit-form')->setAbsolute()->toString()); |
45 | 45 |
46 // Give anonymous users access to edit the node. Do this through the UI to | 46 // Give anonymous users access to edit the node. Do this through the UI to |
47 // ensure caches are handled properly. | 47 // ensure caches are handled properly. |
48 $this->drupalLogin($this->rootUser); | 48 $this->drupalLogin($this->rootUser); |
49 $edit = [ | 49 $edit = [ |
52 $this->drupalPostForm('admin/people/permissions', $edit, 'Save permissions'); | 52 $this->drupalPostForm('admin/people/permissions', $edit, 'Save permissions'); |
53 $this->drupalLogout(); | 53 $this->drupalLogout(); |
54 | 54 |
55 // Anonymous user's should now see the edit-form link but not the | 55 // Anonymous user's should now see the edit-form link but not the |
56 // version-history link. | 56 // version-history link. |
57 $this->drupalGet($node->urlInfo()); | 57 $this->drupalGet($node->toUrl()); |
58 $result = $this->xpath('//link[@rel = "canonical"]'); | 58 $result = $this->xpath('//link[@rel = "canonical"]'); |
59 $this->assertEqual($result[0]->getAttribute('href'), $node->url()); | 59 $this->assertEqual($result[0]->getAttribute('href'), $node->toUrl()->setAbsolute()->toString()); |
60 | 60 |
61 $result = $this->xpath('//link[@rel = "version-history"]'); | 61 $result = $this->xpath('//link[@rel = "version-history"]'); |
62 $this->assertFalse($result, 'Version history not present for anonymous users without access.'); | 62 $this->assertFalse($result, 'Version history not present for anonymous users without access.'); |
63 | 63 |
64 $result = $this->xpath('//link[@rel = "edit-form"]'); | 64 $result = $this->xpath('//link[@rel = "edit-form"]'); |
65 $this->assertEqual($result[0]->getAttribute('href'), $node->url('edit-form')); | 65 $this->assertEqual($result[0]->getAttribute('href'), $node->toUrl('edit-form')->setAbsolute()->toString()); |
66 } | 66 } |
67 | 67 |
68 /** | 68 /** |
69 * Tests the Link header. | 69 * Tests the Link header. |
70 */ | 70 */ |
71 public function testLinkHeader() { | 71 public function testLinkHeader() { |
72 $node = $this->drupalCreateNode(); | 72 $node = $this->drupalCreateNode(); |
73 | 73 |
74 $expected = [ | 74 $expected = [ |
75 '<' . Html::escape($node->url('canonical')) . '>; rel="canonical"', | 75 '<' . Html::escape($node->toUrl('canonical')->setAbsolute()->toString()) . '>; rel="canonical"', |
76 '<' . Html::escape($node->url('canonical'), ['alias' => TRUE]) . '>; rel="shortlink"', | 76 '<' . Html::escape($node->toUrl('canonical')->setAbsolute()->toString(), ['alias' => TRUE]) . '>; rel="shortlink"', |
77 '<' . Html::escape($node->url('revision')) . '>; rel="revision"', | 77 '<' . Html::escape($node->toUrl('revision')->setAbsolute()->toString()) . '>; rel="revision"', |
78 ]; | 78 ]; |
79 | 79 |
80 $this->drupalGet($node->urlInfo()); | 80 $this->drupalGet($node->toUrl()); |
81 | 81 |
82 $links = $this->drupalGetHeaders()['Link']; | 82 $links = $this->drupalGetHeaders()['Link']; |
83 $this->assertEqual($links, $expected); | 83 $this->assertEqual($links, $expected); |
84 } | 84 } |
85 | 85 |
88 */ | 88 */ |
89 public function testMultiByteUtf8() { | 89 public function testMultiByteUtf8() { |
90 $title = '🐝'; | 90 $title = '🐝'; |
91 $this->assertTrue(mb_strlen($title, 'utf-8') < strlen($title), 'Title has multi-byte characters.'); | 91 $this->assertTrue(mb_strlen($title, 'utf-8') < strlen($title), 'Title has multi-byte characters.'); |
92 $node = $this->drupalCreateNode(['title' => $title]); | 92 $node = $this->drupalCreateNode(['title' => $title]); |
93 $this->drupalGet($node->urlInfo()); | 93 $this->drupalGet($node->toUrl()); |
94 $result = $this->xpath('//span[contains(@class, "field--name-title")]'); | 94 $result = $this->xpath('//span[contains(@class, "field--name-title")]'); |
95 $this->assertEqual($result[0]->getText(), $title, 'The passed title was returned.'); | 95 $this->assertEqual($result[0]->getText(), $title, 'The passed title was returned.'); |
96 } | 96 } |
97 | 97 |
98 } | 98 } |