Chris@0: drupalPlaceBlock('system_breadcrumb_block');
Chris@17: $this->drupalPlaceBlock('page_title_block');
Chris@0:
Chris@0: $this->adminUser = $this->drupalCreateUser(['administer nodes', 'create article content', 'create page content', 'post comments']);
Chris@0: $this->drupalLogin($this->adminUser);
Chris@0: $this->addDefaultCommentField('node', 'page');
Chris@0: }
Chris@0:
Chris@0: /**
Chris@0: * Creates one node and tests if the node title has the correct value.
Chris@0: */
Chris@0: public function testNodeTitle() {
Chris@0: // Create "Basic page" content with title.
Chris@0: // Add the node to the frontpage so we can test if teaser links are
Chris@0: // clickable.
Chris@0: $settings = [
Chris@0: 'title' => $this->randomMachineName(8),
Chris@0: 'promote' => 1,
Chris@0: ];
Chris@0: $node = $this->drupalCreateNode($settings);
Chris@0:
Chris@0: // Test
tag.
Chris@0: $this->drupalGet('node/' . $node->id());
Chris@0: $xpath = '//title';
Chris@0: $this->assertEqual($this->xpath($xpath)[0]->getText(), $node->label() . ' | Drupal', 'Page title is equal to node title.', 'Node');
Chris@0:
Chris@0: // Test breadcrumb in comment preview.
Chris@0: $this->drupalGet('comment/reply/node/' . $node->id() . '/comment');
Chris@0: $xpath = '//nav[@class="breadcrumb"]/ol/li[last()]/a';
Chris@0: $this->assertEqual($this->xpath($xpath)[0]->getText(), $node->label(), 'Node breadcrumb is equal to node title.', 'Node');
Chris@0:
Chris@0: // Test node title in comment preview.
Chris@0: $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:
Chris@0: // Test node title is clickable on teaser list (/node).
Chris@0: $this->drupalGet('node');
Chris@0: $this->clickLink($node->label());
Chris@0:
Chris@0: // Test edge case where node title is set to 0.
Chris@0: $settings = [
Chris@0: 'title' => 0,
Chris@0: ];
Chris@0: $node = $this->drupalCreateNode($settings);
Chris@0: // Test that 0 appears as .
Chris@0: $this->drupalGet('node/' . $node->id());
Chris@0: $this->assertTitle(0 . ' | Drupal', 'Page title is equal to 0.', 'Node');
Chris@0: // Test that 0 appears in the template .
Chris@0: $xpath = '//h1';
Chris@17: $this->assertSame('0', $this->xpath($xpath)[0]->getText(), 'Node title is displayed as 0.');
Chris@0:
Chris@0: // Test edge case where node title contains special characters.
Chris@0: $edge_case_title = 'article\'s "title".';
Chris@0: $settings = [
Chris@0: 'title' => $edge_case_title,
Chris@0: ];
Chris@0: $node = $this->drupalCreateNode($settings);
Chris@0: // Test that the title appears as . The title will be escaped on the
Chris@0: // the page.
Chris@0: $edge_case_title_escaped = Html::escape($edge_case_title);
Chris@0: $this->drupalGet('node/' . $node->id());
Chris@0: $this->assertRaw('' . $edge_case_title_escaped . ' | Drupal', 'Page title is equal to article\'s "title".', 'Node');
Chris@0:
Chris@0: // Test that the title appears as when reloading the node page.
Chris@0: $this->drupalGet('node/' . $node->id());
Chris@0: $this->assertRaw('' . $edge_case_title_escaped . ' | Drupal', 'Page title is equal to article\'s "title".', 'Node');
Chris@0:
Chris@0: }
Chris@0:
Chris@0: }