function BookTest::checkBookNode

Checks the outline of sub-pages; previous, up, and next.

Also checks the printer friendly version of the outline.

Parameters

\Drupal\Core\Entity\EntityInterface $node: Node to check.

$nodes: Nodes that should be in outline.

$previous: (optional) Previous link node. Defaults to FALSE.

$up: (optional) Up link node. Defaults to FALSE.

$next: (optional) Next link node. Defaults to FALSE.

array $breadcrumb: The nodes that should be displayed in the breadcrumb.

1 call to BookTest::checkBookNode()
BookTest::testBook in drupal/core/modules/book/lib/Drupal/book/Tests/BookTest.php
Tests book functionality through node interfaces.

File

drupal/core/modules/book/lib/Drupal/book/Tests/BookTest.php, line 162
Definition of Drupal\book\Tests\BookTest.

Class

BookTest
Tests the functionality of the Book module.

Namespace

Drupal\book\Tests

Code

function checkBookNode(EntityInterface $node, $nodes, $previous = FALSE, $up = FALSE, $next = FALSE, array $breadcrumb) {

  // $number does not use drupal_static as it should not be reset
  // since it uniquely identifies each call to checkBookNode().
  static $number = 0;
  $this
    ->drupalGet('node/' . $node->nid);

  // Check outline structure.
  if ($nodes !== NULL) {
    $this
      ->assertPattern($this
      ->generateOutlinePattern($nodes), format_string('Node @number outline confirmed.', array(
      '@number' => $number,
    )));
  }
  else {
    $this
      ->pass(format_string('Node %number does not have outline.', array(
      '%number' => $number,
    )));
  }

  // Check previous, up, and next links.
  if ($previous) {
    $this
      ->assertRaw(l('<b>‹</b> ' . $previous
      ->label(), 'node/' . $previous->nid, array(
      'html' => TRUE,
      'attributes' => array(
        'rel' => array(
          'prev',
        ),
        'title' => t('Go to previous page'),
      ),
    )), 'Previous page link found.');
  }
  if ($up) {
    $this
      ->assertRaw(l('Up', 'node/' . $up->nid, array(
      'html' => TRUE,
      'attributes' => array(
        'title' => t('Go to parent page'),
      ),
    )), 'Up page link found.');
  }
  if ($next) {
    $this
      ->assertRaw(l($next
      ->label() . ' <b>›</b>', 'node/' . $next->nid, array(
      'html' => TRUE,
      'attributes' => array(
        'rel' => array(
          'next',
        ),
        'title' => t('Go to next page'),
      ),
    )), 'Next page link found.');
  }

  // Compute the expected breadcrumb.
  $expected_breadcrumb = array();
  $expected_breadcrumb[] = url('');
  foreach ($breadcrumb as $a_node) {
    $expected_breadcrumb[] = url('node/' . $a_node->nid);
  }

  // Fetch links in the current breadcrumb.
  $links = $this
    ->xpath('//nav[@class="breadcrumb"]/ol/li/a');
  $got_breadcrumb = array();
  foreach ($links as $link) {
    $got_breadcrumb[] = (string) $link['href'];
  }

  // Compare expected and got breadcrumbs.
  $this
    ->assertIdentical($expected_breadcrumb, $got_breadcrumb, 'The breadcrumb is correctly displayed on the page.');

  // Check printer friendly version.
  $this
    ->drupalGet('book/export/html/' . $node->nid);
  $this
    ->assertText($node
    ->label(), 'Printer friendly title found.');
  $this
    ->assertRaw(check_markup($node->body[Language::LANGCODE_NOT_SPECIFIED][0]['value'], $node->body[Language::LANGCODE_NOT_SPECIFIED][0]['format']), 'Printer friendly body found.');
  $number++;
}