WebformNodeAccessPermissionsTest.php in Webform 8.5
File
modules/webform_node/tests/src/Functional/Access/WebformNodeAccessPermissionsTest.php
View source
<?php
namespace Drupal\Tests\webform_node\Functional\Access;
use Drupal\webform\Entity\Webform;
use Drupal\Tests\webform_node\Functional\WebformNodeBrowserTestBase;
class WebformNodeAccessPermissionsTest extends WebformNodeBrowserTestBase {
public static $modules = [
'webform',
'webform_node',
];
public function testAccessPermissions() {
global $base_path;
$submission_own_account = $this
->drupalCreateUser([
'view own webform submission',
'edit own webform submission',
'delete own webform submission',
'access webform submission user',
]);
$submission_any_account = $this
->drupalCreateUser([
'view any webform submission',
'edit any webform submission',
'delete any webform submission',
]);
$submission_own_node_account = $this
->drupalCreateUser([
'view webform submissions own node',
'edit webform submissions own node',
'delete webform submissions own node',
]);
$submission_any_node_account = $this
->drupalCreateUser([
'view webform submissions any node',
'edit webform submissions any node',
'delete webform submissions any node',
]);
$webform = Webform::load('contact');
$node = $this
->createWebformNode('contact', [
'uid' => $submission_own_node_account
->id(),
]);
$nid = $node
->id();
$this
->drupalLogin($submission_own_account);
$edit = [
'subject' => '{subject}',
'message' => '{message}',
];
$sid_1 = $this
->postNodeSubmission($node, $edit);
$this
->drupalGet("node/{$nid}");
$this
->assertRaw('You have already submitted this webform.');
$this
->assertRaw("<a href=\"{$base_path}node/{$nid}/webform/submissions/{$sid_1}\">View your previous submission</a>.");
$this
->drupalGet("node/{$nid}/webform/submissions/{$sid_1}");
$this
->assertResponse(200);
$this
->drupalGet("node/{$nid}/webform/submissions/{$sid_1}/edit");
$this
->assertResponse(200);
$this
->drupalGet("node/{$nid}/webform/submissions/{$sid_1}/delete");
$this
->assertResponse(200);
$sid_2 = $this
->postNodeSubmission($node, $edit);
$this
->drupalGet("node/{$nid}");
$this
->assertRaw('You have already submitted this webform.');
$this
->assertRaw("<a href=\"{$base_path}node/{$nid}/webform/submissions\">View your previous submissions</a>");
$this
->drupalGet("node/{$nid}/webform/submissions");
$this
->assertResponse(200);
$this
->assertLinkByHref("{$base_path}node/{$nid}/webform/submissions/{$sid_1}");
$this
->assertLinkByHref("{$base_path}node/{$nid}/webform/submissions/{$sid_2}");
$this
->drupalGet("node/{$nid}/webform/submissions/{$sid_2}/duplicate");
$this
->assertResponse(403);
$webform
->setSetting('submission_user_duplicate', TRUE);
$webform
->save();
$this
->drupalGet("node/{$nid}/webform/submissions/{$sid_2}/duplicate");
$this
->assertResponse(200);
$this
->drupalGet("node/{$nid}/webform/results/submissions");
$this
->assertResponse(403);
$this
->drupalLogin($submission_any_account);
$this
->drupalGet("node/{$nid}/webform/results/submissions");
$this
->assertResponse(200);
$this
->assertLinkByHref("{$base_path}node/{$nid}/webform/submission/{$sid_1}");
$this
->assertLinkByHref("{$base_path}node/{$nid}/webform/submission/{$sid_2}");
$this
->drupalGet("node/{$nid}/webform/submission/{$sid_1}");
$this
->assertResponse(200);
$this
->drupalLogin($submission_own_node_account);
$this
->drupalGet("node/{$nid}/webform/results/submissions");
$this
->assertResponse(200);
$this
->assertLinkByHref("{$base_path}node/{$nid}/webform/submission/{$sid_1}");
$this
->assertLinkByHref("{$base_path}node/{$nid}/webform/submission/{$sid_2}");
$this
->drupalGet("node/{$nid}/webform/submission/{$sid_1}");
$this
->assertResponse(200);
$this
->drupalGet("node/{$nid}/webform/submissions/{$sid_1}/edit");
$this
->assertResponse(200);
$this
->drupalGet("node/{$nid}/webform/submissions/{$sid_1}/delete");
$this
->assertResponse(200);
$this
->drupalLogin($submission_any_node_account);
$this
->drupalGet("node/{$nid}/webform/results/submissions");
$this
->assertResponse(200);
$this
->assertLinkByHref("{$base_path}node/{$nid}/webform/submission/{$sid_1}");
$this
->assertLinkByHref("{$base_path}node/{$nid}/webform/submission/{$sid_2}");
$this
->drupalGet("node/{$nid}/webform/submission/{$sid_1}");
$this
->assertResponse(200);
$this
->drupalGet("node/{$nid}/webform/submissions/{$sid_1}/edit");
$this
->assertResponse(200);
$this
->drupalGet("node/{$nid}/webform/submissions/{$sid_1}/delete");
$this
->assertResponse(200);
}
}