You are here

function EntityAccessControlHandlerTest::testEntityTranslationAccess in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Entity/EntityAccessControlHandlerTest.php \Drupal\system\Tests\Entity\EntityAccessControlHandlerTest::testEntityTranslationAccess()

Ensures entity access for entity translations is properly working.

File

core/modules/system/src/Tests/Entity/EntityAccessControlHandlerTest.php, line 121
Contains \Drupal\system\Tests\Entity\EntityAccessControlHandlerTest.

Class

EntityAccessControlHandlerTest
Tests the entity access control handler.

Namespace

Drupal\system\Tests\Entity

Code

function testEntityTranslationAccess() {

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

  // Create two test languages.
  foreach (array(
    'foo',
    'bar',
  ) as $langcode) {
    ConfigurableLanguage::create(array(
      'id' => $langcode,
      'label' => $this
        ->randomString(),
    ))
      ->save();
  }
  $entity = entity_create('entity_test', array(
    'name' => 'test',
    'langcode' => 'foo',
  ));
  $entity
    ->save();
  $translation = $entity
    ->addTranslation('bar');
  $this
    ->assertEntityAccess(array(
    'view' => TRUE,
  ), $translation);
}