You are here

public function HoneypotFormTest::testStrictEmptinessOnHoneypotField in Honeypot 8

Same name and namespace in other branches
  1. 2.0.x tests/src/Functional/HoneypotFormTest.php \Drupal\Tests\honeypot\Functional\HoneypotFormTest::testStrictEmptinessOnHoneypotField()

Test that any (not-strict-empty) value triggers protection.

File

tests/src/Functional/HoneypotFormTest.php, line 178

Class

HoneypotFormTest
Test Honeypot spam protection functionality.

Namespace

Drupal\Tests\honeypot\Functional

Code

public function testStrictEmptinessOnHoneypotField() {

  // Initialise the form values.
  $edit['name'] = $this
    ->randomMachineName();
  $edit['mail'] = $edit['name'] . '@example.com';

  // Any value that is not strictly empty should trigger Honeypot.
  foreach ([
    '0',
    ' ',
  ] as $value) {
    $edit['url'] = $value;
    $this
      ->drupalPostForm('user/register', $edit, $this
      ->t('Create new account'));
    $this
      ->assertText($this
      ->t('There was a problem with your form submission. Please refresh the page and try again.'), "Honeypot protection is triggered when the honeypot field contains '{$value}'.");
  }
}