function LinkGeneratorTest::testGenerateHrefs

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php \Drupal\Tests\Core\Utility\LinkGeneratorTest::testGenerateHrefs()
  2. 8.9.x core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php \Drupal\Tests\Core\Utility\LinkGeneratorTest::testGenerateHrefs()
  3. 11.x 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 113

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) : void {
    $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);
}

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