function EntityAccessControlHandlerTest::testDefaultEntityAccess in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/src/Tests/Entity/EntityAccessControlHandlerTest.php \Drupal\system\Tests\Entity\EntityAccessControlHandlerTest::testDefaultEntityAccess()
Ensures default entity access is checked when necessary.
This ensures that the default checkAccess() implementation of the entity access control handler is considered if hook_entity_access() has not explicitly forbidden access. Therefore the default checkAccess() implementation can forbid access, even after access was already explicitly allowed by hook_entity_access().
See also
\Drupal\entity_test\EntityTestAccessControlHandler::checkAccess()
File
- core/
modules/ system/ src/ Tests/ Entity/ EntityAccessControlHandlerTest.php, line 81 - Contains \Drupal\system\Tests\Entity\EntityAccessControlHandlerTest.
Class
- EntityAccessControlHandlerTest
- Tests the entity access control handler.
Namespace
Drupal\system\Tests\EntityCode
function testDefaultEntityAccess() {
// Set up a non-admin user that is allowed to view test entities.
\Drupal::currentUser()
->setAccount($this
->createUser(array(
'uid' => 2,
), array(
'view test entity',
)));
$entity = entity_create('entity_test', array(
'name' => 'forbid_access',
));
// The user is denied access to the entity.
$this
->assertEntityAccess(array(
'create' => FALSE,
'update' => FALSE,
'delete' => FALSE,
'view' => FALSE,
), $entity);
}