function BreadcrumbTest::testAssertBreadcrumbTrait
Same name in other branches
- 9 core/modules/system/tests/src/Functional/Menu/BreadcrumbTest.php \Drupal\Tests\system\Functional\Menu\BreadcrumbTest::testAssertBreadcrumbTrait()
- 8.9.x core/modules/system/tests/src/Functional/Menu/BreadcrumbTest.php \Drupal\Tests\system\Functional\Menu\BreadcrumbTest::testAssertBreadcrumbTrait()
- 10 core/modules/system/tests/src/Functional/Menu/BreadcrumbTest.php \Drupal\Tests\system\Functional\Menu\BreadcrumbTest::testAssertBreadcrumbTrait()
Tests AssertBreadcrumbTrait works as expected.
File
-
core/
modules/ system/ tests/ src/ Functional/ Menu/ BreadcrumbTest.php, line 396
Class
- BreadcrumbTest
- Tests breadcrumbs functionality.
Namespace
Drupal\Tests\system\Functional\MenuCode
public function testAssertBreadcrumbTrait() : void {
// Ensure the test trait works as expected using menu_test routes.
$home = [
'' => 'Home',
];
$trail = $home + [
'menu-test' => 'Menu test root',
];
// Test a passing assertion.
$this->assertBreadcrumb('menu-test/breadcrumb1', $trail);
// If there is no trail, this assert should fail.
$message = 'Breadcrumb assertion should fail with empty trail.';
try {
$this->assertBreadcrumb('menu-test/breadcrumb1', []);
$this->fail($message);
} catch (ExpectationFailedException) {
$this->assertTrue(TRUE, $message);
}
// If the trail is incorrect, this assert should fail.
$message = 'Breadcrumb assertion should fail with incorrect trail.';
try {
$this->assertBreadcrumb('menu-test/breadcrumb1', $home);
$this->fail($message);
} catch (ExpectationFailedException) {
$this->assertTrue(TRUE, $message);
}
// Remove the breadcrumb block to test the trait when breadcrumbs are not
// shown.
Block::load('olivero_breadcrumbs')->delete();
// If there is no trail, this should pass as there is no breadcrumb.
$this->assertBreadcrumb('menu-test/breadcrumb1', []);
// If there is a trail, this should fail as there is no breadcrumb.
$message = 'Breadcrumb assertion should fail when breadcrumb block deleted and there is a trail.';
try {
$this->assertBreadcrumb('menu-test/breadcrumb1', $trail);
$this->fail($message);
} catch (ExpectationFailedException) {
$this->assertTrue(TRUE, $message);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.