public function MailUiTest::testLogging in Maillog / Mail Developer 8
Tests logging mail with maillog module.
File
- tests/
src/ Functional/ MailUiTest.php, line 49
Class
- MailUiTest
- Tests the maillog plugin user interface.
Namespace
Drupal\Tests\maillog\FunctionalCode
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.';
// Send the prepared email.
$sender = new Maillog();
$sender
->mail($mail);
// Create a user with valid permissions and go to the maillog overview page.
$permissions = [
'administer maillog',
'view maillog',
];
$this
->drupalLogin($this
->drupalCreateUser($permissions));
$this
->drupalGet('admin/reports/maillog');
$this
->assertSession()
->statusCodeEquals(200);
// Assert some values and click the subject link.
$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.');
// Test clear log.
$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.');
}