You are here

public function LinkGeneratorTest::testGenerateHrefs 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::testGenerateHrefs()

Tests the link method with certain hrefs.

@dataProvider providerTestGenerateHrefs

See also

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

\Drupal\Tests\Core\Utility\LinkGeneratorTest::providerTestGenerate()

File

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

Class

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

Namespace

Drupal\Tests\Core\Utility

Code

public function testGenerateHrefs($route_name, array $parameters, $absolute, $expected_url) {
  $this->urlGenerator
    ->expects($this
    ->once())
    ->method('generateFromRoute')
    ->with($route_name, $parameters, [
    'absolute' => $absolute,
  ] + $this->defaultOptions)
    ->willReturn((new GeneratedUrl())
    ->setGeneratedUrl($expected_url));
  $this->moduleHandler
    ->expects($this
    ->once())
    ->method('alter');
  $url = new Url($route_name, $parameters, [
    'absolute' => $absolute,
  ]);
  $url
    ->setUrlGenerator($this->urlGenerator);
  $result = $this->linkGenerator
    ->generate('Test', $url);
  $this
    ->assertLink([
    'attributes' => [
      'href' => $expected_url,
    ],
  ], $result);
}