protected function AssertBreadcrumbTrait::assertBreadcrumbParts in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/src/Tests/Menu/AssertBreadcrumbTrait.php \Drupal\system\Tests\Menu\AssertBreadcrumbTrait::assertBreadcrumbParts()
Assert that a trail exists in the internal browser.
Parameters
array $trail: An associative array whose keys are expected breadcrumb link paths and whose values are expected breadcrumb link texts (not sanitized).
1 call to AssertBreadcrumbTrait::assertBreadcrumbParts()
- AssertBreadcrumbTrait::assertBreadcrumb in core/
modules/ system/ src/ Tests/ Menu/ AssertBreadcrumbTrait.php - Assert that a given path shows certain breadcrumb links.
File
- core/
modules/ system/ src/ Tests/ Menu/ AssertBreadcrumbTrait.php, line 64 - Contains \Drupal\system\Tests\Menu\AssertBreadcrumbTrait.
Class
- AssertBreadcrumbTrait
- Provides test assertions for verifying breadcrumbs.
Namespace
Drupal\system\Tests\MenuCode
protected function assertBreadcrumbParts($trail) {
// Compare paths with actual breadcrumb.
$parts = $this
->getBreadcrumbParts();
$pass = TRUE;
// There may be more than one breadcrumb on the page. If $trail is empty
// this test would go into an infinite loop, so we need to check that too.
while ($trail && !empty($parts)) {
foreach ($trail as $path => $title) {
// If the path is empty, generate the path from the <front> route. If
// the path does not start with a leading slash, then run it through
// Url::fromUri('base:')->toString() to get the correct base
// prepended.
if ($path == '') {
$url = Url::fromRoute('<front>')
->toString();
}
elseif ($path[0] != '/') {
$url = Url::fromUri('base:' . $path)
->toString();
}
else {
$url = $path;
}
$part = array_shift($parts);
$pass = $pass && $part['href'] === $url && $part['text'] === Html::escape($title);
}
}
// No parts must be left, or an expected "Home" will always pass.
$pass = $pass && empty($parts);
$this
->assertTrue($pass, format_string('Breadcrumb %parts found on @path.', array(
'%parts' => implode(' » ', $trail),
'@path' => $this
->getUrl(),
)));
}