You are here

public function HandlerFilterRolesTest::testMissingRole in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/user/tests/src/Kernel/Views/HandlerFilterRolesTest.php \Drupal\Tests\user\Kernel\Views\HandlerFilterRolesTest::testMissingRole()
  2. 9 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\Views

Code

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();
}