public function MediaAccessControlHandlerTest::testAccess in Drupal 9
Same name and namespace in other branches
- 8 core/modules/media/tests/src/Kernel/MediaAccessControlHandlerTest.php \Drupal\Tests\media\Kernel\MediaAccessControlHandlerTest::testAccess()
Tests the media access control handler.
@covers ::checkAccess @dataProvider providerAccess
Parameters
string[] $permissions: The permissions that the user should be given.
array $entity_values: Initial values from which to create the media entity.
string $operation: The operation, one of 'view', 'update' or 'delete'.
\Drupal\Core\Access\AccessResultInterface $expected_result: Expected result.
string[] $expected_cache_contexts: Expected cache contexts.
string[] $expected_cache_tags: Expected cache tags.
File
- core/
modules/ media/ tests/ src/ Kernel/ MediaAccessControlHandlerTest.php, line 40
Class
- MediaAccessControlHandlerTest
- Tests the media access control handler.
Namespace
Drupal\Tests\media\KernelCode
public function testAccess(array $permissions, array $entity_values, $operation, AccessResultInterface $expected_result, array $expected_cache_contexts, array $expected_cache_tags) {
// Set a fixed ID so the type specific permissions match.
$media_type = $this
->createMediaType('test', [
'id' => 'test',
]);
$user = $this
->createUser($permissions);
$entity_values += [
'status' => FALSE,
'uid' => $user
->id(),
'bundle' => $media_type
->id(),
];
$entity = Media::create($entity_values);
$entity
->save();
/** @var \Drupal\Core\Entity\EntityAccessControlHandlerInterface $access_handler */
$access_handler = $this->container
->get('entity_type.manager')
->getAccessControlHandler('media');
$this
->assertAccess($expected_result, $expected_cache_contexts, $expected_cache_tags, $access_handler
->access($entity, $operation, $user, TRUE));
}