class PathValidatorTest
Same name in this branch
- 9 core/tests/Drupal/Tests/Core/Path/PathValidatorTest.php \Drupal\Tests\Core\Path\PathValidatorTest
Same name and namespace in other branches
- 11.x core/tests/Drupal/KernelTests/Core/Path/PathValidatorTest.php \Drupal\KernelTests\Core\Path\PathValidatorTest
- 11.x core/tests/Drupal/Tests/Core/Path/PathValidatorTest.php \Drupal\Tests\Core\Path\PathValidatorTest
- 10 core/tests/Drupal/KernelTests/Core/Path/PathValidatorTest.php \Drupal\KernelTests\Core\Path\PathValidatorTest
- 10 core/tests/Drupal/Tests/Core/Path/PathValidatorTest.php \Drupal\Tests\Core\Path\PathValidatorTest
- 8.9.x core/tests/Drupal/KernelTests/Core/Path/PathValidatorTest.php \Drupal\KernelTests\Core\Path\PathValidatorTest
- 8.9.x core/tests/Drupal/Tests/Core/Path/PathValidatorTest.php \Drupal\Tests\Core\Path\PathValidatorTest
Tests the path validator.
@group Path
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\KernelTests\Core\Path\PathValidatorTest uses \Drupal\Tests\user\Traits\UserCreationTrait extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of PathValidatorTest
See also
\Drupal\Core\Path\PathValidator
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Path/ PathValidatorTest.php, line 18
Namespace
Drupal\KernelTests\Core\PathView source
class PathValidatorTest extends KernelTestBase {
use UserCreationTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'path',
'entity_test',
'system',
'user',
];
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->setUpCurrentUser();
$this->installEntitySchema('entity_test');
}
public function testGetUrlIfValidWithoutAccessCheck() {
$requestContext = \Drupal::service('router.request_context');
$pathValidator = \Drupal::service('path.validator');
$entity = EntityTest::create([
'name' => 'test',
]);
$entity->save();
$methods = [
'POST',
'GET',
'PUT',
'PATCH',
'DELETE',
// NULL is used in CLI context which results in a request method of an
// empty string.
'',
// If no request was even pushed onto the request stack, and hence.
FALSE,
];
foreach ($methods as $method) {
if ($method === FALSE) {
$request_stack = $this->container
->get('request_stack');
while ($request_stack->getCurrentRequest()) {
$request_stack->pop();
}
$this->container
->set('router.request_context', new RequestContext());
}
$requestContext->setMethod($method);
/** @var \Drupal\Core\Url $url */
$url = $pathValidator->getUrlIfValidWithoutAccessCheck($entity->toUrl()
->toString(TRUE)
->getGeneratedUrl());
$this->assertEquals($method, $requestContext->getMethod());
$this->assertInstanceOf(Url::class, $url);
$this->assertSame([
'entity_test' => $entity->id(),
], $url->getRouteParameters());
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.