You are here

public function EntityAccessControlHandlerTest::testEntityTranslationAccess in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Entity/EntityAccessControlHandlerTest.php \Drupal\KernelTests\Core\Entity\EntityAccessControlHandlerTest::testEntityTranslationAccess()
  2. 10 core/tests/Drupal/KernelTests/Core/Entity/EntityAccessControlHandlerTest.php \Drupal\KernelTests\Core\Entity\EntityAccessControlHandlerTest::testEntityTranslationAccess()

Ensures entity access for entity translations is properly working.

File

core/tests/Drupal/KernelTests/Core/Entity/EntityAccessControlHandlerTest.php, line 193

Class

EntityAccessControlHandlerTest
Tests the entity access control handler.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testEntityTranslationAccess() {

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

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