public function MultipleRecipientsTest::testMultipleRecipients in Reroute Email 2.x
Same name and namespace in other branches
- 8 tests/src/Functional/MultipleRecipientsTest.php \Drupal\Tests\reroute_email\Functional\MultipleRecipientsTest::testMultipleRecipients()
Test Reroute Email with multiple recipients.
File
- tests/
src/ Functional/ MultipleRecipientsTest.php, line 19
Class
- MultipleRecipientsTest
- Test Reroute Email with multiple recipients.
Namespace
Drupal\Tests\reroute_email\FunctionalCode
public function testMultipleRecipients() {
// Set multiple rerouting emails and a domain to the allowed list.
// Multiple commas and semicolons are added for validation tests.
$this
->configureRerouteEmail(TRUE, 'user1@example.com, user2@example.com,;;,,user@example.com', $this->allowlistedDomain);
// Make sure configured emails were set properly.
$reroute_to = 'user1@example.com,user2@example.com,user@example.com';
$this
->assertEquals($this->rerouteConfig
->get(REROUTE_EMAIL_ADDRESS), $reroute_to, 'Reroute email address was set.');
$this
->assertEquals($this->rerouteConfig
->get(REROUTE_EMAIL_ALLOWLIST), $this->allowlistedDomain, 'Value was set to the allowed list.');
// Submit a test email (should be rerouted).
$to = 'email@not-allowlisted.com, allowlisted@example.com';
$this
->drupalGet('admin/config/development/reroute_email/test');
$this
->submitForm([
'to' => $to,
], t('Send email'));
// Check if the email was rerouted properly.
$this
->assertEmailOriginallyTo($to);
$this
->assertMail('to', $reroute_to, new FormattableMarkup('Email was properly rerouted to the email address: @destination.', [
'@destination' => $reroute_to,
]));
// Submit a test email (should not be rerouted).
$to = 'allowlisted@example.com, user2@example.com, allowed@example.com';
$this
->drupalGet('admin/config/development/reroute_email/test');
$this
->submitForm([
'to' => $to,
], t('Send email'));
// Check if the email was not rerouted.
$this
->assertMail('to', $to, new FormattableMarkup('Email was properly sent the email addresses: @destination.', [
'@destination' => $to,
]));
}