public function EntityAccessControlHandlerTest::testEntityTranslationAccess in Drupal 8
Same name and namespace in other branches
- 9 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);
}