You are here

public function BundleEntityAccessControlHandlerTest::accessProvider in Entity API 8

Data provider for testAccess().

Return value

array A list of testAccess method arguments.

File

tests/src/Unit/BundleEntityAccessControlHandlerTest.php, line 59

Class

BundleEntityAccessControlHandlerTest
@coversDefaultClass \Drupal\entity\BundleEntityAccessControlHandler @group entity

Namespace

Drupal\Tests\entity\Unit

Code

public function accessProvider() {
  $entity_type = $this
    ->prophesize(ContentEntityTypeInterface::class);
  $entity_type
    ->id()
    ->willReturn('green_entity_bundle');
  $entity_type
    ->getBundleOf()
    ->willReturn('green_entity');
  $entity_type
    ->getAdminPermission()
    ->willReturn('administer green_entity');
  $entity_type = $entity_type
    ->reveal();
  $entity = $this
    ->prophesize(ConfigEntityInterface::class);
  $entity
    ->getEntityType()
    ->willReturn($entity_type);
  $entity
    ->getEntityTypeId()
    ->willReturn('green_entity_bundle');
  $entity
    ->id()
    ->willReturn('default');
  $entity
    ->uuid()
    ->willReturn('fake uuid');
  $entity
    ->language()
    ->willReturn(new Language([
    'id' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
  ]));

  // User with no access.
  $user = $this
    ->buildMockUser(1, 'access content');
  $data[] = [
    $entity
      ->reveal(),
    'view label',
    $user
      ->reveal(),
    FALSE,
  ];

  // Permissions which grant "view label" access.
  $permissions = [
    'administer green_entity',
    'view green_entity',
    'view default green_entity',
    'view own green_entity',
    'view any green_entity',
    'view own default green_entity',
    'view any default green_entity',
  ];
  foreach ($permissions as $index => $permission) {
    $user = $this
      ->buildMockUser(10 + $index, $permission);
    $data[] = [
      $entity
        ->reveal(),
      'view label',
      $user
        ->reveal(),
      TRUE,
    ];
  }
  return $data;
}