You are here

public function GroupContentAccessControlHandlerTest::entityCreateAccessProvider in Group 8

Data provider for entityCreateAccessProvider.

Return value

array A list of entityCreateAccessProvider method arguments.

File

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

Class

GroupContentAccessControlHandlerTest
Tests the default GroupContentEnabler access handler.

Namespace

Drupal\Tests\group\Unit

Code

public function entityCreateAccessProvider() {
  $cases = [];
  foreach ($this
    ->getAccessControlHandlerScenarios() as $scenario) {
    foreach ([
      TRUE,
      FALSE,
    ] as $entity_access) {
      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 && $entity_access) {
          $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['definition']['entity_access'] = $entity_access;
        $case['permission'] = $permission;
        $cases[] = $case;
      }
    }
  }
  return $cases;
}