You are here

public function PermissionEventTest::permissionEventDataProvider in Organic groups 8

Provides expected results for the testPermissionEventIntegration test.

Return value

array An array of test properties. Each property is an indexed array with the following items:

  • An array of group content bundle IDs that are associated with the test group. Used to check if group content permissions are correctly provided.
  • An array of permission names that are expected to be returned. Used to check that the correct permissions are returned.
  • An array of full permissions that are expected to be returned. This is a subset of the permissions. It is not necessary to test the full permission data for each entry, testing the data for only 1 or 2 permissions is sufficient.

File

tests/src/Kernel/PermissionEventTest.php, line 130

Class

PermissionEventTest
Tests the implementations of the PermissionEvent in 'og' and 'og_ui'.

Namespace

Drupal\Tests\og\Kernel

Code

public function permissionEventDataProvider() {

  // Test permissions that should be available for both test groups.
  $default_permissions = [
    'add user',
    OgAccess::ADMINISTER_GROUP_PERMISSION,
    OgAccess::DELETE_GROUP_PERMISSION,
    OgAccess::UPDATE_GROUP_PERMISSION,
    'approve and deny subscription',
    'manage members',
    'administer permissions',
    'subscribe without approval',
    'subscribe',
  ];

  // Test permissions that should only be available for the test group that
  // has group content.
  $group_content_permissions = [
    'create test_group_content content',
    'delete any test_group_content content',
    'delete own test_group_content content',
    'edit any test_group_content content',
    'edit own test_group_content content',
  ];

  // A full permission that should be available in both test groups. This is
  // used to test that all properties are correctly applied.
  $group_level_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 full permission that should only be available for the test group that
  // has group content.
  $group_content_operation_permission = new GroupContentOperationPermission([
    'name' => 'create test_group_content content',
    'title' => $this
      ->t('%bundle: Create new content', [
      '%bundle' => 'Test Group Content',
    ]),
    'entity type' => 'node',
    'bundle' => 'test_group_content',
    'operation' => 'create',
  ]);
  return [
    // Test retrieving permissions for a group that has no group content types
    // associated with it.
    [
      [],
      // It should only return the default permissions.
      $default_permissions,
      // The list of permissions should only contain the group level
      // permission ('administer group'). and the group content permission
      // ('create test_group_content node').
      [
        $group_level_permission,
      ],
    ],
    // Test retrieving permissions for a group that has a group content type
    // associated with it.
    [
      [
        'node' => [
          'test_group_content',
        ],
      ],
      // It should return the default permissions as well as the permissions
      // to create, delete and update group content.
      array_merge($default_permissions, $group_content_permissions),
      // The list of permissions should contain both the group level
      // permission ('administer group') and the group content permission
      // ('create test_group_content node').
      [
        $group_level_permission,
        $group_content_operation_permission,
      ],
    ],
  ];
}