function BookTestTrait::checkBookNode
Same name in other branches
- 8.9.x core/modules/book/tests/src/Functional/BookTestTrait.php \Drupal\Tests\book\Functional\BookTestTrait::checkBookNode()
- 10 core/modules/book/tests/src/Functional/BookTestTrait.php \Drupal\Tests\book\Functional\BookTestTrait::checkBookNode()
- 11.x core/modules/book/tests/src/Functional/BookTestTrait.php \Drupal\Tests\book\Functional\BookTestTrait::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: Previous link node.
$up: Up link node.
$next: Next link node.
array $breadcrumb: The nodes that should be displayed in the breadcrumb.
2 calls to BookTestTrait::checkBookNode()
- BookContentModerationTest::testBookWithPendingRevisions in core/
modules/ book/ tests/ src/ Functional/ BookContentModerationTest.php - Tests that book drafts can not modify the book outline.
- BookTest::testBook in core/
modules/ book/ tests/ src/ Functional/ BookTest.php - Tests book functionality through node interfaces.
File
-
core/
modules/ book/ tests/ src/ Functional/ BookTestTrait.php, line 90
Class
- BookTestTrait
- Provides common functionality for Book test classes.
Namespace
Drupal\Tests\book\FunctionalCode
public function checkBookNode(EntityInterface $node, $nodes, $previous, $up, $next, 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->id());
// Check outline structure.
if ($nodes !== NULL) {
$this->assertSession()
->responseMatches($this->generateOutlinePattern($nodes));
}
// Check previous, up, and next links.
if ($previous) {
/** @var \Drupal\Core\Url $url */
$url = $previous->toUrl();
$url->setOptions([
'attributes' => [
'rel' => [
'prev',
],
'title' => t('Go to previous page'),
],
]);
$text = new FormattableMarkup('<b>‹</b> @label', [
'@label' => $previous->label(),
]);
$this->assertSession()
->responseContains(Link::fromTextAndUrl($text, $url)->toString());
}
if ($up) {
/** @var \Drupal\Core\Url $url */
$url = $up->toUrl();
$url->setOptions([
'attributes' => [
'title' => t('Go to parent page'),
],
]);
$this->assertSession()
->responseContains(Link::fromTextAndUrl('Up', $url)->toString());
}
if ($next) {
/** @var \Drupal\Core\Url $url */
$url = $next->toUrl();
$url->setOptions([
'attributes' => [
'rel' => [
'next',
],
'title' => t('Go to next page'),
],
]);
$text = new FormattableMarkup('@label <b>›</b>', [
'@label' => $next->label(),
]);
$this->assertSession()
->responseContains(Link::fromTextAndUrl($text, $url)->toString());
}
// Compute the expected breadcrumb.
$expected_breadcrumb = [];
$expected_breadcrumb[] = Url::fromRoute('<front>')->toString();
foreach ($breadcrumb as $a_node) {
$expected_breadcrumb[] = $a_node->toUrl()
->toString();
}
// Fetch links in the current breadcrumb.
$links = $this->xpath('//nav[@aria-labelledby="system-breadcrumb"]/ol/li/a');
$got_breadcrumb = [];
foreach ($links as $link) {
$got_breadcrumb[] = $link->getAttribute('href');
}
// Compare expected and got breadcrumbs.
$this->assertSame($expected_breadcrumb, $got_breadcrumb, 'The breadcrumb is correctly displayed on the page.');
// Check printer friendly version.
$this->drupalGet('book/export/html/' . $node->id());
$this->assertSession()
->pageTextContains($node->label());
$this->assertSession()
->responseContains($node->body->processed);
$number++;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.