SwiftMailerTestBase.php in Swift Mailer 8.2
File
tests/src/Functional/SwiftMailerTestBase.php
View source
<?php
namespace Drupal\Tests\swiftmailer\Functional;
use Drupal\Core\Test\AssertMailTrait;
use Drupal\swiftmailer_test\SwiftMailerDrupalStateLogger;
use Drupal\Tests\BrowserTestBase;
abstract class SwiftMailerTestBase extends BrowserTestBase {
use AssertMailTrait;
protected $defaultTheme = 'stark';
public static $modules = [
'swiftmailer_test',
'swiftmailer',
'mailsystem',
];
protected $logger = NULL;
protected function setUp() {
parent::setUp();
$this
->config('mailsystem.settings')
->set('defaults', [
'formatter' => 'swiftmailer',
'sender' => 'test_mail_collector',
])
->clear('modules.swiftmailer.none')
->save();
$this->logger = new SwiftMailerDrupalStateLogger();
}
protected function assertBodyContains($value) {
$captured_emails = $this->container
->get('state')
->get('system.test_mail_collector') ?: [];
$email = end($captured_emails);
$this
->assertStringContainsString($value, (string) $email['body']);
}
protected function assertSubject($value) {
$captured_emails = $this->container
->get('state')
->get('system.test_mail_collector') ?: [];
$email = end($captured_emails);
$this
->assertEquals($value, (string) $email['subject']);
}
protected function enablePlain() {
$this
->config('swiftmailer.message')
->set('content_type', SWIFTMAILER_FORMAT_PLAIN)
->save();
}
}