public function BookTest::testBookExport in Drupal 9
Same name and namespace in other branches
- 8 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 247
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('Printer-friendly version');
// Make sure each part of the book is there.
foreach ($nodes as $node) {
$this
->assertSession()
->pageTextContains($node
->label());
$this
->assertSession()
->responseContains($node->body->processed);
}
// 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 non-existent 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('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);
}