public function BookTest::testBookExport in Drupal 8
Same name and namespace in other branches
- 9 core/modules/book/tests/src/Functional/BookTest.php \Drupal\Tests\book\Functional\BookTest::testBookExport()
Tests book export ("printer-friendly version") functionality.
File
- core/
modules/ book/ tests/ src/ Functional/ BookTest.php, line 225
Class
- BookTest
- Create a book, add pages, and test book interface.
Namespace
Drupal\Tests\book\FunctionalCode
public function testBookExport() {
// Create a book.
$nodes = $this
->createBook();
// Log in as web user and view printer-friendly version.
$this
->drupalLogin($this->webUser);
$this
->drupalGet('node/' . $this->book
->id());
$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($node->body->processed, 'Node body found in printer friendly version.');
}
// Make sure we can't export an unsupported format.
$this
->drupalGet('book/export/foobar/' . $this->book
->id());
$this
->assertSession()
->statusCodeEquals(404);
// Make sure we get a 404 on a not existing book node.
$this
->drupalGet('book/export/html/123');
$this
->assertSession()
->statusCodeEquals(404);
// 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
->id());
$this
->assertSession()
->linkNotExists(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
->id());
$this
->assertSession()
->statusCodeEquals(403);
// Now grant anonymous users permission to view the printer-friendly
// version and verify that node access restrictions still prevent them from
// seeing it.
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, [
'access printer-friendly version',
]);
$this
->drupalGet('book/export/html/' . $this->book
->id());
$this
->assertSession()
->statusCodeEquals(403);
}