You are here

public function UrlGeneratorTraitTest::testUrl in Drupal 8

@covers ::url

@expectedDeprecation Drupal\Core\Routing\UrlGeneratorTrait::url() is deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Url::fromUri() instead. See https://www.drupal.org/node/2614344

File

core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTraitTest.php, line 64

Class

UrlGeneratorTraitTest
@coversDefaultClass \Drupal\Core\Routing\UrlGeneratorTrait @group Routing @group legacy

Namespace

Drupal\Tests\Core\Routing

Code

public function testUrl() {
  $route_name = 'some_route_name';
  $generated_url = 'some/generated/url';
  $url_generator = $this
    ->createMock('Drupal\\Core\\Routing\\UrlGeneratorInterface');
  $url_generator
    ->expects($this
    ->once())
    ->method('generateFromRoute')
    ->with($route_name, [], [])
    ->willReturn($generated_url);
  $url_generator_trait_object = $this
    ->getMockForTrait('Drupal\\Core\\Routing\\UrlGeneratorTrait');
  $url_generator_trait_object
    ->setUrlGenerator($url_generator);
  $url_generator_method = new \ReflectionMethod($url_generator_trait_object, 'url');
  $url_generator_method
    ->setAccessible(TRUE);
  $result = $url_generator_method
    ->invoke($url_generator_trait_object, $route_name);
  $this
    ->assertSame($generated_url, $result);
}