function EntityAccessControlHandlerTest::testEntityTranslationAccess

Same name in other branches
  1. 9 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()
  3. 11.x 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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.