assertBreadcrumb example

$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());
  }

}
ConfigurableLanguage::createFromLangcode('de')->save();
    ConfigurableLanguage::createFromLangcode('gsw-berne')->save();
  }

  /** * Tests breadcrumbs with URL prefixes. */
  public function testBreadCrumbs() {
    // /user/login is the default frontpage which only works for an anonymous     // user. Access the frontpage in different languages, ensure that no     // breadcrumb is displayed.     $this->assertBreadcrumb('user/login', []);
    $this->assertBreadcrumb('de/user/login', []);
    $this->assertBreadcrumb('gsw-berne/user/login', []);

    $admin_user = $this->drupalCreateUser(['access administration pages']);
    $this->drupalLogin($admin_user);

    // Use administration routes to assert that breadcrumb is displayed     // correctly on pages other than the frontpage.     $this->assertBreadcrumb('admin', [
      '' => 'Home',
    ]);
    
$bundle_info = \Drupal::service('entity_type.bundle.info');
    $node_bundles = $bundle_info->getBundleInfo('node');
    $this->assertEquals('NewBar', $node_bundles['page']['label'], 'Node type bundle cache is updated');

    // Remove the body field.     $this->drupalGet('admin/structure/types/manage/page/fields/node.page.body/delete');
    $this->submitForm([], 'Delete');
    // Resave the settings for this type.     $this->drupalGet('admin/structure/types/manage/page');
    $this->submitForm([], 'Save content type');
    $front_page_path = Url::fromRoute('<front>')->toString();
    $this->assertBreadcrumb('admin/structure/types/manage/page/fields', [
      $front_page_path => 'Home',
      'admin/structure/types' => 'Content types',
      'admin/structure/types/manage/page' => 'NewBar',
    ]);
    // Check that the body field doesn't exist.     $this->drupalGet('node/add/page');
    $assert->pageTextNotContains('Body');
  }

  /** * Tests deleting a content type that still has content. */
$this->assertSession()->pageTextContains('Block description');
    $this->assertNotEmpty($this->cssSelect('#edit-body-0-value'), 'Body field was found.');

    // Change the block type name.     $edit = [
      'label' => 'Bar',
    ];
    $this->drupalGet('admin/structure/block-content/manage/basic');
    $this->assertSession()->titleEquals('Edit basic block type | Drupal');
    $this->submitForm($edit, 'Save');
    $front_page_path = Url::fromRoute('<front>')->toString();
    $this->assertBreadcrumb('admin/structure/block-content/manage/basic/fields', [
      $front_page_path => 'Home',
      'admin/structure/block-content' => 'Block types',
      'admin/structure/block-content/manage/basic' => 'Edit Bar',
    ]);
    \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();

    $this->drupalGet('block/add');
    $this->assertSession()->pageTextContains('Bar');
    $this->clickLink('Bar');
    // Verify that the original machine name was used in the URL.     $this->assertSession()->addressEquals(Url::fromRoute('block_content.add_form', ['block_content_type' => 'basic']));

    
