You are here

public function YamlFormUiElementTest::testPermissions in YAML Form 8

Tests permissions.

File

modules/yamlform_ui/src/Tests/YamlFormUiElementTest.php, line 164

Class

YamlFormUiElementTest
Tests for form UI element.

Namespace

Drupal\yamlform_ui\Tests

Code

public function testPermissions() {
  $yamlform = $this
    ->createYamlForm();

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

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

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