You are here

public function WebformSettingsRemoteAddrTest::testRemoteAddr in Webform 8.5

Same name and namespace in other branches
  1. 6.x tests/src/Functional/Settings/WebformSettingsRemoteAddrTest.php \Drupal\Tests\webform\Functional\Settings\WebformSettingsRemoteAddrTest::testRemoteAddr()

Tests webform disable remote IP address.

File

tests/src/Functional/Settings/WebformSettingsRemoteAddrTest.php, line 27

Class

WebformSettingsRemoteAddrTest
Tests for disable tracking of remote IP address.

Namespace

Drupal\Tests\webform\Functional\Settings

Code

public function testRemoteAddr() {
  $this
    ->drupalLogin($this->rootUser);

  // Get submission values and data.
  $values = [
    'webform_id' => 'test_form_remote_addr',
    'data' => [
      'name' => 'John',
    ],
  ];

  // Make sure the IP is not stored.
  $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);

  // Enable the setting and make sure the IP is stored.
  $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);
}