public function CustomBreadcrumbsTest::testNodeBreadcrumbs in Custom Breadcrumbs 1.x
Tests a custom breadcrumbs for nodes.
File
- tests/
src/ Functional/ CustomBreadcrumbsTest.php, line 60
Class
- CustomBreadcrumbsTest
- Tests custom breadcrumbs.
Namespace
Drupal\Tests\custom_breadcrumbs\FunctionalCode
public function testNodeBreadcrumbs() {
// Add a custom breadcrumbs to the Basic page and Article.
$edit = [
'label' => 'Article breadcrumbs',
'id' => 'article_breadcrumbs',
'status' => 1,
'breadcrumbPaths' => "/foo\n/bar",
'breadcrumbTitles' => "Foo\nBar",
'entityType' => 'node',
];
$this
->drupalGet('admin/structure/custom_breadcrumbs/add');
$this
->submitForm($edit, 'Save');
$edit = [
'label' => 'Page breadcrumbs',
'id' => 'page_breadcrumbs',
'status' => 1,
'breadcrumbPaths' => "/foo2\n/bar2",
'breadcrumbTitles' => "Foo2\nBar2",
'entityType' => 'node',
];
$this
->drupalGet('admin/structure/custom_breadcrumbs/add');
$this
->submitForm($edit, 'Save');
// An additional additional options were not available the first time due to
// the disabled ajax. Edit the custom breadcrumbs again and select the
// entity bundle.
$edit = [
'entityBundle' => 'article',
];
$this
->drupalGet('admin/structure/custom-breadcrumbs/article_breadcrumbs');
$this
->submitForm($edit, 'Save');
$edit = [
'entityBundle' => 'page',
];
$this
->drupalGet('admin/structure/custom-breadcrumbs/page_breadcrumbs');
$this
->submitForm($edit, 'Save');
$this
->drupalCreateNode([
'title' => $this
->randomString(),
'id' => 1,
'type' => 'article',
]);
$this
->drupalCreateNode([
'title' => $this
->randomString(),
'id' => 2,
'type' => 'page',
]);
$home_path = Url::fromRoute('<front>')
->toString();
$this
->assertBreadcrumb('node/1', [
$home_path => 'Home',
'foo' => 'Foo',
'bar' => 'Bar',
]);
$this
->assertBreadcrumb('node/2', [
$home_path => 'Home',
'foo2' => 'Foo2',
'bar2' => 'Bar2',
]);
}