WebformGroupElementAccessTest.php in Webform 8.5
File
modules/webform_group/tests/src/Functional/WebformGroupElementAccessTest.php
View source
<?php
namespace Drupal\Tests\webform_group\Functional;
class WebformGroupElementAccessTest extends WebformGroupBrowserTestBase {
public function testGroupElementAccess() {
$group = $this
->createGroup([
'type' => 'default',
]);
$node = $this
->createWebformNode('test_group_element_access');
$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('anonymous');
$this
->assertNoFieldByName('authenticated');
$this
->assertNoFieldByName('outsider');
$this
->assertNoFieldByName('member');
$this
->assertNoFieldByName('custom');
$this
->drupalLogin($outsider_user);
$this
->drupalGet('/node/' . $node
->id());
$this
->assertNoFieldByName('anonymous');
$this
->assertFieldByName('authenticated');
$this
->assertNoFieldByName('outsider');
$this
->assertNoFieldByName('member');
$this
->assertNoFieldByName('custom');
$this
->drupalLogin($member_user);
$this
->drupalGet('/node/' . $node
->id());
$this
->assertNoFieldByName('anonymous');
$this
->assertFieldByName('authenticated');
$this
->assertNoFieldByName('outsider');
$this
->assertNoFieldByName('member');
$this
->assertNoFieldByName('custom');
$group
->addContent($node, 'group_node:webform');
$group
->save();
$this
->drupalLogout();
$this
->drupalGet('/node/' . $node
->id());
$this
->assertFieldByName('anonymous');
$this
->assertNoFieldByName('authenticated');
$this
->assertNoFieldByName('outsider');
$this
->assertNoFieldByName('member');
$this
->assertNoFieldByName('custom');
$this
->drupalLogin($outsider_user);
$this
->drupalGet('/node/' . $node
->id());
$this
->assertNoFieldByName('anonymous');
$this
->assertFieldByName('authenticated');
$this
->assertFieldByName('outsider');
$this
->assertNoFieldByName('member');
$this
->assertNoFieldByName('custom');
$this
->drupalLogin($member_user);
$this
->drupalGet('/node/' . $node
->id());
$this
->assertNoFieldByName('anonymous');
$this
->assertFieldByName('authenticated');
$this
->assertNoFieldByName('outsider');
$this
->assertFieldByName('member');
$this
->assertNoFieldByName('custom');
$this
->drupalLogin($custom_user);
$this
->drupalGet('/node/' . $node
->id());
$this
->assertNoFieldByName('anonymous');
$this
->assertFieldByName('authenticated');
$this
->assertNoFieldByName('outsider');
$this
->assertFieldByName('member');
$this
->assertFieldByName('custom');
}
}