You are here

public function ContactStorageTest::testMaximumSubmissionLimit in Contact Storage 8

File

tests/src/Functional/ContactStorageTest.php, line 392

Class

ContactStorageTest
Tests storing contact messages and viewing them through UI.

Namespace

Drupal\Tests\contact_storage\Functional

Code

public function testMaximumSubmissionLimit() {

  // Create a new contact form with a maximum submission limit of 2.
  $this
    ->addContactForm('test_id_3', 'test_label', 'simpletest@example.com', FALSE, [
    'contact_storage_maximum_submissions_user' => 2,
  ]);
  $this
    ->assertText('Contact form test_label has been added.');

  // Sends 2 messages with "Send yourself a copy" option activated, shouldn't
  // reach the limit even if 2 messages are sent twice.
  $this
    ->drupalGet('contact/test_id_3');
  $edit = [
    'subject[0][value]' => 'Test subject',
    'message[0][value]' => 'Test message',
    'copy' => 'checked',
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Send message'));
  $this
    ->assertText('Your message has been sent.');
  $this
    ->drupalGet('contact/test_id_3');
  $this
    ->drupalPostForm(NULL, $edit, t('Send message'));
  $this
    ->assertText('Your message has been sent.');

  // Try accessing the form after the limit has been reached.
  $this
    ->drupalGet('contact/test_id_3');
  $this
    ->assertText('You have reached the maximum submission limit of 2 for this form.');
}