Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\node\Functional;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\comment\Tests\CommentTestTrait;
|
Chris@0
|
6 use Drupal\Component\Utility\Html;
|
Chris@0
|
7
|
Chris@0
|
8 /**
|
Chris@0
|
9 * Tests node title.
|
Chris@0
|
10 *
|
Chris@0
|
11 * @group node
|
Chris@0
|
12 */
|
Chris@0
|
13 class NodeTitleTest extends NodeTestBase {
|
Chris@0
|
14
|
Chris@0
|
15 use CommentTestTrait;
|
Chris@0
|
16
|
Chris@0
|
17 /**
|
Chris@0
|
18 * Modules to enable.
|
Chris@0
|
19 *
|
Chris@0
|
20 * @var array
|
Chris@0
|
21 */
|
Chris@0
|
22 public static $modules = ['comment', 'views', 'block'];
|
Chris@0
|
23
|
Chris@0
|
24 /**
|
Chris@0
|
25 * A user with permission to bypass access content.
|
Chris@0
|
26 *
|
Chris@0
|
27 * @var \Drupal\user\UserInterface
|
Chris@0
|
28 */
|
Chris@0
|
29 protected $adminUser;
|
Chris@0
|
30
|
Chris@0
|
31 /**
|
Chris@0
|
32 * {@inheritdoc}
|
Chris@0
|
33 */
|
Chris@0
|
34 protected function setUp() {
|
Chris@0
|
35 parent::setUp();
|
Chris@0
|
36 $this->drupalPlaceBlock('system_breadcrumb_block');
|
Chris@17
|
37 $this->drupalPlaceBlock('page_title_block');
|
Chris@0
|
38
|
Chris@0
|
39 $this->adminUser = $this->drupalCreateUser(['administer nodes', 'create article content', 'create page content', 'post comments']);
|
Chris@0
|
40 $this->drupalLogin($this->adminUser);
|
Chris@0
|
41 $this->addDefaultCommentField('node', 'page');
|
Chris@0
|
42 }
|
Chris@0
|
43
|
Chris@0
|
44 /**
|
Chris@0
|
45 * Creates one node and tests if the node title has the correct value.
|
Chris@0
|
46 */
|
Chris@0
|
47 public function testNodeTitle() {
|
Chris@0
|
48 // Create "Basic page" content with title.
|
Chris@0
|
49 // Add the node to the frontpage so we can test if teaser links are
|
Chris@0
|
50 // clickable.
|
Chris@0
|
51 $settings = [
|
Chris@0
|
52 'title' => $this->randomMachineName(8),
|
Chris@0
|
53 'promote' => 1,
|
Chris@0
|
54 ];
|
Chris@0
|
55 $node = $this->drupalCreateNode($settings);
|
Chris@0
|
56
|
Chris@0
|
57 // Test <title> tag.
|
Chris@0
|
58 $this->drupalGet('node/' . $node->id());
|
Chris@0
|
59 $xpath = '//title';
|
Chris@0
|
60 $this->assertEqual($this->xpath($xpath)[0]->getText(), $node->label() . ' | Drupal', 'Page title is equal to node title.', 'Node');
|
Chris@0
|
61
|
Chris@0
|
62 // Test breadcrumb in comment preview.
|
Chris@0
|
63 $this->drupalGet('comment/reply/node/' . $node->id() . '/comment');
|
Chris@0
|
64 $xpath = '//nav[@class="breadcrumb"]/ol/li[last()]/a';
|
Chris@0
|
65 $this->assertEqual($this->xpath($xpath)[0]->getText(), $node->label(), 'Node breadcrumb is equal to node title.', 'Node');
|
Chris@0
|
66
|
Chris@0
|
67 // Test node title in comment preview.
|
Chris@0
|
68 $this->assertEqual($this->xpath('//article[contains(concat(" ", normalize-space(@class), " "), :node-class)]/h2/a/span', [':node-class' => ' node--type-' . $node->bundle() . ' '])[0]->getText(), $node->label(), 'Node preview title is equal to node title.', 'Node');
|
Chris@0
|
69
|
Chris@0
|
70 // Test node title is clickable on teaser list (/node).
|
Chris@0
|
71 $this->drupalGet('node');
|
Chris@0
|
72 $this->clickLink($node->label());
|
Chris@0
|
73
|
Chris@0
|
74 // Test edge case where node title is set to 0.
|
Chris@0
|
75 $settings = [
|
Chris@0
|
76 'title' => 0,
|
Chris@0
|
77 ];
|
Chris@0
|
78 $node = $this->drupalCreateNode($settings);
|
Chris@0
|
79 // Test that 0 appears as <title>.
|
Chris@0
|
80 $this->drupalGet('node/' . $node->id());
|
Chris@0
|
81 $this->assertTitle(0 . ' | Drupal', 'Page title is equal to 0.', 'Node');
|
Chris@0
|
82 // Test that 0 appears in the template <h1>.
|
Chris@0
|
83 $xpath = '//h1';
|
Chris@17
|
84 $this->assertSame('0', $this->xpath($xpath)[0]->getText(), 'Node title is displayed as 0.');
|
Chris@0
|
85
|
Chris@0
|
86 // Test edge case where node title contains special characters.
|
Chris@0
|
87 $edge_case_title = 'article\'s "title".';
|
Chris@0
|
88 $settings = [
|
Chris@0
|
89 'title' => $edge_case_title,
|
Chris@0
|
90 ];
|
Chris@0
|
91 $node = $this->drupalCreateNode($settings);
|
Chris@0
|
92 // Test that the title appears as <title>. The title will be escaped on the
|
Chris@0
|
93 // the page.
|
Chris@0
|
94 $edge_case_title_escaped = Html::escape($edge_case_title);
|
Chris@0
|
95 $this->drupalGet('node/' . $node->id());
|
Chris@0
|
96 $this->assertRaw('<title>' . $edge_case_title_escaped . ' | Drupal</title>', 'Page title is equal to article\'s "title".', 'Node');
|
Chris@0
|
97
|
Chris@0
|
98 // Test that the title appears as <title> when reloading the node page.
|
Chris@0
|
99 $this->drupalGet('node/' . $node->id());
|
Chris@0
|
100 $this->assertRaw('<title>' . $edge_case_title_escaped . ' | Drupal</title>', 'Page title is equal to article\'s "title".', 'Node');
|
Chris@0
|
101
|
Chris@0
|
102 }
|
Chris@0
|
103
|
Chris@0
|
104 }
|