function BreadcrumbTest::testAssertBreadcrumbTrait

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Menu/BreadcrumbTest.php \Drupal\Tests\system\Functional\Menu\BreadcrumbTest::testAssertBreadcrumbTrait()
  2. 10 core/modules/system/tests/src/Functional/Menu/BreadcrumbTest.php \Drupal\Tests\system\Functional\Menu\BreadcrumbTest::testAssertBreadcrumbTrait()
  3. 11.x 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 390

Class

BreadcrumbTest
Tests breadcrumbs functionality.

Namespace

Drupal\Tests\system\Functional\Menu

Code

public function testAssertBreadcrumbTrait() {
    // Ensure the test trait works as expected using menu_test routes.
    $home = [
        '' => 'Home',
    ];
    $trail = $home + [
        'menu-test' => t('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 $e) {
        $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 $e) {
        $this->assertTrue(TRUE, $message);
    }
    // Remove the breadcrumb block to test the trait when breadcrumbs are not
    // shown.
    Block::load('bartik_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 $e) {
        $this->assertTrue(TRUE, $message);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.