You are here

public function PermissionEventTest::invalidPermissionsProvider in Organic groups 8

Data provider to test handling of invalid 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 767

Class

PermissionEventTest
Tests permission events.

Namespace

Drupal\Tests\og\Unit

Code

public function invalidPermissionsProvider() {
  $permissions = [
    // A permission without a machine name.
    [
      [
        new GroupPermission([
          'title' => $this
            ->t('This permission does not have a title.'),
        ]),
      ],
    ],
    // A permission without a human readable title.
    [
      [
        new GroupPermission([
          'name' => 'invalid permission',
        ]),
      ],
    ],
    // A group content operation permission without a machine name.
    [
      [
        new GroupContentOperationPermission([
          'title' => $this
            ->t('This is an invalid permission.'),
          'entity type' => 'node',
          'bundle' => 'article',
          'operation' => 'create',
        ]),
      ],
    ],
    // A group content operation permission without a human readable title.
    [
      [
        new GroupContentOperationPermission([
          'name' => 'invalid permission',
          'entity type' => 'node',
          'bundle' => 'article',
          'operation' => 'create',
        ]),
      ],
    ],
    // A group content operation permission without an entity type ID.
    [
      [
        new GroupContentOperationPermission([
          'name' => 'invalid permission',
          'title' => $this
            ->t('This is an invalid permission.'),
          'bundle' => 'article',
          'operation' => 'create',
        ]),
      ],
    ],
    // A group content operation permission without a bundle.
    [
      [
        new GroupContentOperationPermission([
          'name' => 'invalid permission',
          'title' => $this
            ->t('This is an invalid permission.'),
          'entity type' => 'node',
          'operation' => 'create',
        ]),
      ],
    ],
    // A group content operation permission without an operation.
    [
      [
        new GroupContentOperationPermission([
          'name' => 'invalid permission',
          'title' => $this
            ->t('This is an invalid permission.'),
          'entity type' => 'node',
          'bundle' => 'article',
        ]),
      ],
    ],
    // A mix of correct and incorrect 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,
          ],
        ]),
        '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,
          ],
        ]),
        'permission' => new GroupPermission([
          'name' => 'invalid permission',
        ]),
      ],
    ],
  ];

  // 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;
}