1 node.test NodeTitleTestCase::testNodeTitle()

Creates one node and tests if the node title has the correct value.


core/modules/node/tests/node.test, line 2583
Tests for node.module.


Tests node title functionality.


function testNodeTitle() {
  // Create "Page" content with title.
  // Add the node to the frontpage so we can test if teaser links are clickable.
  $settings = array(
    'title' => $this->randomName(8),
    'promote' => 1,
  $node = $this->backdropCreateNode($settings);

  // Test <title> tag.
  $xpath = '//title';
  $this->assertEqual(current($this->xpath($xpath)), $node->title . ' | Backdrop CMS', 'Page title is equal to node title.', 'Node');

  // Test breadcrumb in comment preview.
  $xpath = '//nav[@class="breadcrumb"]/ol/li[last()]/a';
  $this->assertEqual(current($this->xpath($xpath)), $node->title, 'Node breadcrumb is equal to node title.', 'Node');

  // Test node title in comment preview.
  $this->assertEqual(current($this->xpath('//article[@id=:id]//h2/a', array(':id' => 'node-' . $node->nid))), $node->title, 'Node preview title is equal to node title.', 'Node');

  // Test node title is clickable on teaser list (/node).

  // Hide path display for Post node type.
  $config = config('node.type.post');
  $config->set('settings.hidden_path', '1');
  $this->assertEqual($config->get('settings.hidden_path'), '1', 'The POST content type has hidden_path enabled.');

  // Create "Post" content with title.
  $settings = array(
    'type' => 'post',
    'title' => $this->randomName(8),
    'promote' => 1,
  $node = $this->backdropCreateNode($settings);

  // Test post title is clickable for admin account on teaser list (/node).
  $this->assertResponse(200, 'Received 200 response from post with hidden_path.');
  // Test node title is NOT clickable for standard account.
  // Also ensure that there is no "read more" link.
  $this->assertNoLinkByHref(backdrop_get_path_alias('node/' . $node->nid));