You are here

public function UncacheableEntityAccessControlHandlerTest::accessProvider in Entity API 8

Data provider for testAccess().

Return value

array A list of testAccess method arguments.

File

tests/src/Unit/UncacheableEntityAccessControlHandlerTest.php, line 79

Class

UncacheableEntityAccessControlHandlerTest
@coversDefaultClass \Drupal\entity\UncacheableEntityAccessControlHandler @group entity

Namespace

Drupal\Tests\entity\Unit

Code

public function accessProvider() {
  $entity_type = $this
    ->prophesize(ContentEntityTypeInterface::class);
  $entity_type
    ->id()
    ->willReturn('green_entity');
  $entity_type
    ->getAdminPermission()
    ->willReturn('administer green_entity');
  $entity_type
    ->hasHandlerClass('permission_provider')
    ->willReturn(TRUE);
  $entity_type
    ->getHandlerClass('permission_provider')
    ->willReturn(UncacheableEntityPermissionProvider::class);
  $entity = $this
    ->buildMockEntity($entity_type
    ->reveal(), 6);
  $data = [];

  // Admin permission.
  $admin_user = $this
    ->buildMockUser(5, 'administer green_entity');
  $data[] = [
    $entity
      ->reveal(),
    'view',
    $admin_user
      ->reveal(),
    TRUE,
  ];
  $data[] = [
    $entity
      ->reveal(),
    'update',
    $admin_user
      ->reveal(),
    TRUE,
  ];
  $data[] = [
    $entity
      ->reveal(),
    'duplicate',
    $admin_user
      ->reveal(),
    TRUE,
  ];
  $data[] = [
    $entity
      ->reveal(),
    'delete',
    $admin_user
      ->reveal(),
    TRUE,
  ];

  // View, update, duplicate, delete permissions, entity without an owner.
  $second_entity = $this
    ->buildMockEntity($entity_type
    ->reveal());
  foreach ([
    'view',
    'update',
    'duplicate',
    'delete',
  ] as $operation) {
    $first_user = $this
      ->buildMockUser(6, $operation . ' green_entity');
    $second_user = $this
      ->buildMockUser(7, 'access content');
    $data[] = [
      $second_entity
        ->reveal(),
      $operation,
      $first_user
        ->reveal(),
      TRUE,
    ];
    $data[] = [
      $second_entity
        ->reveal(),
      $operation,
      $second_user
        ->reveal(),
      FALSE,
    ];
  }

  // View, update, duplicate, delete permissions.
  foreach ([
    'view',
    'update',
    'duplicate',
    'delete',
  ] as $operation) {

    // Owner, non-owner, user with "any" permission.
    $first_user = $this
      ->buildMockUser(6, $operation . ' own green_entity');
    $second_user = $this
      ->buildMockUser(7, $operation . ' own green_entity');
    $third_user = $this
      ->buildMockUser(8, $operation . ' any green_entity');
    $data[] = [
      $entity
        ->reveal(),
      $operation,
      $first_user
        ->reveal(),
      TRUE,
    ];
    $data[] = [
      $entity
        ->reveal(),
      $operation,
      $second_user
        ->reveal(),
      FALSE,
    ];
    $data[] = [
      $entity
        ->reveal(),
      $operation,
      $third_user
        ->reveal(),
      TRUE,
    ];
  }

  // Per bundle and unpublished view permissions.
  $first_user = $this
    ->buildMockUser(11, 'view any first green_entity');
  $second_user = $this
    ->buildMockUser(12, 'view own first green_entity');
  $third_user = $this
    ->buildMockUser(13, 'view own unpublished green_entity');
  $first_entity = $this
    ->buildMockEntity($entity_type
    ->reveal(), 9999, 'first');
  $second_entity = $this
    ->buildMockEntity($entity_type
    ->reveal(), 12, 'first');
  $third_entity = $this
    ->buildMockEntity($entity_type
    ->reveal(), 9999, 'second');
  $fourth_entity = $this
    ->buildMockEntity($entity_type
    ->reveal(), 10, 'second');
  $fifth_entity = $this
    ->buildMockEntity($entity_type
    ->reveal(), 13, 'first', FALSE);

  // The first user can view the two entities of bundle "first".
  $data[] = [
    $first_entity
      ->reveal(),
    'view',
    $first_user
      ->reveal(),
    TRUE,
  ];
  $data[] = [
    $second_entity
      ->reveal(),
    'view',
    $first_user
      ->reveal(),
    TRUE,
  ];
  $data[] = [
    $third_entity
      ->reveal(),
    'view',
    $first_user
      ->reveal(),
    FALSE,
  ];
  $data[] = [
    $fourth_entity
      ->reveal(),
    'view',
    $first_user
      ->reveal(),
    FALSE,
  ];
  $data[] = [
    $fifth_entity
      ->reveal(),
    'view',
    $first_user
      ->reveal(),
    FALSE,
  ];

  // The second user can view their own entity of bundle "first".
  $data[] = [
    $first_entity
      ->reveal(),
    'view',
    $second_user
      ->reveal(),
    FALSE,
  ];
  $data[] = [
    $second_entity
      ->reveal(),
    'view',
    $second_user
      ->reveal(),
    TRUE,
  ];
  $data[] = [
    $third_entity
      ->reveal(),
    'view',
    $second_user
      ->reveal(),
    FALSE,
  ];
  $data[] = [
    $fourth_entity
      ->reveal(),
    'view',
    $second_user
      ->reveal(),
    FALSE,
  ];
  $data[] = [
    $fourth_entity
      ->reveal(),
    'view',
    $second_user
      ->reveal(),
    FALSE,
  ];
  $data[] = [
    $fifth_entity
      ->reveal(),
    'view',
    $second_user
      ->reveal(),
    FALSE,
  ];

  // The third user can only view their own unpublished entity.
  $data[] = [
    $first_entity
      ->reveal(),
    'view',
    $third_user
      ->reveal(),
    FALSE,
  ];
  $data[] = [
    $second_entity
      ->reveal(),
    'view',
    $third_user
      ->reveal(),
    FALSE,
  ];
  $data[] = [
    $third_entity
      ->reveal(),
    'view',
    $third_user
      ->reveal(),
    FALSE,
  ];
  $data[] = [
    $fourth_entity
      ->reveal(),
    'view',
    $third_user
      ->reveal(),
    FALSE,
  ];
  $data[] = [
    $fourth_entity
      ->reveal(),
    'view',
    $third_user
      ->reveal(),
    FALSE,
  ];
  $data[] = [
    $fifth_entity
      ->reveal(),
    'view',
    $third_user
      ->reveal(),
    TRUE,
  ];
  return $data;
}