You are here

protected function RngTestTrait::createUserRoleRules in RNG - Events and Registrations 8

Same name and namespace in other branches
  1. 8.2 src/Tests/RngTestTrait.php \Drupal\rng\Tests\RngTestTrait::createUserRoleRules()
  2. 3.x src/Tests/RngTestTrait.php \Drupal\rng\Tests\RngTestTrait::createUserRoleRules()

Create rules for an event type.

Parameters

array $roles: An array of role ID to add access.

array $operations: An array of operations. Value is boolean whether to grant, key can be any of 'create', 'view', 'update', 'delete'.

9 calls to RngTestTrait::createUserRoleRules()
RngRegistrationAccessTest::testRegisterSelf in tests/src/Kernel/RngRegistrationAccessTest.php
Test register self
RngRegistrationAccessTest::testRegisterSelfNoDuplicates in tests/src/Kernel/RngRegistrationAccessTest.php
Test register self no duplicates.
RngRegistrationAccessTest::testRegisterSelfNoPermission in tests/src/Kernel/RngRegistrationAccessTest.php
Test register self no permission
RngRegistrationAccessTest::testRegisterSelfRuleNoRoles in tests/src/Kernel/RngRegistrationAccessTest.php
Test register self rule with no roles.
RngRegistrationAccessTest::testRegisterSelfRuleRoleAlternative in tests/src/Kernel/RngRegistrationAccessTest.php
Test register self rule a role the user does not have.

... See full list

File

src/Tests/RngTestTrait.php, line 108

Class

RngTestTrait

Namespace

Drupal\rng\Tests

Code

protected function createUserRoleRules($roles = [], $operations = []) {
  $rule = EventTypeRule::create([
    'trigger' => 'rng_event.register',
    'entity_type' => 'entity_test',
    'bundle' => 'entity_test',
    'machine_name' => 'user_role',
  ]);
  $rule
    ->setCondition('role', [
    'id' => 'rng_user_role',
    'roles' => $roles,
  ]);
  $rule
    ->setAction('registration_operations', [
    'id' => 'registration_operations',
    'configuration' => [
      'operations' => $operations,
    ],
  ]);
  $rule
    ->save();
}