public function AccessCheckTest::testBypassNodeAccess in Permissions by Term 8
Same name and namespace in other branches
- 8.2 tests/src/Kernel/AccessCheckTest.php \Drupal\Tests\permissions_by_term\Kernel\AccessCheckTest::testBypassNodeAccess()
File
- tests/
src/ Kernel/ AccessCheckTest.php, line 170
Class
- AccessCheckTest
- Class AccessCheckTest
Namespace
Drupal\Tests\permissions_by_term\KernelCode
public function testBypassNodeAccess() {
Vocabulary::create([
'name' => 'Test Multilingual',
'vid' => 'test_multilingual',
'langcode' => 'de',
])
->save();
$term = Term::create([
'name' => 'term1',
'vid' => 'test',
'langcode' => 'de',
]);
$term
->save();
$node = Node::create([
'type' => 'page',
'title' => 'test_title',
'field_tags' => [
[
'target_id' => $term
->id(),
],
],
]);
$node
->save();
$this->accessStorage
->addTermPermissionsByUserIds([
99,
], $term
->id(), 'de');
$this
->assertFalse($this->accessCheck
->canUserAccessByNodeId($node
->id(), \Drupal::currentUser()
->id(), 'de'));
$editorRole = Role::create([
'id' => 'editor',
]);
$editorRole
->grantPermission('bypass node access');
$editorRole
->save();
$user = User::load(\Drupal::currentUser()
->id());
$user
->addRole('editor');
$user
->save();
$accountSwitcher = \Drupal::service('account_switcher');
$accountSwitcher
->switchTo($user);
$this
->assertTrue($this->accessCheck
->canUserAccessByNodeId($node
->id(), \Drupal::currentUser()
->id(), 'de'));
}