function LinkGeneratorTest::testGenerateTwice

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

Tests whether rendering the same link twice works.

This is a regression test for https://www.drupal.org/node/2842399.

File

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

Class

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

Namespace

Drupal\Tests\Core\Utility

Code

public function testGenerateTwice() {
    $this->urlGenerator
        ->expects($this->any())
        ->method('generateFromRoute')
        ->willReturn((new GeneratedUrl())->setGeneratedUrl('/'));
    $url = Url::fromRoute('<front>', [], [
        'attributes' => [
            'class' => [
                'foo',
                'bar',
            ],
        ],
    ]);
    $url->setUrlGenerator($this->urlGenerator);
    $link = Link::fromTextAndUrl('text', $url);
    $link->setLinkGenerator($this->linkGenerator);
    $output = $link->toString() . $link->toString();
    $this->assertEquals('<a href="/" class="foo bar">text</a><a href="/" class="foo bar">text</a>', $output);
}

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