function HandlerFilterRolesTest::testMissingRole
Same name in other branches
- 8.9.x core/modules/user/tests/src/Kernel/Views/HandlerFilterRolesTest.php \Drupal\Tests\user\Kernel\Views\HandlerFilterRolesTest::testMissingRole()
- 10 core/modules/user/tests/src/Kernel/Views/HandlerFilterRolesTest.php \Drupal\Tests\user\Kernel\Views\HandlerFilterRolesTest::testMissingRole()
- 11.x core/modules/user/tests/src/Kernel/Views/HandlerFilterRolesTest.php \Drupal\Tests\user\Kernel\Views\HandlerFilterRolesTest::testMissingRole()
Tests that a warning is triggered if the filter references a missing role.
File
-
core/
modules/ user/ tests/ src/ Kernel/ Views/ HandlerFilterRolesTest.php, line 101
Class
- HandlerFilterRolesTest
- Tests the roles filter handler.
Namespace
Drupal\Tests\user\Kernel\ViewsCode
public function testMissingRole() {
$role = Role::create([
'id' => 'test_user_role',
'label' => 'Test user role',
]);
$role->save();
/** @var \Drupal\views\Entity\View $view */
$view = View::load('test_user_name');
$display =& $view->getDisplay('default');
$display['display_options']['filters']['roles_target_id'] = [
'id' => 'roles_target_id',
'table' => 'user__roles',
'field' => 'roles_target_id',
'value' => [
'test_user_role' => 'test_user_role',
],
'plugin_id' => 'user_roles',
];
// Ensure no warning is triggered before the role is deleted.
$view->calculateDependencies();
$role->delete();
$this->expectWarning();
$this->expectWarningMessage('The test_user_role role does not exist. You should review and fix the configuration of the test_user_name view.');
$view->calculateDependencies();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.