Upgraded drupal core with security updates
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / Routing / UrlIntegrationTest.php
1 <?php
2
3 namespace Drupal\KernelTests\Core\Routing;
4
5 use Drupal\Core\Url;
6 use Drupal\KernelTests\KernelTestBase;
7 use Drupal\user\Entity\Role;
8 use Drupal\user\Entity\User;
9
10 /**
11  * Tests the URL object integration into the access system.
12  *
13  * @group Url
14  */
15 class UrlIntegrationTest extends KernelTestBase {
16
17   /**
18    * Modules to enable.
19    *
20    * @var array
21    */
22   public static $modules = ['user', 'router_test', 'system'];
23
24   /**
25    * Ensures that the access() method on \Drupal\Core\Url objects works.
26    */
27   public function testAccess() {
28     /** @var \Drupal\user\RoleInterface $role_with_access */
29     $role_with_access = Role::create(['id' => 'role_with_access']);
30     $role_with_access->grantPermission('administer users');
31     $role_with_access->save();
32
33     /** @var \Drupal\user\RoleInterface $role_without_access */
34     $role_without_access = Role::create(['id' => 'role_without_access']);
35     $role_without_access->save();
36
37     $user_with_access = User::create(['roles' => ['role_with_access']]);
38     $user_without_access = User::create(['roles' => ['role_without_access']]);
39
40     $url_always_access = new Url('router_test.1');
41     $this->assertTrue($url_always_access->access($user_with_access));
42     $this->assertTrue($url_always_access->access($user_without_access));
43
44     $url_none_access = new Url('router_test.15');
45     $this->assertFalse($url_none_access->access($user_with_access));
46     $this->assertFalse($url_none_access->access($user_without_access));
47
48     $url_access = new Url('router_test.16');
49     $this->assertTrue($url_access->access($user_with_access));
50     $this->assertFalse($url_access->access($user_without_access));
51   }
52
53 }