public function EntityTestAccessTest::testCreateAccess in Workbench Access 8
Test create access integration.
File
- tests/
src/ Kernel/ EntityTestAccessTest.php, line 107
Class
- EntityTestAccessTest
- Tests workbench_access integration with entity_test.
Namespace
Drupal\Tests\workbench_access\KernelCode
public function testCreateAccess() {
// The first user in a kernel test gets UID 1, so we need to make sure we're
// not testing with that user.
$this
->createUser();
// Create a section.
$term = Term::create([
'vid' => $this->vocabulary
->id(),
'name' => 'Some section',
]);
$term
->save();
// Create two users with equal permissions but assign one of them to the
// section.
$permissions = [
'administer entity_test content',
'view test entity',
];
$allowed_editor = $this
->createUser($permissions);
$allowed_editor
->save();
$this->userStorage
->addUser($this->scheme, $allowed_editor, [
$term
->id(),
]);
$editor_with_no_access = $this
->createUser($permissions);
$permissions[] = 'bypass workbench access';
$editor_with_bypass_access = $this
->createUser($permissions);
$this
->assertTrue($this->accessHandler
->createAccess('access_controlled', $allowed_editor));
$this
->assertFalse($this->accessHandler
->createAccess('access_controlled', $editor_with_no_access));
$this
->assertTrue($this->accessHandler
->createAccess('access_controlled', $editor_with_bypass_access));
}