function UrlTest::testCreateFromRequest

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/UrlTest.php \Drupal\Tests\Core\UrlTest::testCreateFromRequest()
  2. 10 core/tests/Drupal/Tests/Core/UrlTest.php \Drupal\Tests\Core\UrlTest::testCreateFromRequest()
  3. 11.x 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 260

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);
}

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