You are here

public function IntegrationTest::testIntegration in Webform Deter 8

Tests basic webform deter functionality.

File

tests/src/FunctionalJavascript/IntegrationTest.php, line 48

Class

IntegrationTest
Tests basic webform_deter functionality.

Namespace

Drupal\Tests\webform_deter\FunctionalJavascript

Code

public function testIntegration() {
  $session = $this
    ->getSession();
  $page = $session
    ->getPage();
  $assert_session = $this
    ->assertSession();

  // Before anything else, check that the install defined a default message
  // and no patterns.
  $config = \Drupal::config('webform_deter.settings');
  $message = $config
    ->get('warning_message');
  $this
    ->assertEquals(WebformDeterSettingsForm::DEFAULT_MESSAGE, $message);
  $patterns = $config
    ->get('patterns');
  $this
    ->assertEquals([], $patterns);

  // Configure something else on the config form.
  $this
    ->drupalGet('/admin/config/system');
  $page
    ->clickLink('Webform Deter Settings');
  $assert_session
    ->addressEquals('/admin/config/system/webform_deter/settings');
  $assert_session
    ->pageTextContains('Webform Deter Settings');
  $assert_session
    ->pageTextContains('The message shown to users when a deter pattern matches.');
  $assert_session
    ->pageTextContains('A new-line separated list of patterns to match against.');
  $page
    ->fillField('warning_message', 'Hey ho, private info in here!');
  $patterns = <<<PATTERNS
(dob|birthday|date of birth)
[\\d \\-]{13,19}
(card number|credit card)
\\d{1,2}[^\\d]\\d{1,2}[^\\d]\\d{2,4}
\\d{9}
(license number|driver\\'s license number)
[\\d\\-]{9,11}
(ssn|social security number)
PATTERNS;
  $page
    ->fillField('patterns', $patterns);
  $page
    ->findButton('Save configuration')
    ->press();
  $assert_session
    ->pageTextContains('The configuration options have been saved');
  $this
    ->drupalGet('/webform/contact');
  $assert_session
    ->fieldExists('Your Name');
  $page
    ->fillField('subject', 'Foo');

  // Test a bunch of matching text samples.
  $personal_info = [
    'dob',
    'birthday',
    'date of birth',
    'card number',
    'credit card',
    '4545 4545 1212 1212',
    '123456789',
    'license number',
    '123-45-6789',
    'ssn',
    'social security number',
  ];
  foreach ($personal_info as $value) {
    $page
      ->fillField('message', 'aaa ' . $value . ' bbb');
    $page
      ->findButton('Send message')
      ->press();
    $this
      ->assertTrue($this
      ->assertAlertMessage('Hey ho, private info in here!'));
    $this
      ->cancelAlert();
  }

  // If you click "OK" in the alert, the webform submission goes through.
  $page
    ->fillField('message', 'aaa ssn bbb');
  $page
    ->findButton('Send message')
    ->press();
  $this
    ->assertTrue($this
    ->assertAlertMessage('Hey ho, private info in here!'));
  $this
    ->confirmAlert();
  $assert_session
    ->pageTextContains('Your message has been sent');
}