You are here

public function SwiftMailerAlterTest::testPlainTextConfigurationSetting in Swift Mailer 8

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/SwiftMailerAlterTest.php \Drupal\Tests\swiftmailer\Functional\SwiftMailerAlterTest::testPlainTextConfigurationSetting()

File

tests/src/Functional/SwiftMailerAlterTest.php, line 123

Class

SwiftMailerAlterTest
@group swiftmailer

Namespace

Drupal\Tests\swiftmailer\Functional

Code

public function testPlainTextConfigurationSetting() {
  \Drupal::configFactory()
    ->getEditable('swiftmailer.message')
    ->set('convert_mode', TRUE)
    ->save();
  $plugin = Drupal\swiftmailer\Plugin\Mail\SwiftMailer::create(\Drupal::getContainer(), [], NULL, NULL);

  // Empty plain text, generate from html.
  $message = [
    'module' => 'swiftmailer_test',
    'key' => 'swiftmailer_test_1',
    'headers' => [
      'Content-Type' => SWIFTMAILER_FORMAT_HTML,
    ],
    'subject' => 'Subject',
    'body' => [
      Drupal\Core\Render\Markup::create('<strong>Hello World</strong>'),
    ],
  ];
  $message = $plugin
    ->format($message);
  $this
    ->assertContains('<strong>Hello World</strong>', (string) $message['body']);
  $this
    ->assertContains('HELLO WORLD', $message['plain']);

  // Keep original plain text version.
  $message = [
    'module' => 'swiftmailer_test',
    'key' => 'swiftmailer_test_1',
    'headers' => [
      'Content-Type' => SWIFTMAILER_FORMAT_HTML,
    ],
    'subject' => 'Subject',
    'plain' => 'Original Plain Text Version',
    'body' => [
      Drupal\Core\Render\Markup::create('<strong>Hello World</strong>'),
    ],
  ];
  $message = $plugin
    ->format($message);
  $this
    ->assertContains('<strong>Hello World</strong>', (string) $message['body']);
  $this
    ->assertContains('Original Plain Text Version', $message['plain']);
}