function LayoutBuilderAccessTest::testAccessWithBundles
Same name in other branches
- 9 core/modules/layout_builder/tests/src/Functional/LayoutBuilderAccessTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderAccessTest::testAccessWithBundles()
- 8.9.x core/modules/layout_builder/tests/src/Functional/LayoutBuilderAccessTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderAccessTest::testAccessWithBundles()
- 11.x 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.
array $permission_dependencies: An array of expected permission dependencies.
File
-
core/
modules/ layout_builder/ tests/ src/ Functional/ LayoutBuilderAccessTest.php, line 75
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, array $permission_dependencies) : void {
$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);
if (!empty($permission_dependencies)) {
$permission_definitions = \Drupal::service('user.permissions')->getPermissions();
foreach ($permission_dependencies as $permission => $expected_dependencies) {
$this->assertSame($expected_dependencies, $permission_definitions[$permission]['dependencies']);
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.