function EntityAccessTest::testEntityAccess

Ensures entity access is properly working.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Entity/EntityAccessTest.php, line 62
Contains Drupal\system\Tests\Entity\EntityAccessTest.

Class

EntityAccessTest
Tests the entity access controller.

Namespace

Drupal\system\Tests\Entity

Code

function testEntityAccess() {

  // Set up a non-admin user that is allowed to view test entities.
  global $user;
  $user = $this
    ->createUser(array(
    'uid' => 2,
  ), array(
    'view test entity',
  ));
  $entity = entity_create('entity_test', array(
    'name' => 'test',
  ));

  // The current user is allowed to view entities.
  $this
    ->assertEntityAccess(array(
    'create' => FALSE,
    'update' => FALSE,
    'delete' => FALSE,
    'view' => TRUE,
  ), $entity);

  // The custom user is not allowed to perform any operation on test entities.
  $custom_user = $this
    ->createUser();
  $this
    ->assertEntityAccess(array(
    'create' => FALSE,
    'update' => FALSE,
    'delete' => FALSE,
    'view' => FALSE,
  ), $entity, $custom_user);
}