WebformSettingsConfidentialTest.php in Webform 8.5
File
tests/src/Functional/Settings/WebformSettingsConfidentialTest.php
View source
<?php
namespace Drupal\Tests\webform\Functional\Settings;
use Drupal\user\Entity\Role;
use Drupal\webform\Entity\Webform;
use Drupal\webform\Entity\WebformSubmission;
use Drupal\Tests\webform\Functional\WebformBrowserTestBase;
class WebformSettingsConfidentialTest extends WebformBrowserTestBase {
protected static $testWebforms = [
'test_form_confidential',
];
public function testConfidential() {
$anonymous_role = Role::load('anonymous');
$anonymous_role
->grantPermission('view own webform submission')
->grantPermission('edit own webform submission')
->grantPermission('delete own webform submission')
->save();
$this
->drupalLogin($this->rootUser);
$webform = Webform::load('test_form_confidential');
$this
->drupalGet('/webform/test_form_confidential');
$this
->assertNoFieldById('edit-name', NULL);
$this
->assertRaw('This form is confidential.');
$this
->drupalGet('/webform/test_form_confidential/test');
$this
->assertFieldById('edit-name', NULL);
$this
->assertNoRaw('This form is confidential.');
$sid = $this
->postSubmissionTest($webform, [
'name' => 'John',
]);
$webform_submission = WebformSubmission::load($sid);
$this
->assertEqual($webform_submission
->getRemoteAddr(), '(unknown)');
$this
->assertEqual($webform_submission
->getOwnerId(), 0);
$this
->drupalLogout();
$this
->drupalGet('/webform/test_form_confidential');
$this
->assertFieldById('edit-name', NULL);
$this
->assertNoRaw('This form is confidential.');
$sid = $this
->postSubmission($webform, [
'name' => 'John',
]);
$webform_submission = WebformSubmission::load($sid);
$this
->assertEqual($webform_submission
->getRemoteAddr(), '(unknown)');
$this
->assertEqual($webform_submission
->getOwnerId(), 0);
$this
->drupalGet('/webform/test_form_confidential');
$this
->assertRaw('View your previous submission');
$this
->drupalLogin($this->rootUser);
$webform_submission = $this
->loadSubmission($sid);
$this
->assertEqual($webform_submission
->getOwnerId(), 0);
$this
->drupalLogout();
$this
->drupalGet('/webform/test_form_confidential');
$this
->assertNoRaw('View your previous submission.');
}
}