WebformGroupSubmissionAccessTest.php in Webform 8.5
File
modules/webform_group/tests/src/Functional/WebformGroupSubmissionAccessTest.php
View source
<?php
namespace Drupal\Tests\webform_group\Functional;
use Drupal\Tests\webform\Traits\WebformSubmissionViewAccessTrait;
use Drupal\webform\Entity\Webform;
use Drupal\webform\Entity\WebformSubmission;
class WebformGroupSubmissionAccessTest extends WebformGroupBrowserTestBase {
use WebformSubmissionViewAccessTrait;
public static $modules = [
'webform_group',
'webform_group_test',
'views',
'webform_test_views',
];
public function testWebformGroupAccessSubmissionViewsTest() {
$webform = Webform::load('contact');
$access = $webform
->getAccessRules();
$access['create']['roles'] = [];
$access['view_own']['group_roles'] = [
'member',
];
$access['view_any']['group_roles'] = [
'custom',
];
$webform
->setAccessRules($access);
$webform
->save();
$group = $this
->createGroup([
'type' => 'default',
]);
$node = $this
->createWebformNode('contact');
$group
->addContent($node, 'group_node:webform');
$group
->save();
$users = [];
$users['outsider'] = $this
->createUser();
$users['member'] = $this
->createUser();
$group
->addMember($users['member']);
$users['custom'] = $this
->createUser();
$group
->addMember($users['custom'], [
'group_roles' => [
'default-custom',
],
]);
$group
->save();
$submission_generate = \Drupal::service('webform_submission.generate');
foreach ($users as $user) {
WebformSubmission::create([
'webform_id' => 'contact',
'entity_type' => 'node',
'entity_id' => $node
->id(),
'uid' => $user
->id(),
'data' => $submission_generate
->getData($webform),
])
->save();
}
$this
->checkUserSubmissionAccess($webform, $users);
}
}