// Test deleting the block.     $this->drupalGet("admin/content/block/" . $revised_block->id());
    $this->clickLink('Delete');
    $this->assertSession()->pageTextContains('Are you sure you want to delete the content block ' . $revised_block->label() . '?');

    // Test breadcrumb.     $trail = [
      '' => 'Home',
      'admin/content/block' => 'Content blocks',
      'admin/content/block/' . $revised_block->id() => $revised_block->label(),
    ];
    $this->assertBreadcrumb(
      'admin/content/block/' . $revised_block->id() . '/delete', $trail
    );
  }

}
private function verifyBreadcrumbs() {
    // View the database log event page.     $query = Database::getConnection()->select('watchdog');
    $query->addExpression('MIN([wid])');
    $wid = $query->execute()->fetchField();
    $trail = [
      '' => 'Home',
      'admin' => 'Administration',
      'admin/reports' => 'Reports',
      'admin/reports/dblog' => 'Recent log messages',
    ];
    $this->assertBreadcrumb('admin/reports/dblog/event/' . $wid$trail);
  }

  /** * Generates and then verifies various types of events. */
  private function verifyEvents() {
    // Invoke events.     $this->doUser();
    $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
    $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
    $this->doNode('article');
    
/** * Tests breadcrumb on a help topic page. */
  public function verifyBreadCrumb() {
    // Verify Help Topics administration breadcrumbs.     $trail = [
      '' => 'Home',
      'admin' => 'Administration',
      'admin/help' => 'Help',
    ];
    $this->assertBreadcrumb('admin/help/topic/help_topics_test.test', $trail);
    // Ensure we are on the expected help topic page.     $this->assertSession()->pageTextContains('Also there should be a related topic link below to the Help module topic page and the linked topic.');

    // Verify that another page does not have the help breadcrumb.     $trail = [
      '' => 'Home',
      'admin' => 'Administration',
      'admin/config' => 'Configuration',
      'admin/config/system' => 'System',
    ];
    $this->assertBreadcrumb('admin/config/system/site-information', $trail);
  }
public function testTranslatedBreadcrumbs() {
    // Ensure non-translated breadcrumb is correct.     $breadcrumb = [Url::fromRoute('<front>')->toString() => 'Home'];
    foreach ($this->terms as $term) {
      $breadcrumb[$term->toUrl()->toString()] = $term->label();
    }
    // The last item will not be in the breadcrumb.     array_pop($breadcrumb);

    // Check the breadcrumb on the leaf term page.     $term = $this->getLeafTerm();
    $this->assertBreadcrumb($term->toUrl()$breadcrumb$term->label());

    $languages = \Drupal::languageManager()->getLanguages();

    // Construct the expected translated breadcrumb.     $breadcrumb = [Url::fromRoute('<front>', []['language' => $languages[$this->translateToLangcode]])->toString() => 'Home'];
    foreach ($this->terms as $term) {
      $translated = $term->getTranslation($this->translateToLangcode);
      $url = $translated->toUrl('canonical', ['language' => $languages[$this->translateToLangcode]])->toString();
      $breadcrumb[$url] = $translated->label();
    }
    array_pop($breadcrumb);

    
    $settings = [
      'title' => $this->randomMachineName(8),
      'promote' => 1,
    ];
    $node = $this->drupalCreateNode($settings);

    // Test <title> tag.     $this->drupalGet('node/' . $node->id());
    $this->assertSession()->elementTextEquals('xpath', '//title', $node->label() . ' | Drupal');

    // Test breadcrumb in comment preview.     $this->assertBreadcrumb('comment/reply/node/' . $node->id() . '/comment', [
      '' => 'Home',
      'node/' . $node->id() => $node->label(),
    ]);

    // Verify that node preview title is equal to node title.     $this->assertSession()->elementTextEquals('xpath', "//article/h2/a/span", $node->label());

    // Test node title is clickable on teaser list (/node).     $this->drupalGet('node');
    $this->clickLink($node->label());

    
public function testBreadCrumbs() {
    // Prepare common base breadcrumb elements.     $home = ['' => 'Home'];
    $admin = $home + ['admin' => 'Administration'];
    $config = $admin + ['admin/config' => 'Configuration'];
    $type = 'article';

    // Verify Taxonomy administration breadcrumbs.     $trail = $admin + [
      'admin/structure' => 'Structure',
    ];
    $this->assertBreadcrumb('admin/structure/taxonomy', $trail);

    $trail += [
      'admin/structure/taxonomy' => 'Taxonomy',
    ];
    $this->assertBreadcrumb('admin/structure/taxonomy/manage/tags', $trail);
    $trail += [
      'admin/structure/taxonomy/manage/tags' => 'Edit Tags',
    ];
    $this->assertBreadcrumb('admin/structure/taxonomy/manage/tags/overview', $trail);
    $this->assertBreadcrumb('admin/structure/taxonomy/manage/tags/add', $trail);

    
Home | Imprint | This part of the site doesn't use cookies.