function EntityAccessControlHandlerTest::testEntityTranslationAccess
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Entity/EntityAccessControlHandlerTest.php \Drupal\KernelTests\Core\Entity\EntityAccessControlHandlerTest::testEntityTranslationAccess()
- 10 core/tests/Drupal/KernelTests/Core/Entity/EntityAccessControlHandlerTest.php \Drupal\KernelTests\Core\Entity\EntityAccessControlHandlerTest::testEntityTranslationAccess()
- 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\EntityCode
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.