You are here

public function TermTest::testTermBreadcrumbs in Drupal 9

Same name and namespace in other branches
  1. 8 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 629

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.
  $this
    ->drupalGet('taxonomy/term/' . $term
    ->id() . '/edit');
  $breadcrumbs = $this
    ->getSession()
    ->getPage()
    ->findAll('css', 'nav.breadcrumb ol li a');
  $this
    ->assertCount(2, $breadcrumbs, 'The breadcrumbs are present on the page.');
  $this
    ->assertSame('Home', $breadcrumbs[0]
    ->getText(), 'First breadcrumb text is Home');
  $this
    ->assertSame($term
    ->label(), $breadcrumbs[1]
    ->getText(), 'Second breadcrumb text is term name on term edit page.');
  $this
    ->assertSession()
    ->assertEscaped($breadcrumbs[1]
    ->getText());

  // Check the breadcrumb on the term delete page.
  $this
    ->drupalGet('taxonomy/term/' . $term
    ->id() . '/delete');
  $breadcrumbs = $this
    ->getSession()
    ->getPage()
    ->findAll('css', 'nav.breadcrumb ol li a');
  $this
    ->assertCount(2, $breadcrumbs, 'The breadcrumbs are present on the page.');
  $this
    ->assertSame('Home', $breadcrumbs[0]
    ->getText(), 'First breadcrumb text is Home');
  $this
    ->assertSame($term
    ->label(), $breadcrumbs[1]
    ->getText(), 'Second breadcrumb text is term name on term delete page.');
  $this
    ->assertSession()
    ->assertEscaped($breadcrumbs[1]
    ->getText());
}