function LinkGeneratorTest::testGenerateOptions

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

Tests the link method with arbitrary passed options.

See also

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

File

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

Class

LinkGeneratorTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Utility%21LinkGenerator.php/class/LinkGenerator/8.9.x" title="Provides a class which generates a link with route names and parameters." class="local">\Drupal\Core\Utility\LinkGenerator</a> @group Utility

Namespace

Drupal\Tests\Core\Utility

Code

public function testGenerateOptions() {
    $this->urlGenerator
        ->expects($this->once())
        ->method('generateFromRoute')
        ->with('test_route_1', [], [
        'key' => 'value',
    ] + $this->defaultOptions)
        ->willReturn((new GeneratedUrl())->setGeneratedUrl('/test-route-1?test=value'));
    $url = new Url('test_route_1', [], [
        'key' => 'value',
    ]);
    $url->setUrlGenerator($this->urlGenerator);
    $result = $this->linkGenerator
        ->generate('Test', $url);
    $this->assertLink([
        'attributes' => [
            'href' => '/test-route-1?test=value',
        ],
    ], $result);
}

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