You are here

public function DrupalTest::testUrl in Drupal 8

Tests the url() method.

@covers ::url

@group legacy @expectedDeprecation Drupal::url() is deprecated as of Drupal 8.0.x, will be removed before Drupal 9.0.0. Instead create a \Drupal\Core\Url object directly, for example using Url::fromRoute()

See also

\Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute()

File

core/tests/Drupal/Tests/Core/DrupalTest.php, line 368

Class

DrupalTest
Tests the Drupal class.

Namespace

Drupal\Tests\Core

Code

public function testUrl() {
  $route_parameters = [
    'test_parameter' => 'test',
  ];
  $options = [
    'test_option' => 'test',
  ];
  $generator = $this
    ->createMock('Drupal\\Core\\Routing\\UrlGeneratorInterface');
  $generator
    ->expects($this
    ->once())
    ->method('generateFromRoute')
    ->with('test_route', $route_parameters, $options)
    ->will($this
    ->returnValue('path_string'));
  $this
    ->setMockContainerService('url_generator', $generator);
  $this
    ->assertInternalType('string', \Drupal::url('test_route', $route_parameters, $options));
}