function EntityAccessTest::testEntityTranslationAccess

Ensures entity access for entity translations is properly working.

File

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

Class

EntityAccessTest
Tests the entity access controller.

Namespace

Drupal\system\Tests\Entity

Code

function testEntityTranslationAccess() {

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

  // Create two test languages.
  foreach (array(
    'foo',
    'bar',
  ) as $langcode) {
    $language = new Language(array(
      'langcode' => $langcode,
      'name' => $this
        ->randomString(),
    ));
    language_save($language);
  }
  $entity = entity_create('entity_test', array(
    'name' => 'test',
    'langcode' => 'foo',
  ));
  $entity
    ->save();
  $translation = $entity
    ->getTranslation('bar');
  $this
    ->assertEntityAccess(array(
    'view' => TRUE,
  ), $translation);
}