function ContactPersonalTest::testPersonalContactFlood
Same name in other branches
- 9 core/modules/contact/tests/src/Functional/ContactPersonalTest.php \Drupal\Tests\contact\Functional\ContactPersonalTest::testPersonalContactFlood()
- 8.9.x core/modules/contact/tests/src/Functional/ContactPersonalTest.php \Drupal\Tests\contact\Functional\ContactPersonalTest::testPersonalContactFlood()
- 11.x core/modules/contact/tests/src/Functional/ContactPersonalTest.php \Drupal\Tests\contact\Functional\ContactPersonalTest::testPersonalContactFlood()
Tests the personal contact form flood protection.
File
-
core/
modules/ contact/ tests/ src/ Functional/ ContactPersonalTest.php, line 257
Class
- ContactPersonalTest
- Tests personal contact form functionality.
Namespace
Drupal\Tests\contact\FunctionalCode
public function testPersonalContactFlood() : void {
$flood_limit = 3;
$this->config('contact.settings')
->set('flood.limit', $flood_limit)
->save();
$this->drupalLogin($this->webUser);
// Submit contact form with correct values and check flood interval.
for ($i = 0; $i < $flood_limit; $i++) {
$this->submitPersonalContact($this->contactUser);
$this->assertSession()
->pageTextContains('Your message has been sent.');
}
// Submit contact form one over limit.
$this->submitPersonalContact($this->contactUser);
// Normal user should be denied access to flooded contact form.
$interval = \Drupal::service('date.formatter')->formatInterval($this->config('contact.settings')
->get('flood.interval'));
$this->assertSession()
->pageTextContains("You cannot send more than 3 messages in {$interval}. Try again later.");
// Test that the admin user can still access the contact form even though
// the flood limit was reached.
$this->drupalLogin($this->adminUser);
$this->assertSession()
->pageTextNotContains('Try again later.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.