class UrlIntegrationTest
Same name and namespace in other branches
- 11.x core/tests/Drupal/KernelTests/Core/Routing/UrlIntegrationTest.php \Drupal\KernelTests\Core\Routing\UrlIntegrationTest
- 10 core/tests/Drupal/KernelTests/Core/Routing/UrlIntegrationTest.php \Drupal\KernelTests\Core\Routing\UrlIntegrationTest
- 8.9.x core/tests/Drupal/KernelTests/Core/Routing/UrlIntegrationTest.php \Drupal\KernelTests\Core\Routing\UrlIntegrationTest
Tests the URL object integration into the access system.
@group Url
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\Routing\UrlIntegrationTest extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of UrlIntegrationTest
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Routing/ UrlIntegrationTest.php, line 15
Namespace
Drupal\KernelTests\Core\RoutingView source
class UrlIntegrationTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'user',
'router_test',
'system',
];
/**
* Ensures that the access() method on \Drupal\Core\Url objects works.
*/
public function testAccess() {
/** @var \Drupal\user\RoleInterface $role_with_access */
$role_with_access = Role::create([
'id' => 'role_with_access',
'label' => 'With access',
]);
$role_with_access->grantPermission('administer users');
$role_with_access->save();
/** @var \Drupal\user\RoleInterface $role_without_access */
$role_without_access = Role::create([
'id' => 'role_without_access',
'label' => 'Without access',
]);
$role_without_access->save();
$user_with_access = User::create([
'roles' => [
'role_with_access',
],
]);
$user_without_access = User::create([
'roles' => [
'role_without_access',
],
]);
$url_always_access = new Url('router_test.1');
$this->assertTrue($url_always_access->access($user_with_access));
$this->assertTrue($url_always_access->access($user_without_access));
$url_none_access = new Url('router_test.15');
$this->assertFalse($url_none_access->access($user_with_access));
$this->assertFalse($url_none_access->access($user_without_access));
$url_access = new Url('router_test.16');
$this->assertTrue($url_access->access($user_with_access));
$this->assertFalse($url_access->access($user_without_access));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.