public function NodeAccessTest::testCreateAccess in Workbench Access 8
Test create access integration.
File
- tests/
src/ Kernel/ NodeAccessTest.php, line 92
Class
- NodeAccessTest
- Tests workbench_access integration with node access APIs.
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 = [
'create page content',
'edit any page content',
'access content',
'delete any page content',
'administer nodes',
];
$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('page', $allowed_editor));
$this
->assertFalse($this->accessHandler
->createAccess('page', $editor_with_no_access));
$this
->assertTrue($this->accessHandler
->createAccess('page', $editor_with_bypass_access));
}