You are here

public function LinkGeneratorTest::testGenerateAttributes in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 227
Contains \Drupal\Tests\Core\Utility\LinkGeneratorTest.

Class

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

Namespace

Drupal\Tests\Core\Utility

Code

public function testGenerateAttributes() {
  $this->urlGenerator
    ->expects($this
    ->once())
    ->method('generateFromRoute')
    ->with('test_route_1', array(), $this->defaultOptions)
    ->willReturn((new GeneratedUrl())
    ->setGeneratedUrl('/test-route-1'));

  // Test that HTML attributes are added to the anchor.
  $url = new Url('test_route_1', array(), array(
    'attributes' => array(
      'title' => 'Tooltip',
    ),
  ));
  $url
    ->setUrlGenerator($this->urlGenerator);
  $result = $this->linkGenerator
    ->generate('Test', $url);
  $this
    ->assertLink(array(
    'attributes' => array(
      'href' => '/test-route-1',
      'title' => 'Tooltip',
    ),
  ), $result);
}