class HandlerFieldRoleTest
Same name and namespace in other branches
- 11.x core/modules/user/tests/src/Functional/Views/HandlerFieldRoleTest.php \Drupal\Tests\user\Functional\Views\HandlerFieldRoleTest
- 10 core/modules/user/tests/src/Functional/Views/HandlerFieldRoleTest.php \Drupal\Tests\user\Functional\Views\HandlerFieldRoleTest
- 8.9.x core/modules/user/tests/src/Functional/Views/HandlerFieldRoleTest.php \Drupal\Tests\user\Functional\Views\HandlerFieldRoleTest
Tests the handler of the user: role field.
@group user
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait extends \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\user\Functional\Views\UserTestBase extends \Drupal\Tests\views\Functional\ViewTestBase
- class \Drupal\Tests\user\Functional\Views\HandlerFieldRoleTest extends \Drupal\Tests\user\Functional\Views\UserTestBase
- class \Drupal\Tests\user\Functional\Views\UserTestBase extends \Drupal\Tests\views\Functional\ViewTestBase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of HandlerFieldRoleTest
See also
views_handler_field_user_name
File
-
core/
modules/ user/ tests/ src/ Functional/ Views/ HandlerFieldRoleTest.php, line 14
Namespace
Drupal\Tests\user\Functional\ViewsView source
class HandlerFieldRoleTest extends UserTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = [
'test_views_handler_field_role',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
public function testRole() {
// Create a couple of roles for the view.
$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);
// Add roles to user 1.
$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');
// Verify that the view test_views_handler_field_role renders role assigned
// to user in the correct order and markup in role names is escaped.
$this->assertSession()
->responseContains($rolename_b . Html::escape('<em>' . $rolename_a . '</em>'));
// Verify that the view test_views_handler_field_role does not render a role
// not assigned to a user.
$this->assertSession()
->pageTextNotContains($rolename_not_assigned);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.