function HandlerFilterRolesTest::testMissingRole

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

Class

HandlerFilterRolesTest
Tests the roles filter handler.

Namespace

Drupal\Tests\user\Kernel\Views

Code

public function testMissingRole() {
  $role = Role::create([
    'id' => '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->expectException(Warning::class);
  $this->expectExceptionMessage('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.