function LinkGeneratorTest::testGenerateBubbleableMetadata

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php \Drupal\Tests\Core\Utility\LinkGeneratorTest::testGenerateBubbleableMetadata()
  2. 8.9.x core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php \Drupal\Tests\Core\Utility\LinkGeneratorTest::testGenerateBubbleableMetadata()
  3. 10 core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php \Drupal\Tests\Core\Utility\LinkGeneratorTest::testGenerateBubbleableMetadata()

Tests the LinkGenerator's support for collecting bubbleable metadata.

See also

\Drupal\Core\Utility\LinkGenerator::generate()

File

core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php, line 554

Class

LinkGeneratorTest
@coversDefaultClass \Drupal\Core\Utility\LinkGenerator @group Utility

Namespace

Drupal\Tests\Core\Utility

Code

public function testGenerateBubbleableMetadata() : void {
    $options = [
        'query' => [],
        'language' => NULL,
        'set_active_class' => FALSE,
        'absolute' => FALSE,
    ];
    $this->urlGenerator
        ->expects($this->any())
        ->method('generateFromRoute')
        ->willReturnMap([
        [
            'test_route_1',
            [],
            $options,
            TRUE,
            (new GeneratedUrl())->setGeneratedUrl('/test-route-1'),
        ],
    ]);
    $url = new Url('test_route_1');
    $url->setUrlGenerator($this->urlGenerator);
    $expected_link_markup = '<a href="/test-route-1">Test</a>';
    // Test ::generate().
    $this->assertSame($expected_link_markup, (string) $this->linkGenerator
        ->generate('Test', $url));
    $generated_link = $this->linkGenerator
        ->generate('Test', $url);
    $this->assertSame($expected_link_markup, (string) $generated_link->getGeneratedLink());
    $this->assertInstanceOf('\\Drupal\\Core\\Render\\BubbleableMetadata', $generated_link);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.