You are here

RealMailTest.php in Swift Mailer 8.2

File

tests/src/Functional/RealMailTest.php
View source
<?php

namespace Drupal\Tests\swiftmailer\Functional;


/**
 * Tests with real mails generated by Drupal Core.
 *
 * @group swiftmailer
 */
class RealMailTest extends SwiftMailerTestBase {

  /**
   * {@inheritdoc}
   */
  public static $modules = [
    'user',
    'contact',
  ];

  /**
   * Tests user account messages.
   */
  public function testUser() {
    $account = $this
      ->drupalCreateUser();
    $this
      ->config('system.site')
      ->set('name', 'Rise & shine')
      ->save();

    // Password reset.
    $this
      ->config('user.mail')
      ->set('password_reset.subject', 'You forgot <again>')
      ->set('password_reset.body', '#Your password for [site:name] is a&<b<#')
      ->save();
    $this
      ->drupalGet('user/password');
    $this
      ->submitForm([
      'name' => $account
        ->getEmail(),
    ], 'Submit');
    $this
      ->assertSubject('You forgot ');

    // @todo Should be $this->assertSubject('You forgot <again>');
    $this
      ->assertBodyContains('#Your password for Rise &amp;amp; shine is a&amp;&lt;b&lt;#');

    // @todo Should be $this->assertBodyContains('#Your password for Rise &amp; shine is a&amp;&lt;b&lt;#');
    // Plain text.
    $this
      ->enablePlain();
    $this
      ->drupalGet('user/password');
    $this
      ->submitForm([
      'name' => $account
        ->getEmail(),
    ], 'Submit');
    $this
      ->assertBodyContains('#Your password for Rise &amp; shine is a&<b<#');

    // @todo Should be $this->assertBodyContains('#Your password for Rise & shine is a&<b<#');
    // Account notification message.
    $this
      ->config('user.settings')
      ->set('notify.status_activated', TRUE)
      ->save();
    $this
      ->config('user.mail')
      ->set('status_activated.body', '#ACTIVATED#')
      ->save();
    _user_mail_notify('status_activated', $account);
    $this
      ->assertBodyContains('#ACTIVATED#');
  }

  /**
   * Tests contact form messages.
   */
  public function testContact() {

    // Enable site-wide contact form.
    $edit = [
      'label' => 'Help & Support',
      'id' => 'contact',
      'message' => 'OK',
      'recipients' => 'admin@example.com',
      'reply' => '',
      'selected' => TRUE,
    ];
    $this
      ->drupalLogin($this
      ->createUser([
      'administer contact forms',
      'access site-wide contact form',
    ]));
    $this
      ->drupalGet('admin/structure/contact/add');
    $this
      ->submitForm($edit, 'Save');
    $edit = [
      'subject[0][value]' => 'Hello & greetings',
      'message[0][value]' => '#I am so happy <grin>#',
    ];

    // HTML.
    $this
      ->drupalGet('contact/contact');
    $this
      ->submitForm($edit, 'Send message');
    $this
      ->assertSubject('[Help & Support] Hello & greetings');
    $this
      ->assertBodyContains('#I am so happy &lt;grin&gt;#');

    // Plain text.
    $this
      ->enablePlain();
    $this
      ->drupalGet('contact/contact');
    $this
      ->submitForm($edit, 'Send message');
    $this
      ->assertBodyContains('#I am so happy <grin>#');
  }

}

Classes

Namesort descending Description
RealMailTest Tests with real mails generated by Drupal Core.