WebformGroupFormAccessTest.php in Webform 8.5
File
modules/webform_group/tests/src/Functional/WebformGroupFormAccessTest.php
View source
<?php
namespace Drupal\Tests\webform_group\Functional;
use Drupal\webform\Entity\Webform;
class WebformGroupFormAccessTest extends WebformGroupBrowserTestBase {
public function testGroupFormAccess() {
$webform = Webform::load('contact');
$group = $this
->createGroup([
'type' => 'default',
]);
$node = $this
->createWebformNode('contact');
$nid = $node
->id();
$outsider_user = $this
->createUser();
$member_user = $this
->createUser();
$group
->addMember($member_user);
$custom_user = $this
->createUser();
$group
->addMember($custom_user, [
'group_roles' => [
'default-custom',
],
]);
$group
->save();
$this
->drupalLogout();
$this
->drupalGet('/node/' . $node
->id());
$this
->assertFieldByName('message');
$this
->drupalLogin($outsider_user);
$this
->drupalGet('/node/' . $node
->id());
$this
->assertFieldByName('message');
$this
->drupalLogin($member_user);
$this
->drupalGet('/node/' . $node
->id());
$this
->assertFieldByName('message');
$group
->addContent($node, 'group_node:webform');
$group
->save();
$access = $webform
->getAccessRules();
$access['create']['roles'] = [];
$access['create']['group_roles'] = [];
$webform
->setAccessRules($access);
$webform
->save();
$this
->drupalLogout();
$this
->drupalGet('/node/' . $node
->id());
$this
->assertNoFieldByName('message');
$this
->drupalLogin($outsider_user);
$this
->drupalGet('/node/' . $node
->id());
$this
->assertNoFieldByName('message');
$access['create']['group_roles'][] = 'outsider';
$webform
->setAccessRules($access);
$webform
->save();
$this
->drupalGet('/node/' . $node
->id());
$this
->assertFieldByName('message');
$this
->drupalLogin($member_user);
$this
->drupalGet('/node/' . $node
->id());
$this
->assertNoFieldByName('message');
$access['create']['group_roles'][] = 'member';
$webform
->setAccessRules($access);
$webform
->save();
$this
->drupalGet('/node/' . $node
->id());
$this
->assertFieldByName('message');
$this
->drupalLogout();
$this
->drupalGet("/node/{$nid}/webform/results/submissions");
$this
->assertResponse(403);
$this
->drupalLogin($member_user);
$this
->drupalGet("/node/{$nid}/webform/results/submissions");
$this
->assertResponse(403);
$access['view_any']['group_roles'][] = 'member';
$webform
->setAccessRules($access);
$webform
->save();
$this
->drupalGet("/node/{$nid}/webform/results/submissions");
$this
->assertResponse(200);
}
}