function ContactPersonalTest::testSendPersonalContactMessage in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/contact/src/Tests/ContactPersonalTest.php \Drupal\contact\Tests\ContactPersonalTest::testSendPersonalContactMessage()
Tests that mails for contact messages are correctly sent.
File
- core/
modules/ contact/ src/ Tests/ ContactPersonalTest.php, line 66 - Contains \Drupal\contact\Tests\ContactPersonalTest.
Class
- ContactPersonalTest
- Tests personal contact form functionality.
Namespace
Drupal\contact\TestsCode
function testSendPersonalContactMessage() {
// Ensure that the web user's email needs escaping.
$mail = $this->webUser
->getUsername() . '&escaped@example.com';
$this->webUser
->setEmail($mail)
->save();
$this
->drupalLogin($this->webUser);
$this
->drupalGet('user/' . $this->contactUser
->id() . '/contact');
$this
->assertEscaped($mail);
$message = $this
->submitPersonalContact($this->contactUser);
$mails = $this
->drupalGetMails();
$this
->assertEqual(1, count($mails));
$mail = $mails[0];
$this
->assertEqual($mail['to'], $this->contactUser
->getEmail());
$this
->assertEqual($mail['from'], $this
->config('system.site')
->get('mail'));
$this
->assertEqual($mail['reply-to'], $this->webUser
->getEmail());
$this
->assertEqual($mail['key'], 'user_mail');
$variables = array(
'@site-name' => $this
->config('system.site')
->get('name'),
'@subject' => $message['subject[0][value]'],
'@recipient-name' => $this->contactUser
->getUsername(),
);
$subject = PlainTextOutput::renderFromHtml(t('[@site-name] @subject', $variables));
$this
->assertEqual($mail['subject'], $subject, 'Subject is in sent message.');
$this
->assertTrue(strpos($mail['body'], 'Hello ' . $variables['@recipient-name']) !== FALSE, 'Recipient name is in sent message.');
$this
->assertTrue(strpos($mail['body'], $this->webUser
->getUsername()) !== FALSE, 'Sender name is in sent message.');
$this
->assertTrue(strpos($mail['body'], $message['message[0][value]']) !== FALSE, 'Message body is in sent message.');
// Check there was no problems raised during sending.
$this
->drupalLogout();
$this
->drupalLogin($this->adminUser);
// Verify that the correct watchdog message has been logged.
$this
->drupalGet('/admin/reports/dblog');
$placeholders = array(
'@sender_name' => $this->webUser->username,
'@sender_email' => $this->webUser
->getEmail(),
'@recipient_name' => $this->contactUser
->getUsername(),
);
$this
->assertRaw(SafeMarkup::format('@sender_name (@sender_email) sent @recipient_name an email.', $placeholders));
// Ensure an unescaped version of the email does not exist anywhere.
$this
->assertNoRaw($this->webUser
->getEmail());
}