You are here

public function RerouteEmailTestBase::configureRerouteEmail in Reroute Email 2.x

Same name and namespace in other branches
  1. 8 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 $allowlisted: (optional) The email addresses from the allowed list.

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).

8 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.
DomainAllowlistedTest::testAllowedByDomain in tests/src/Functional/DomainAllowlistedTest.php
Basic tests for the domain addresses from the allowed list.
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, $allowlisted = NULL, $description = NULL, $message = NULL, $mailkeys = NULL) {
  $current_values = $install_values = [
    REROUTE_EMAIL_ENABLE => FALSE,
    REROUTE_EMAIL_ADDRESS => '',
    REROUTE_EMAIL_ALLOWLIST => '',
    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_ALLOWLIST => NULL === $allowlisted ? $current_values[REROUTE_EMAIL_ALLOWLIST] : $allowlisted,
    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
    ->drupalGet('admin/config/development/reroute_email');
  $this
    ->submitForm($post, t('Save configuration'));
  $this
    ->assertSession()
    ->pageTextContains(t('The configuration options have been saved.'));

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