public function CustomBreadcrumbsTest::testPathBreadcrumbs in Custom Breadcrumbs 1.x
Tests a custom breadcrumbs for paths.
File
- tests/
src/ Functional/ CustomBreadcrumbsTest.php, line 126
Class
- CustomBreadcrumbsTest
- Tests custom breadcrumbs.
Namespace
Drupal\Tests\custom_breadcrumbs\FunctionalCode
public function testPathBreadcrumbs() {
// Create node 1.
$this
->drupalCreateNode([
'title' => $this
->randomString(),
'id' => 1,
'type' => 'article',
]);
// Add a custom breadcrumbs type path.
$edit = [
'label' => 'Path breadcrumbs',
'id' => 'path_breadcrumbs',
'status' => 1,
'type' => 2,
'pathPattern' => "/node/1",
'breadcrumbPaths' => "/foo\n/bar",
'breadcrumbTitles' => "Foo\nBar",
];
$this
->drupalGet('admin/structure/custom_breadcrumbs/add');
$this
->submitForm($edit, 'Save');
$home_path = Url::fromRoute('<front>')
->toString();
$this
->assertBreadcrumb('node/1', [
$home_path => 'Home',
'foo' => 'Foo',
'bar' => 'Bar',
]);
// Create node 2.
$this
->drupalCreateNode([
'title' => $this
->randomString(),
'id' => 2,
'type' => 'article',
]);
// Add one more path pattern to the custom breadcrumb.
$edit = [
'pathPattern' => "/node/1\n/node/2",
];
$this
->drupalGet('admin/structure/custom-breadcrumbs/path_breadcrumbs');
$this
->submitForm($edit, 'Save');
// Test with more than one path pattern.
$this
->assertBreadcrumb('node/1', [
$home_path => 'Home',
'foo' => 'Foo',
'bar' => 'Bar',
]);
$this
->assertBreadcrumb('node/2', [
$home_path => 'Home',
'foo' => 'Foo',
'bar' => 'Bar',
]);
}