public function ContactEmailsRecipientReferenceTest::testSendToReferencedField in Contact Emails 8
Test referenced field functionality to email address.
Throws
\Exception
File
- src/
Tests/ ContactEmailsRecipientReferenceTest.php, line 33
Class
- ContactEmailsRecipientReferenceTest
- Tests contact emails recipients.
Namespace
Drupal\contact_emails\TestsCode
public function testSendToReferencedField() {
$this
->addContactFormWithEmailFieldForReferencing();
// Add the email.
$params = [
'subject[0][value]' => 'Contact Emails Test Form Subject',
'message[0][value]' => 'Contact Emails Test Form Body',
'recipient_type[0][value]' => 'reference',
'recipient_reference[0][value]' => 'field_reference.contact_message.contact_reference_test_form.field_email_reference',
'reply_to_type[0][value]' => 'default',
'status[value]' => TRUE,
];
$this
->drupalPostForm('/admin/structure/contact/manage/contact_emails_test_form/emails/add', $params, t('Save'));
// Open the contact form on the front-end.
$this
->drupalGet('/contact/contact_emails_test_form');
// Get the reference options.
$elements = $this
->xpath('//select[@name="field_reference"]');
$options = $elements[0]
->findAll('xpath', '//option');
$last_option = end($options);
// Submit the 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_reference' => $last_option
->getValue(),
];
$this
->drupalPostForm(NULL, $params, t('Send message'));
// Assert that the message to is the email of the currently logged in user.
$this
->assertText('Message-to:email-via-reference@test.com', 'Message to set successfully.');
}