You are here

public function LinkGeneratorTest::testGenerate in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php \Drupal\Tests\Core\Utility\LinkGeneratorTest::testGenerate()

Tests the generate() method with a route.

@covers ::generate

File

core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php, line 132
Contains \Drupal\Tests\Core\Utility\LinkGeneratorTest.

Class

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

Namespace

Drupal\Tests\Core\Utility

Code

public function testGenerate() {
  $this->urlGenerator
    ->expects($this
    ->once())
    ->method('generateFromRoute')
    ->with('test_route_1', array(), array(
    'fragment' => 'the-fragment',
  ) + $this->defaultOptions)
    ->willReturn((new GeneratedUrl())
    ->setGeneratedUrl('/test-route-1#the-fragment'));
  $this->moduleHandler
    ->expects($this
    ->once())
    ->method('alter')
    ->with('link', $this
    ->isType('array'));
  $url = new Url('test_route_1', array(), array(
    'fragment' => 'the-fragment',
  ));
  $url
    ->setUrlGenerator($this->urlGenerator);
  $result = $this->linkGenerator
    ->generate('Test', $url);
  $this
    ->assertLink(array(
    'attributes' => array(
      'href' => '/test-route-1#the-fragment',
    ),
    'content' => 'Test',
  ), $result);
}