You are here

public function LayoutBuilderAccessTest::testAccessWithoutBundles in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/layout_builder/tests/src/Functional/LayoutBuilderAccessTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderAccessTest::testAccessWithoutBundles()

Tests Layout Builder access for an entity type that does not have bundles.

@dataProvider providerTestAccessWithoutBundles

File

core/modules/layout_builder/tests/src/Functional/LayoutBuilderAccessTest.php, line 187

Class

LayoutBuilderAccessTest
Tests access to Layout Builder.

Namespace

Drupal\Tests\layout_builder\Functional

Code

public function testAccessWithoutBundles(array $permissions, $default_access, $non_editable_access, $editable_access, array $permission_dependencies) {
  $permissions[] = 'access user profiles';
  $user = $this
    ->drupalCreateUser($permissions);
  $this
    ->drupalLogin($user);
  $this
    ->drupalGet('admin/config/people/accounts/display/default/layout');
  $this
    ->assertExpectedAccess($default_access);
  $this
    ->drupalGet($user
    ->toUrl());
  $this
    ->assertExpectedAccess(TRUE);
  $this
    ->drupalGet($user
    ->toUrl('edit-form'));
  $this
    ->assertExpectedAccess(TRUE);
  $this
    ->drupalGet('user/' . $user
    ->id() . '/layout');
  $this
    ->assertExpectedAccess($editable_access);
  $non_editable_user = $this
    ->drupalCreateUser();
  $this
    ->drupalGet($non_editable_user
    ->toUrl());
  $this
    ->assertExpectedAccess(TRUE);
  $this
    ->drupalGet($non_editable_user
    ->toUrl('edit-form'));
  $this
    ->assertExpectedAccess(FALSE);
  $this
    ->drupalGet('user/' . $non_editable_user
    ->id() . '/layout');
  $this
    ->assertExpectedAccess($non_editable_access);
  $non_viewable_user = $this
    ->drupalCreateUser([], 'bad person', FALSE, [
    'status' => 0,
  ]);
  $this
    ->drupalGet($non_viewable_user
    ->toUrl());
  $this
    ->assertExpectedAccess(FALSE);
  $this
    ->drupalGet($non_viewable_user
    ->toUrl('edit-form'));
  $this
    ->assertExpectedAccess(FALSE);
  $this
    ->drupalGet('user/' . $non_viewable_user
    ->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']);
    }
  }
}