You are here

public function LinkGeneratorTest::testGenerateTwice in Drupal 9

Same name and namespace in other branches
  1. 8 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()

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')
    ->will($this
    ->returnValue((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);
}