function UrlTest::testCreateFromRequest

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/UrlTest.php \Drupal\Tests\Core\UrlTest::testCreateFromRequest()
  2. 8.9.x core/tests/Drupal/Tests/Core/UrlTest.php \Drupal\Tests\Core\UrlTest::testCreateFromRequest()
  3. 10 core/tests/Drupal/Tests/Core/UrlTest.php \Drupal\Tests\Core\UrlTest::testCreateFromRequest()

Tests the createFromRequest method.

@covers ::createFromRequest

File

core/tests/Drupal/Tests/Core/UrlTest.php, line 234

Class

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

Namespace

Drupal\Tests\Core

Code

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.