public function HoneypotFormTest::testProtectRegisterUserTooFast in Honeypot 2.0.x
Same name and namespace in other branches
- 8 tests/src/Functional/HoneypotFormTest.php \Drupal\Tests\honeypot\Functional\HoneypotFormTest::testProtectRegisterUserTooFast()
Test for user register too fast.
File
- tests/
src/ Functional/ HoneypotFormTest.php, line 152
Class
- HoneypotFormTest
- Test Honeypot spam protection functionality.
Namespace
Drupal\Tests\honeypot\FunctionalCode
public function testProtectRegisterUserTooFast() {
\Drupal::configFactory()
->getEditable('honeypot.settings')
->set('time_limit', 1)
->save();
// First attempt a submission that does not trigger honeypot.
$edit['name'] = $this
->randomMachineName();
$edit['mail'] = $edit['name'] . '@example.com';
$this
->drupalGet('user/register');
sleep(2);
$this
->drupalPostForm(NULL, $edit, $this
->t('Create new account'));
$this
->assertNoText($this
->t('There was a problem with your form submission.'));
// Set the time limit a bit higher so we can trigger honeypot.
\Drupal::configFactory()
->getEditable('honeypot.settings')
->set('time_limit', 5)
->save();
// Set up form and submit it.
$edit['name'] = $this
->randomMachineName();
$edit['mail'] = $edit['name'] . '@example.com';
$this
->drupalPostForm('user/register', $edit, $this
->t('Create new account'));
// Form should have error message.
$this
->assertSession()
->pageTextContains('There was a problem with your form submission. Please wait 6 seconds and try again.');
}