function LinkGeneratorTest::testGenerateAttributes

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

Tests the link method with additional attributes.

See also

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

File

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

Class

LinkGeneratorTest
@coversDefaultClass \Drupal\Core\Utility\LinkGenerator[[api-linebreak]] @group Utility

Namespace

Drupal\Tests\Core\Utility

Code

public function testGenerateAttributes() : void {
  $this->urlGenerator
    ->expects($this->once())
    ->method('generateFromRoute')
    ->with('test_route_1', [], $this->defaultOptions)
    ->willReturn((new GeneratedUrl())->setGeneratedUrl('/test-route-1'));
  // Test that HTML attributes are added to the anchor.
  $url = new Url('test_route_1', [], [
    'attributes' => [
      'title' => 'Tooltip',
    ],
  ]);
  $url->setUrlGenerator($this->urlGenerator);
  $result = $this->linkGenerator
    ->generate('Test', $url);
  $this->assertLink([
    'attributes' => [
      'href' => '/test-route-1',
      'title' => 'Tooltip',
    ],
  ], $result);
}

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