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 104
Contains Drupal\system\Tests\Entity\EntityAccessTest.

Class

EntityAccessTest
Tests the entity access controller.

Namespace

Drupal\system\Tests\Entity

Code

function testEntityTranslationAccess() {

  // Enable translations for the test entity type.
  variable_set('entity_test_translation', TRUE);
  module_enable(array(
    'locale',
  ));

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

  // 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);
}