You are here

protected function ContactEmailsTestBase::addContactFormWithEmailFieldForReferencing in Contact Emails 8

Helper function to create additional contact form to test referencing.

Throws

\Exception

2 calls to ContactEmailsTestBase::addContactFormWithEmailFieldForReferencing()
ContactEmailsRecipientReferenceTest::testSendToReferencedField in src/Tests/ContactEmailsRecipientReferenceTest.php
Test referenced field functionality to email address.
ContactEmailsReplyToReferenceTest::testReplyToReferencedField in src/Tests/ContactEmailsReplyToReferenceTest.php
Test referenced field functionality reply-to email address.

File

src/ContactEmailsTestBase.php, line 104

Class

ContactEmailsTestBase
Base class for contact emails tests.

Namespace

Drupal\contact_emails

Code

protected function addContactFormWithEmailFieldForReferencing() {

  // Create a contact form.
  $params = [
    'label' => 'Contact Reference Test Form',
    'id' => 'contact_reference_test_form',
    'message' => 'Your message has been sent.',
    'recipients' => 'test@example.com',
    'contact_storage_submit_text' => 'Send message',
  ];
  $this
    ->drupalPostForm('admin/structure/contact/add', $params, t('Save'));

  // Add an email field to be referenced.
  $params = [
    'new_storage_type' => 'email',
    'label' => 'Email reference',
    'field_name' => 'email_reference',
  ];
  $this
    ->drupalPostForm('admin/structure/contact/manage/contact_reference_test_form/fields/add-field', $params, t('Save and continue'));

  // Save the default base field settings.
  $this
    ->drupalPostForm(NULL, [], t('Save field settings'));

  // Save the field settings.
  $this
    ->drupalPostForm(NULL, [], t('Save settings'));

  // Assert that the field exists.
  $this
    ->assertText('field_email_reference', 'Field email address exists.');

  // Add an email field to reference the new form's field.
  $params = [
    'new_storage_type' => 'entity_reference',
    'label' => 'Reference',
    'field_name' => 'reference',
  ];
  $this
    ->drupalPostForm('admin/structure/contact/manage/contact_emails_test_form/fields/add-field', $params, t('Save and continue'));

  // Save the default base field settings.
  $params = [
    'settings[target_type]' => 'contact_message',
  ];
  $this
    ->drupalPostForm(NULL, $params, t('Save field settings'));

  // Save the field settings.
  $params = [
    'settings[handler_settings][target_bundles][contact_reference_test_form]' => 'contact_reference_test_form',
  ];
  $this
    ->drupalPostForm(NULL, $params, t('Save settings'));

  // Assert that the field exists.
  $this
    ->assertText('field_reference', 'Field reference exists.');

  // Save the display settings to make the reference a simple select.
  $params = [
    'fields[field_reference][type]' => 'options_select',
  ];
  $this
    ->drupalPostForm('admin/structure/contact/manage/contact_emails_test_form/form-display', $params, t('Save'));

  // Submit the refernce contact form on the front-end of the website.
  $params = [
    'subject[0][value]' => 'Submission Test Form Subject',
    'message[0][value]' => 'Submission Test Form Body',
    'field_email_reference[0][value]' => 'email-via-reference@test.com',
  ];
  $this
    ->drupalPostForm('contact/contact_reference_test_form', $params, t('Send message'));

  // Assert that it says message has been sent.
  $this
    ->assertText('Your message has been sent.', 'Message sent successfully.');
}