HandlerFieldRoleTest.php in Drupal 9
File
core/modules/user/tests/src/Functional/Views/HandlerFieldRoleTest.php
View source
<?php
namespace Drupal\Tests\user\Functional\Views;
use Drupal\Component\Utility\Html;
use Drupal\user\Entity\User;
class HandlerFieldRoleTest extends UserTestBase {
public static $testViews = [
'test_views_handler_field_role',
];
protected $defaultTheme = 'stark';
public function testRole() {
$rolename_a = 'a' . $this
->randomMachineName(8);
$this
->drupalCreateRole([
'access content',
], $rolename_a, '<em>' . $rolename_a . '</em>', 9);
$rolename_b = 'b' . $this
->randomMachineName(8);
$this
->drupalCreateRole([
'access content',
], $rolename_b, $rolename_b, 8);
$rolename_not_assigned = $this
->randomMachineName(8);
$this
->drupalCreateRole([
'access content',
], $rolename_not_assigned, $rolename_not_assigned);
$user = User::load(1);
$user
->addRole($rolename_a);
$user
->addRole($rolename_b);
$user
->save();
$this
->drupalLogin($this
->createUser([
'access user profiles',
]));
$this
->drupalGet('/test-views-handler-field-role');
$this
->assertSession()
->responseContains($rolename_b . Html::escape('<em>' . $rolename_a . '</em>'));
$this
->assertSession()
->pageTextNotContains($rolename_not_assigned);
}
}