function ContactPersonalTest::testPersonalContactFlood

Same name in other branches
  1. 9 core/modules/contact/tests/src/Functional/ContactPersonalTest.php \Drupal\Tests\contact\Functional\ContactPersonalTest::testPersonalContactFlood()
  2. 10 core/modules/contact/tests/src/Functional/ContactPersonalTest.php \Drupal\Tests\contact\Functional\ContactPersonalTest::testPersonalContactFlood()
  3. 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 259

Class

ContactPersonalTest
Tests personal contact form functionality.

Namespace

Drupal\Tests\contact\Functional

Code

public function testPersonalContactFlood() {
    $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->assertText(t('Your message has been sent.'), 'Message sent.');
    }
    // Submit contact form one over limit.
    $this->submitPersonalContact($this->contactUser);
    $this->assertRaw(t('You cannot send more than %number messages in @interval. Try again later.', [
        '%number' => $flood_limit,
        '@interval' => \Drupal::service('date.formatter')->formatInterval($this->config('contact.settings')
            ->get('flood.interval')),
    ]), 'Normal user denied access to flooded contact form.');
    // Test that the admin user can still access the contact form even though
    // the flood limit was reached.
    $this->drupalLogin($this->adminUser);
    $this->assertNoText('Try again later.', 'Admin user not denied access to flooded contact form.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.