You are here

public function HoneypotFormTest::testProtectContactForm in Honeypot 8

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

Test protection on the Contact form.

File

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

Class

HoneypotFormTest
Test Honeypot spam protection functionality.

Namespace

Drupal\Tests\honeypot\Functional

Code

public function testProtectContactForm() {
  $this
    ->drupalLogin($this->adminUser);

  // Disable 'protect_all_forms'.
  \Drupal::configFactory()
    ->getEditable('honeypot.settings')
    ->set('protect_all_forms', FALSE)
    ->save();

  // Create a Website feedback contact form.
  $feedback_form = ContactForm::create([
    'id' => 'feedback',
    'label' => 'Website feedback',
    'recipients' => [],
    'reply' => '',
    'weight' => 0,
  ]);
  $feedback_form
    ->save();
  $contact_settings = \Drupal::configFactory()
    ->getEditable('contact.settings');
  $contact_settings
    ->set('default_form', 'feedback')
    ->save();

  // Submit the admin form so we can verify the right forms are displayed.
  $this
    ->drupalPostForm('admin/config/content/honeypot', [
    'form_settings[contact_message_feedback_form]' => TRUE,
  ], $this
    ->t('Save configuration'));
  $this
    ->drupalLogin($this->webUser);
  $this
    ->drupalGet('contact/feedback');
  $this
    ->assertSession()
    ->fieldExists('url');
}