$this->
drupalLogout();
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID,
['access site-wide contact form'
]);
// Test the auto-reply for form 'foo'.
$email =
$this->
randomMachineName(32
) . '@example.com';
$subject =
$this->
randomMachineName(64
);
$this->
submitContact($this->
randomMachineName(16
),
$email,
$subject, 'foo',
$this->
randomString(128
));
// We are testing the auto-reply, so there should be one email going to the sender.
$captured_emails =
$this->
getMails(['id' => 'contact_page_autoreply', 'to' =>
$email]);
$this->
assertCount(1,
$captured_emails);
$this->
assertEquals(trim(MailFormatHelper::
htmlToText($foo_autoreply)),
trim($captured_emails[0
]['body'
]));
// Test the auto-reply for form 'bar'.
$email =
$this->
randomMachineName(32
) . '@example.com';
$this->
submitContact($this->
randomMachineName(16
),
$email,
$this->
randomString(64
), 'bar',
$this->
randomString(128
));
// Auto-reply for form 'bar' should result in one auto-reply email to the sender.
$captured_emails =
$this->
getMails(['id' => 'contact_page_autoreply', 'to' =>
$email]);
$this->
assertCount(1,
$captured_emails);
$this->
assertEquals(trim(MailFormatHelper::
htmlToText($bar_autoreply)),
trim($captured_emails[0
]['body'
]));
// Verify that no auto-reply is sent when the auto-reply field is left blank.