You are here

public function UrlTest::testCreateFromRequest in Drupal 8

Tests the createFromRequest method.

@covers ::createFromRequest

File

core/tests/Drupal/Tests/Core/UrlTest.php, line 260
Contains \Drupal\Tests\Core\UrlTest.

Class

UrlTest
@coversDefaultClass \Drupal\Core\Url @group UrlTest

Namespace

Drupal\Tests\Core

Code

public function testCreateFromRequest() {
  $attributes = [
    '_raw_variables' => new ParameterBag([
      'color' => 'chartreuse',
    ]),
    RouteObjectInterface::ROUTE_NAME => 'the_route_name',
  ];
  $request = new Request([], [], $attributes);
  $this->router
    ->expects($this
    ->once())
    ->method('matchRequest')
    ->with($request)
    ->will($this
    ->returnValue($attributes));
  $url = Url::createFromRequest($request);
  $expected = new Url('the_route_name', [
    'color' => 'chartreuse',
  ]);
  $this
    ->assertEquals($expected, $url);
}