function BookTest::checkBookNode in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/book/src/Tests/BookTest.php \Drupal\book\Tests\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 core/
modules/ book/ src/ Tests/ BookTest.php - Tests book functionality through node interfaces.
File
- core/
modules/ book/ src/ Tests/ BookTest.php, line 253 - Contains \Drupal\book\Tests\BookTest.
Class
- BookTest
- Create a book, add pages, and test book interface.
Namespace
Drupal\book\TestsCode
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
->id());
// 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) {
/** @var \Drupal\Core\Url $url */
$url = $previous
->urlInfo();
$url
->setOptions(array(
'attributes' => array(
'rel' => array(
'prev',
),
'title' => t('Go to previous page'),
),
));
$text = SafeMarkup::format('<b>‹</b> @label', array(
'@label' => $previous
->label(),
));
$this
->assertRaw(\Drupal::l($text, $url), 'Previous page link found.');
}
if ($up) {
/** @var \Drupal\Core\Url $url */
$url = $up
->urlInfo();
$url
->setOptions(array(
'attributes' => array(
'title' => t('Go to parent page'),
),
));
$this
->assertRaw(\Drupal::l('Up', $url), 'Up page link found.');
}
if ($next) {
/** @var \Drupal\Core\Url $url */
$url = $next
->urlInfo();
$url
->setOptions(array(
'attributes' => array(
'rel' => array(
'next',
),
'title' => t('Go to next page'),
),
));
$text = SafeMarkup::format('@label <b>›</b>', array(
'@label' => $next
->label(),
));
$this
->assertRaw(\Drupal::l($text, $url), 'Next page link found.');
}
// Compute the expected breadcrumb.
$expected_breadcrumb = array();
$expected_breadcrumb[] = \Drupal::url('<front>');
foreach ($breadcrumb as $a_node) {
$expected_breadcrumb[] = $a_node
->url();
}
// 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
->id());
$this
->assertText($node
->label(), 'Printer friendly title found.');
$this
->assertRaw($node->body->processed, 'Printer friendly body found.');
$number++;
}