WebformSettingsRemoteAddrTest.php in Webform 8.5
File
tests/src/Functional/Settings/WebformSettingsRemoteAddrTest.php
View source
<?php
namespace Drupal\Tests\webform\Functional\Settings;
use Drupal\webform\Entity\Webform;
use Drupal\webform\Entity\WebformSubmission;
use Drupal\webform\WebformSubmissionForm;
use Drupal\Tests\webform\Functional\WebformBrowserTestBase;
class WebformSettingsRemoteAddrTest extends WebformBrowserTestBase {
protected static $testWebforms = [
'test_form_remote_addr',
];
public function testRemoteAddr() {
$this
->drupalLogin($this->rootUser);
$values = [
'webform_id' => 'test_form_remote_addr',
'data' => [
'name' => 'John',
],
];
$webform = Webform::load('test_form_remote_addr');
$sid = $this
->postSubmission($webform, [
'name' => 'John',
]);
$webform_submission = WebformSubmission::load($sid);
$this
->assertEqual($webform_submission
->getRemoteAddr(), '(unknown)');
$this
->assertEqual($webform_submission
->getOwnerId(), 1);
$webform_submission = WebformSubmissionForm::submitFormValues($values);
$this
->assertEqual($webform_submission
->getRemoteAddr(), '(unknown)');
$this
->assertEqual($webform_submission
->getOwnerId(), 1);
$webform
->setSetting('form_remote_addr', TRUE);
$webform
->save();
$sid = $this
->postSubmission($webform, [
'name' => 'John',
]);
$webform_submission = WebformSubmission::load($sid);
$this
->assertNotEqual($webform_submission
->getRemoteAddr(), '(unknown)');
$this
->assertEqual($webform_submission
->getOwnerId(), 1);
$webform_submission = WebformSubmissionForm::submitFormValues($values);
$this
->assertNotEqual($webform_submission
->getRemoteAddr(), '(unknown)');
$this
->assertEqual($webform_submission
->getOwnerId(), 1);
}
}