function UrlTest::testUrlFromRequest
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/UrlTest.php \Drupal\Tests\Core\UrlTest::testUrlFromRequest()
- 10 core/tests/Drupal/Tests/Core/UrlTest.php \Drupal\Tests\Core\UrlTest::testUrlFromRequest()
- 11.x core/tests/Drupal/Tests/Core/UrlTest.php \Drupal\Tests\Core\UrlTest::testUrlFromRequest()
Tests creating a Url from a request.
File
-
core/
tests/ Drupal/ Tests/ Core/ UrlTest.php, line 123
Class
- UrlTest
- @coversDefaultClass \Drupal\Core\Url @group UrlTest
Namespace
Drupal\Tests\CoreCode
public function testUrlFromRequest() {
$this->router
->expects($this->at(0))
->method('matchRequest')
->with($this->getRequestConstraint('/node'))
->willReturn([
RouteObjectInterface::ROUTE_NAME => 'view.frontpage.page_1',
'_raw_variables' => new ParameterBag(),
]);
$this->router
->expects($this->at(1))
->method('matchRequest')
->with($this->getRequestConstraint('/node/1'))
->willReturn([
RouteObjectInterface::ROUTE_NAME => 'node_view',
'_raw_variables' => new ParameterBag([
'node' => '1',
]),
]);
$this->router
->expects($this->at(2))
->method('matchRequest')
->with($this->getRequestConstraint('/node/2/edit'))
->willReturn([
RouteObjectInterface::ROUTE_NAME => 'node_edit',
'_raw_variables' => new ParameterBag([
'node' => '2',
]),
]);
$urls = [];
foreach ($this->map as $index => $values) {
$path = array_pop($values);
$url = Url::createFromRequest(Request::create("{$path}"));
$expected = Url::fromRoute($values[0], $values[1], $values[2]);
$this->assertEquals($expected, $url);
$urls[$index] = $url;
}
return $urls;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.