View source
<?php
namespace Drupal\Tests\webform\Functional\Settings;
use Drupal\webform\Entity\Webform;
use Drupal\Tests\webform_node\Functional\WebformNodeBrowserTestBase;
class WebformSettingsLimitUniqueTest extends WebformNodeBrowserTestBase {
public static $modules = [
'webform',
'webform_node',
];
protected static $testWebforms = [
'test_form_limit_total_unique',
'test_form_limit_user_unique',
];
public function testLimitUnique() {
$webform_total_unique = Webform::load('test_form_limit_total_unique');
$webform_user_unique = Webform::load('test_form_limit_user_unique');
$user = $this
->drupalCreateUser();
$admin_user = $this
->drupalCreateUser([
'administer webform',
]);
$manage_any_user = $this
->drupalCreateUser([
'view any webform submission',
'edit any webform submission',
]);
$edit_any_user = $this
->drupalCreateUser([
'edit any webform submission',
]);
$manage_own_user = $this
->drupalCreateUser([
'view own webform submission',
'edit own webform submission',
]);
$edit_user_only = $this
->drupalCreateUser([
'edit own webform submission',
]);
$this
->drupalGet('/webform/test_form_limit_total_unique');
$this
->assertResponse(403);
$this
->assertNoFieldByName('name', '');
$this
->drupalLogin($manage_any_user);
$this
->drupalGet('/webform/test_form_limit_total_unique');
$this
->assertResponse(200);
$this
->assertFieldByName('name', '');
$this
->drupalLogin($admin_user);
$this
->drupalGet('/webform/test_form_limit_total_unique');
$this
->assertFieldByName('name', '');
$this
->drupalGet('/webform/test_form_limit_total_unique/test');
$this
->assertRaw(' The below webform has been prepopulated with custom/random test data. When submitted, this information <strong>will still be saved</strong> and/or <strong>sent to designated recipients</strong>');
$this
->drupalLogin($this->rootUser);
$this
->drupalGet('/webform/test_form_limit_total_unique');
$this
->assertFieldByName('name', '');
$this
->drupalLogin($admin_user);
$sid = $this
->postSubmission($webform_total_unique, [
'name' => 'John Smith',
]);
$this
->drupalGet('/webform/test_form_limit_total_unique');
$this
->assertFieldByName('name', 'John Smith');
$this
->assertRaw("<div><b>Submission ID:</b> {$sid}</div>");
$this
->drupalGet('/webform/test_form_limit_total_unique');
$this
->assertFieldByName('name', 'John Smith');
$this
->assertRaw("<div><b>Submission ID:</b> {$sid}</div>");
$this
->drupalGet('/webform/test_form_limit_total_unique/test');
$this
->assertFieldByName('name', 'John Smith');
$this
->assertRaw("<div><b>Submission ID:</b> {$sid}</div>");
$this
->assertNoRaw(' The below webform has been prepopulated with custom/random test data. When submitted, this information <strong>will still be saved</strong> and/or <strong>sent to designated recipients</strong>');
$this
->drupalLogin($manage_any_user);
$this
->drupalGet('/webform/test_form_limit_total_unique');
$this
->assertFieldByName('name', 'John Smith');
$this
->assertRaw("<div><b>Submission ID:</b> {$sid}</div>");
$this
->drupalLogout();
$node_total_unique = $this
->createWebformNode('test_form_limit_total_unique');
$this
->drupalGet('/webform/test_form_limit_total_unique');
$this
->assertResponse(403);
$this
->assertNoFieldByName('name', '');
$this
->drupalGet('/node/' . $node_total_unique
->id());
$this
->assertResponse(403);
$this
->drupalLogin($user);
$this
->drupalGet('/webform/test_form_limit_total_unique');
$this
->assertResponse(403);
$this
->assertNoFieldByName('name', '');
$this
->drupalGet('/node/' . $node_total_unique
->id());
$this
->assertResponse(403);
$this
->drupalLogin($manage_any_user);
$this
->drupalGet('/node/' . $node_total_unique
->id());
$this
->assertResponse(200);
$this
->assertFieldByName('name', '');
$this
->drupalLogin($admin_user);
$this
->drupalGet('/node/' . $node_total_unique
->id());
$this
->assertFieldByName('name', '');
$sid = $this
->postNodeSubmission($node_total_unique, [
'name' => 'John Lennon',
]);
$this
->drupalGet('/webform/test_form_limit_total_unique');
$this
->assertFieldByName('name', 'John Lennon');
$this
->assertRaw("<div><b>Submission ID:</b> {$sid}</div>");
$this
->drupalGet('/node/' . $node_total_unique
->id() . '/webform/test');
$this
->assertFieldByName('name', 'John Lennon');
$this
->assertRaw("<div><b>Submission ID:</b> {$sid}</div>");
$this
->drupalLogin($this->rootUser);
$this
->drupalGet('/node/' . $node_total_unique
->id() . '/webform/test');
$this
->assertFieldByName('name', 'John Lennon');
$this
->assertRaw("<div><b>Submission ID:</b> {$sid}</div>");
$this
->drupalLogout();
$this
->drupalGet('/webform/test_form_limit_user_unique');
$this
->assertResponse(403);
$this
->drupalLogin($user);
$this
->drupalGet('/webform/test_form_limit_user_unique');
$this
->assertResponse(403);
$this
->drupalLogin($edit_any_user);
$this
->drupalGet('/webform/test_form_limit_user_unique');
$this
->assertResponse(403);
$this
->drupalLogin($edit_user_only);
$this
->drupalGet('/webform/test_form_limit_user_unique');
$this
->assertResponse(403);
$this
->drupalLogin($manage_own_user);
$this
->drupalGet('/webform/test_form_limit_user_unique');
$this
->assertFieldByName('name', '');
$this
->drupalLogin($admin_user);
$this
->drupalGet('/webform/test_form_limit_user_unique');
$this
->assertFieldByName('name', '');
$this
->drupalGet('/webform/test_form_limit_user_unique/test');
$this
->assertRaw(' The below webform has been prepopulated with custom/random test data. When submitted, this information <strong>will still be saved</strong> and/or <strong>sent to designated recipients</strong>');
$this
->drupalLogin($this->rootUser);
$this
->drupalGet('/webform/test_form_limit_user_unique');
$this
->assertFieldByName('name', '');
$this
->drupalLogin($admin_user);
$sid = $this
->postSubmission($webform_user_unique, [
'name' => 'John Smith',
]);
$this
->drupalGet('/webform/test_form_limit_user_unique');
$this
->assertFieldByName('name', 'John Smith');
$this
->assertRaw("<div><b>Submission ID:</b> {$sid}</div>");
$this
->drupalGet('/webform/test_form_limit_user_unique/test');
$this
->assertFieldByName('name', 'John Smith');
$this
->assertRaw("<div><b>Submission ID:</b> {$sid}</div>");
$this
->drupalLogin($manage_own_user);
$this
->drupalGet('/webform/test_form_limit_user_unique');
$this
->assertFieldByName('name', '');
$this
->drupalLogin($this->rootUser);
$this
->drupalGet('/webform/test_form_limit_user_unique');
$this
->assertFieldByName('name', '');
$sid = $this
->postSubmission($webform_user_unique, [
'name' => 'Jane Doe',
]);
$this
->drupalGet('/webform/test_form_limit_user_unique');
$this
->assertFieldByName('name', 'Jane Doe');
$this
->assertRaw("<div><b>Submission ID:</b> {$sid}</div>");
$this
->assertLinkByHref(base_path() . 'webform/test_form_limit_user_unique/submissions/' . $sid . '/delete?destination=' . base_path() . 'form/test-form-limit-user-unique');
$this
->drupalGet('/webform/test_form_limit_user_unique/test');
$this
->assertFieldByName('name', 'Jane Doe');
$this
->assertRaw("<div><b>Submission ID:</b> {$sid}</div>");
$this
->assertLinkByHref(base_path() . 'admin/structure/webform/manage/test_form_limit_user_unique/submission/' . $sid . '/delete');
}
}