function BookTest::testBookExport

Tests book export ("printer-friendly version") functionality.

File

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

Class

BookTest

Namespace

Drupal\book\Tests

Code

function testBookExport() {

  // Create a book.
  $nodes = $this
    ->createBook();

  // Login as web user and view printer-friendly version.
  $this
    ->drupalLogin($this->web_user);
  $this
    ->drupalGet('node/' . $this->book->nid);
  $this
    ->clickLink(t('Printer-friendly version'));

  // Make sure each part of the book is there.
  foreach ($nodes as $node) {
    $this
      ->assertText($node
      ->label(), 'Node title found in printer friendly version.');
    $this
      ->assertRaw(check_markup($node->body[LANGUAGE_NOT_SPECIFIED][0]['value'], $node->body[LANGUAGE_NOT_SPECIFIED][0]['format']), 'Node body found in printer friendly version.');
  }

  // Make sure we can't export an unsupported format.
  $this
    ->drupalGet('book/export/foobar/' . $this->book->nid);
  $this
    ->assertResponse('404', 'Unsupported export format returned "not found".');

  // Make sure we get a 404 on a not existing book node.
  $this
    ->drupalGet('book/export/html/123');
  $this
    ->assertResponse('404', 'Not existing book node returned "not found".');

  // Make sure an anonymous user cannot view printer-friendly version.
  $this
    ->drupalLogout();

  // Load the book and verify there is no printer-friendly version link.
  $this
    ->drupalGet('node/' . $this->book->nid);
  $this
    ->assertNoLink(t('Printer-friendly version'), 'Anonymous user is not shown link to printer-friendly version.');

  // Try getting the URL directly, and verify it fails.
  $this
    ->drupalGet('book/export/html/' . $this->book->nid);
  $this
    ->assertResponse('403', 'Anonymous user properly forbidden.');
}