You are here

public function PermissionEventTest::permissionsProvider in Organic groups 8

Data provider to test permissions.

Return value

array An array of test data arrays, each test data array containing:

  • An array of test permissions, keyed by permission ID.
  • The entity type ID of the group type to which these permissions apply.
  • The bundle ID of the group type to which these permissions apply.
  • An array of group content bundle IDs to which these permissions apply, keyed by group content entity type ID.

File

tests/src/Unit/PermissionEventTest.php, line 667

Class

PermissionEventTest
Tests permission events.

Namespace

Drupal\Tests\og\Unit

Code

public function permissionsProvider() {
  $permissions = [
    // A simple permission with only the required option.
    [
      [
        'appreciate nature' => new GroupPermission([
          'name' => 'appreciate nature',
          'title' => $this
            ->t('Allows the member to go outdoors and appreciate the landscape.'),
        ]),
      ],
    ],
    // A single permission with restricted access and a default role.
    [
      [
        OgAccess::ADMINISTER_GROUP_PERMISSION => new GroupPermission([
          'name' => OgAccess::ADMINISTER_GROUP_PERMISSION,
          'title' => $this
            ->t('Administer group'),
          'description' => $this
            ->t('Manage group members and content in the group.'),
          'default roles' => [
            OgRoleInterface::ADMINISTRATOR,
          ],
          'restrict access' => TRUE,
        ]),
      ],
    ],
    // A permission restricted to a specific role, and having a default role.
    [
      [
        'unsubscribe' => new GroupPermission([
          'name' => 'unsubscribe',
          'title' => $this
            ->t('Unsubscribe from group'),
          'description' => $this
            ->t('Allow members to unsubscribe themselves from a group, removing their membership.'),
          'roles' => [
            OgRoleInterface::AUTHENTICATED,
          ],
          'default roles' => [
            OgRoleInterface::AUTHENTICATED,
          ],
        ]),
      ],
    ],
    // Simulate a subscriber providing multiple permissions.
    [
      [
        'subscribe' => new GroupPermission([
          'name' => 'subscribe',
          'title' => $this
            ->t('Subscribe to group'),
          'description' => $this
            ->t('Allow non-members to request membership to a group (approval required).'),
          'roles' => [
            OgRoleInterface::ANONYMOUS,
          ],
          'default roles' => [
            OgRoleInterface::ANONYMOUS,
          ],
        ]),
        'subscribe without approval' => new GroupPermission([
          'name' => 'subscribe without approval',
          'title' => $this
            ->t('Subscribe to group (no approval required)'),
          'description' => $this
            ->t('Allow non-members to join a group without an approval from group administrators.'),
          'roles' => [
            OgRoleInterface::ANONYMOUS,
          ],
        ]),
        'unsubscribe' => new GroupPermission([
          'name' => 'unsubscribe',
          'title' => $this
            ->t('Unsubscribe from group'),
          'description' => $this
            ->t('Allow members to unsubscribe themselves from a group, removing their membership.'),
          'roles' => [
            OgRoleInterface::AUTHENTICATED,
          ],
          'default roles' => [
            OgRoleInterface::AUTHENTICATED,
          ],
        ]),
      ],
    ],
    // A mix of GroupPermissions and GroupContentOperationPermissions.
    [
      [
        'appreciate nature' => new GroupPermission([
          'name' => 'appreciate nature',
          'title' => $this
            ->t('Allows the member to go outdoors and appreciate the landscape.'),
        ]),
        'create article content' => new GroupContentOperationPermission([
          'name' => 'create article content',
          'title' => $this
            ->t('Article: Create new content'),
          'entity type' => 'node',
          'bundle' => 'article',
          'operation' => 'create',
        ]),
      ],
    ],
  ];

  // Supply a random entity type ID, bundle ID and array of group content
  // bundle IDs for each data set.
  foreach ($permissions as &$item) {
    $item[] = $this
      ->randomMachineName();
    $item[] = $this
      ->randomMachineName();
    $item[] = [
      $this
        ->randomMachineName() => [
        $this
          ->randomMachineName(),
      ],
    ];
  }
  return $permissions;
}