BreadcrumbsTest.php in GraphQL 8.3
File
modules/graphql_core/tests/src/Kernel/Breadcrumbs/BreadcrumbsTest.php
View source
<?php
namespace Drupal\Tests\graphql_core\Kernel\Breadcrumbs;
use Drupal\Core\Breadcrumb\Breadcrumb;
use Drupal\Core\Link;
use Drupal\Core\Url;
use Drupal\Tests\graphql_core\Kernel\GraphQLCoreTestBase;
use Prophecy\Argument;
class BreadcrumbsTest extends GraphQLCoreTestBase {
public static $modules = [
'graphql_breadcrumbs_test',
];
protected function setUp() {
parent::setUp();
$breadcrumbManager = $this
->prophesize('Drupal\\Core\\Breadcrumb\\BreadcrumbManager');
$breadcrumbManager
->build(Argument::any())
->will(function ($args) {
$routeMatch = $args[0];
$breadcrumb = new Breadcrumb();
if ($routeMatch
->getRouteName() == 'graphql_breadcrumbs_test.test') {
$breadcrumb
->addLink(new Link('Test breadcrumb', Url::fromUserInput('/breadcrumbs-test')));
}
return $breadcrumb;
});
$this->container
->set('breadcrumb', $breadcrumbManager
->reveal());
}
public function testBreadcrumbs() {
$query = $this
->getQueryFromFile('breadcrumbs.gql');
$metadata = $this
->defaultCacheMetaData();
$this
->assertResults($query, [
'path' => '/breadcrumbs-test',
], [
'route' => [
'breadcrumb' => [
0 => [
'text' => 'Test breadcrumb',
],
],
],
], $metadata);
}
}