You are here

public function WebformUiElementTest::testPermissions in Webform 6.x

Same name and namespace in other branches
  1. 8.5 modules/webform_ui/tests/src/Functional/WebformUiElementTest.php \Drupal\Tests\webform_ui\Functional\WebformUiElementTest::testPermissions()

Tests permissions.

File

modules/webform_ui/tests/src/Functional/WebformUiElementTest.php, line 296

Class

WebformUiElementTest
Tests for webform UI element.

Namespace

Drupal\Tests\webform_ui\Functional

Code

public function testPermissions() {
  $webform = Webform::load('contact');

  // Check source page access not visible to user with 'administer webform'
  // permission.
  $account = $this
    ->drupalCreateUser([
    'administer webform',
  ]);
  $this
    ->drupalLogin($account);
  $this
    ->drupalGet('/admin/structure/webform/manage/' . $webform
    ->id() . '/source');
  $this
    ->assertResponse(403);
  $this
    ->drupalLogout();

  // Check source page access not visible to user with 'edit webform source'
  // without 'administer webform' permission.
  $account = $this
    ->drupalCreateUser([
    'edit webform source',
  ]);
  $this
    ->drupalLogin($account);
  $this
    ->drupalGet('/admin/structure/webform/manage/' . $webform
    ->id() . '/source');
  $this
    ->assertResponse(403);
  $this
    ->drupalLogout();

  // Check source page access visible to user with 'edit webform source'
  // and 'administer webform' permission.
  $account = $this
    ->drupalCreateUser([
    'administer webform',
    'edit webform source',
  ]);
  $this
    ->drupalLogin($account);
  $this
    ->drupalGet('/admin/structure/webform/manage/' . $webform
    ->id() . '/source');
  $this
    ->assertResponse(200);
  $this
    ->drupalLogout();
}