You are here

public function RerouteEmailTestBase::configureRerouteEmail in Reroute Email 8

Same name and namespace in other branches
  1. 2.x tests/src/Functional/RerouteEmailTestBase.php \Drupal\Tests\reroute_email\Functional\RerouteEmailTestBase::configureRerouteEmail()

Helper function to configure Reroute Email Settings.

Parameters

bool $enable: (optional) Set to TRUE to enable email Rerouting.

string $addresses: (optional) The email addresses to which emails should be rerouted.

string $whitelisted: (optional) The whitelisted email addresses.

bool $description: (optional) Set to TRUE to show rerouting description.

bool $message: (optional) Set to TRUE to display a status message after rerouting.

string $mailkeys: (optional) A list of modules or mail keys should be rerouted, defaults to empty string (all outgoing emails are rerouted).

7 calls to RerouteEmailTestBase::configureRerouteEmail()
ContactTest::testBasicNotification in tests/src/Functional/ContactTest.php
Basic tests of email rerouting for emails sent through the Contact forms.
DefaultAddressesTest::testRerouteDefaultAddress in tests/src/Functional/DefaultAddressesTest.php
Test reroute email address is set to site_mail, sendmail_from or empty.
DomainWhitelistedTest::testDomainWhitelistedEmail in tests/src/Functional/DomainWhitelistedTest.php
Basic tests for the domain whitelisted addresses.
MailKeysTest::testMailKeysFilter in tests/src/Functional/MailKeysTest.php
Test Reroute Email with mail keys filter.
MultipleRecipientsTest::testMultipleRecipients in tests/src/Functional/MultipleRecipientsTest.php
Test Reroute Email with multiple recipients.

... See full list

File

tests/src/Functional/RerouteEmailTestBase.php, line 110

Class

RerouteEmailTestBase
Base test class for Reroute Email test cases.

Namespace

Drupal\Tests\reroute_email\Functional

Code

public function configureRerouteEmail($enable = NULL, $addresses = NULL, $whitelisted = NULL, $description = NULL, $message = NULL, $mailkeys = NULL) {
  $current_values = $install_values = [
    REROUTE_EMAIL_ENABLE => FALSE,
    REROUTE_EMAIL_ADDRESS => '',
    REROUTE_EMAIL_WHITELIST => '',
    REROUTE_EMAIL_DESCRIPTION => TRUE,
    REROUTE_EMAIL_MESSAGE => TRUE,
    REROUTE_EMAIL_MAILKEYS => '',
  ];
  foreach ($install_values as $key => $value) {
    $current_values[$key] = NULL === $this->rerouteConfig
      ->get($key) ? $value : $this->rerouteConfig
      ->get($key);
  }

  // Configure to Reroute Email settings form.
  $post = [
    REROUTE_EMAIL_ENABLE => NULL === $enable ? $current_values[REROUTE_EMAIL_ENABLE] : $enable,
    REROUTE_EMAIL_ADDRESS => NULL === $addresses ? $current_values[REROUTE_EMAIL_ADDRESS] : $addresses,
    REROUTE_EMAIL_WHITELIST => NULL === $whitelisted ? $current_values[REROUTE_EMAIL_WHITELIST] : $whitelisted,
    REROUTE_EMAIL_DESCRIPTION => NULL === $description ? $current_values[REROUTE_EMAIL_DESCRIPTION] : $description,
    REROUTE_EMAIL_MESSAGE => NULL === $message ? $current_values[REROUTE_EMAIL_MESSAGE] : $message,
    REROUTE_EMAIL_MAILKEYS => NULL === $mailkeys ? $current_values[REROUTE_EMAIL_MAILKEYS] : $mailkeys,
  ];

  // Submit Reroute Email Settings form and check if it was successful.
  $this
    ->drupalPostForm('admin/config/development/reroute_email', $post, t('Save configuration'));
  $this
    ->assertText(t('The configuration options have been saved.'));

  // Rebuild config values after form submit.
  $this->rerouteConfig = $this
    ->config('reroute_email.settings');
}