public function LayoutBuilderAccessTest::testAccessWithBundles in Drupal 8
Same name and namespace in other branches
- 9 core/modules/layout_builder/tests/src/Functional/LayoutBuilderAccessTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderAccessTest::testAccessWithBundles()
Tests Layout Builder access for an entity type that has bundles.
@dataProvider providerTestAccessWithBundles
Parameters
array $permissions: An array of permissions to grant to the user.
bool $default_access: Whether access is expected for the defaults.
bool $non_editable_access: Whether access is expected for a non-editable override.
bool $editable_access: Whether access is expected for an editable override.
File
- core/
modules/ layout_builder/ tests/ src/ Functional/ LayoutBuilderAccessTest.php, line 70
Class
- LayoutBuilderAccessTest
- Tests access to Layout Builder.
Namespace
Drupal\Tests\layout_builder\FunctionalCode
public function testAccessWithBundles(array $permissions, $default_access, $non_editable_access, $editable_access) {
$permissions[] = 'edit own bundle_with_section_field content';
$permissions[] = 'access content';
$user = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($user);
$editable_node = $this
->createNode([
'uid' => $user
->id(),
'type' => 'bundle_with_section_field',
'title' => 'The first node title',
'body' => [
[
'value' => 'The first node body',
],
],
]);
$non_editable_node = $this
->createNode([
'uid' => 1,
'type' => 'bundle_with_section_field',
'title' => 'The second node title',
'body' => [
[
'value' => 'The second node body',
],
],
]);
$non_viewable_node = $this
->createNode([
'uid' => $user
->id(),
'status' => 0,
'type' => 'bundle_with_section_field',
'title' => 'Nobody can see this node.',
'body' => [
[
'value' => 'Does it really exist?',
],
],
]);
$this
->drupalGet($editable_node
->toUrl('edit-form'));
$this
->assertExpectedAccess(TRUE);
$this
->drupalGet($non_editable_node
->toUrl('edit-form'));
$this
->assertExpectedAccess(FALSE);
$this
->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default/layout');
$this
->assertExpectedAccess($default_access);
$this
->drupalGet('node/' . $editable_node
->id() . '/layout');
$this
->assertExpectedAccess($editable_access);
$this
->drupalGet('node/' . $non_editable_node
->id() . '/layout');
$this
->assertExpectedAccess($non_editable_access);
$this
->drupalGet($non_viewable_node
->toUrl());
$this
->assertExpectedAccess(FALSE);
$this
->drupalGet('node/' . $non_viewable_node
->id() . '/layout');
$this
->assertExpectedAccess(FALSE);
}