You are here

public function GroupContentAccessControlHandlerTest::relationCreateAccessProvider in Group 8

Data provider for testRelationCreateAccess.

Return value

array A list of testRelationCreateAccess method arguments.

File

tests/src/Unit/GroupContentAccessControlHandlerTest.php, line 264

Class

GroupContentAccessControlHandlerTest
Tests the default GroupContentEnabler access handler.

Namespace

Drupal\Tests\group\Unit

Code

public function relationCreateAccessProvider() {
  $cases = [];
  foreach ($this
    ->getAccessControlHandlerScenarios() as $scenario) {
    foreach ([
      'some permission name',
      FALSE,
    ] as $permission) {
      $case = $scenario;

      // Default is neutral result if no permissions are defined or entity
      // access control is turned off for the plugin.
      $case['expected'] = function () {
        return AccessResult::neutral();
      };
      $permission_exists = $case['definition']['admin_permission'] || $permission;
      if ($permission_exists) {
        $has_admin = $case['definition']['admin_permission'] && $case['has_admin_permission'];
        $has_regular = $permission && $case['has_permission'];
        $case['expected'] = function () use ($has_admin, $has_regular) {
          return AccessResult::allowedIf($has_admin || $has_regular)
            ->addCacheContexts([
            'user.group_permissions',
          ]);
        };
      }
      $case['permission'] = $permission;
      $cases[] = $case;
    }
  }
  return $cases;
}