function TermTest::testTermBreadcrumbs

Same name in other branches
  1. 8.9.x core/modules/taxonomy/tests/src/Functional/TermTest.php \Drupal\Tests\taxonomy\Functional\TermTest::testTermBreadcrumbs()
  2. 10 core/modules/taxonomy/tests/src/Functional/TermTest.php \Drupal\Tests\taxonomy\Functional\TermTest::testTermBreadcrumbs()
  3. 11.x core/modules/taxonomy/tests/src/Functional/TermTest.php \Drupal\Tests\taxonomy\Functional\TermTest::testTermBreadcrumbs()

Check the breadcrumb on edit and delete a term page.

File

core/modules/taxonomy/tests/src/Functional/TermTest.php, line 738

Class

TermTest
Tests load, save and delete for taxonomy terms.

Namespace

Drupal\Tests\taxonomy\Functional

Code

public function testTermBreadcrumbs() {
    $edit = [
        'name[0][value]' => $this->randomMachineName(14),
        'description[0][value]' => $this->randomMachineName(100),
        'parent[]' => [
            0,
        ],
    ];
    // Create the term.
    $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary
        ->id() . '/add');
    $this->submitForm($edit, 'Save');
    $terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')
        ->loadByProperties([
        'name' => $edit['name[0][value]'],
    ]);
    $term = reset($terms);
    $this->assertNotNull($term, 'Term found in database.');
    // Check the breadcrumb on the term edit page.
    $trail = [
        '' => 'Home',
        'taxonomy/term/' . $term->id() => $term->label(),
    ];
    $this->assertBreadcrumb('taxonomy/term/' . $term->id() . '/edit', $trail);
    $this->assertSession()
        ->assertEscaped($term->label());
    // Check the breadcrumb on the term delete page.
    $trail = [
        '' => 'Home',
        'taxonomy/term/' . $term->id() => $term->label(),
    ];
    $this->assertBreadcrumb('taxonomy/term/' . $term->id() . '/delete', $trail);
    $this->assertSession()
        ->assertEscaped($term->label());
}

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