View source
<?php
namespace Drupal\Tests\maillog\Functional;
use Drupal\maillog\Plugin\Mail\Maillog;
use Drupal\Tests\BrowserTestBase;
class MailUiTest extends BrowserTestBase {
public static $modules = [
'maillog',
'user',
'system',
'views',
'contact',
];
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
$this
->config('system.mail')
->set('interface.default', 'maillog')
->save();
$this
->config('system.site')
->set('mail', 'simpletest@example.com')
->save();
$this
->config('maillog.settings')
->set('send', FALSE)
->save();
}
public function testLogging() {
$mail = \Drupal::service('plugin.manager.mail')
->mail('maillog', 'ui_test', 'test@example.com', \Drupal::languageManager()
->getCurrentLanguage(), [], 'me@example.com', FALSE);
$mail['subject'] = 'This is a test subject.';
$mail['body'] = 'This message is a test email body.';
$sender = new Maillog();
$sender
->mail($mail);
$permissions = [
'administer maillog',
'view maillog',
];
$this
->drupalLogin($this
->drupalCreateUser($permissions));
$this
->drupalGet('admin/reports/maillog');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertText('simpletest@example.com');
$this
->assertText('test@example.com');
$this
->clickLink('This is a test subject.');
$this
->assertText('This message is a test email body.');
$this
->drupalGet('admin/config/development/maillog');
$this
->assertSession()
->statusCodeEquals(200);
$this
->drupalPostForm(NULL, [], 'Clear all maillog entries');
$this
->assertSession()
->statusCodeEquals(200);
$this
->drupalPostForm(NULL, [], 'Clear');
$this
->assertSession()
->statusCodeEquals(200);
$this
->drupalGet('admin/reports/maillog');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertNoText('simpletest@example.com');
$this
->assertText('There are no mail logs in the database.');
}
public function testNotice() {
$recipient = $this
->drupalCreateUser();
$permissions = [
'access user contact forms',
'access user profiles',
'administer maillog',
];
$this
->drupalLogin($this
->drupalCreateUser($permissions));
$edit = [
'subject[0][value]' => 'Test Message',
'message[0][value]' => 'This is a test.',
];
$this
->drupalPostForm('user/' . $recipient
->id() . '/contact', $edit, 'Send message');
$this
->clickLink('here');
$this
->assertResponse(200);
$this
->assertTitle('Maillog Settings | Drupal');
}
public function testVerboseOutput() {
$account = $this
->drupalCreateUser();
$this
->drupalLogin($this
->drupalCreateUser([
'access user contact forms',
'access user profiles',
'view maillog',
]));
$this
->drupalGet('user/' . $account
->id() . '/contact');
$this
->assertSession()
->statusCodeEquals(200);
$edit = [
'subject[0][value]' => 'Test Message',
'message[0][value]' => 'This is a test.',
];
$this
->drupalPostForm(NULL, $edit, 'Send message');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertText('A mail has been sent:');
$this
->assertRaw('[To] => ' . $account
->getAccountName() . '@example.com');
$this
->assertRaw('[Header] => Array');
$this
->assertRaw('[X-Mailer] => Drupal');
$this
->assertRaw('[Content-Type] => text/plain; charset=UTF-8; format=flowed; delsp=yes');
$this
->assertRaw('[Body] => Hello ' . $account
->getAccountName());
$this
->config('maillog.settings')
->set('verbose', FALSE)
->save();
$this
->drupalGet('user/' . $account
->id() . '/contact');
$this
->assertSession()
->statusCodeEquals(200);
$edit = [
'subject[0][value]' => 'Test Message',
'message[0][value]' => 'This is a test.',
];
$this
->drupalPostForm(NULL, $edit, 'Send message');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertNoText('A mail has been sent:');
$this
->assertNoRaw('[To] => ' . $account
->getAccountName() . '@example.com');
$this
->assertNoRaw('[Header] => Array');
$this
->config('maillog.settings')
->set('verbose', TRUE)
->save();
$this
->drupalLogin($this
->drupalCreateUser([
'access user contact forms',
'access user profiles',
]));
$this
->drupalGet('user/' . $account
->id() . '/contact');
$this
->assertSession()
->statusCodeEquals(200);
$edit = [
'subject[0][value]' => 'Test Message',
'message[0][value]' => 'This is a test.',
];
$this
->drupalPostForm(NULL, $edit, 'Send message');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertNoText('A mail has been sent:');
$this
->assertNoRaw('[To] => ' . $account
->getAccountName() . '@example.com');
$this
->assertNoRaw('[Header] => Array');
}
}