Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / user / src / Tests / Views / HandlerFieldRoleTest.php
1 <?php
2
3 namespace Drupal\user\Tests\Views;
4
5 use Drupal\Component\Utility\Html;
6 use Drupal\user\Entity\User;
7
8 /**
9  * Tests the handler of the user: role field.
10  *
11  * @group user
12  * @see views_handler_field_user_name
13  */
14 class HandlerFieldRoleTest extends UserTestBase {
15
16   /**
17    * Views used by this test.
18    *
19    * @var array
20    */
21   public static $testViews = ['test_views_handler_field_role'];
22
23   public function testRole() {
24     // Create a couple of roles for the view.
25     $rolename_a = 'a' . $this->randomMachineName(8);
26     $this->drupalCreateRole(['access content'], $rolename_a, '<em>' . $rolename_a . '</em>', 9);
27
28     $rolename_b = 'b' . $this->randomMachineName(8);
29     $this->drupalCreateRole(['access content'], $rolename_b, $rolename_b, 8);
30
31     $rolename_not_assigned = $this->randomMachineName(8);
32     $this->drupalCreateRole(['access content'], $rolename_not_assigned, $rolename_not_assigned);
33
34     // Add roles to user 1.
35     $user = User::load(1);
36     $user->addRole($rolename_a);
37     $user->addRole($rolename_b);
38     $user->save();
39
40     $this->drupalLogin($this->createUser(['access user profiles']));
41     $this->drupalGet('/test-views-handler-field-role');
42     $this->assertText($rolename_b . Html::escape('<em>' . $rolename_a . '</em>'), 'View test_views_handler_field_role renders role assigned to user in the correct order and markup in role names is escaped.');
43     $this->assertNoText($rolename_not_assigned, 'View test_views_handler_field_role does not render a role not assigned to a user.');
44   }
45
46 }