BlockContentAccessControlHandler example

// Create user 1 test does not have all permissions.     User::create([
      'name' => 'admin',
    ])->save();

    $this->role = Role::create([
      'id' => 'roly',
      'label' => 'roly poly',
    ]);
    $this->role->save();
    $this->accessControlHandler = new BlockContentAccessControlHandler(\Drupal::entityTypeManager()->getDefinition('block_content'), \Drupal::service('event_dispatcher'));
  }

  /** * Test block content entity access. * * @param string $operation * The entity operation to test. * @param bool $published * Whether the latest revision should be published. * @param bool $reusable * Whether the block content should be reusable. Non-reusable blocks are * typically used in Layout Builder. * @param array $permissions * Permissions to grant to the test user. * @param bool $isLatest * Whether the block content should be the latest revision when checking * access. If FALSE, multiple revisions will be created, and an older * revision will be loaded before checking access. * @param string|null $parent_access * Whether the test user has access to the parent entity, valid values are * class names of classes implementing AccessResultInterface. Set to NULL to * assert parent will not be called. * @param string $expected_access * The expected access for the user and block content. Valid values are * class names of classes implementing AccessResultInterface * @param string|null $expected_access_message * The expected access message. * * @covers ::checkAccess * * @dataProvider providerTestAccess * * @phpstan-param class-string<\Drupal\Core\Access\AccessResultInterface>|null $parent_access * @phpstan-param class-string<\Drupal\Core\Access\AccessResultInterface> $expected_access */
Home | Imprint | This part of the site doesn't use cookies.