public function MailhandlerNodeTest::testSignedMails in Mailhandler 8
Tests signed mail messages.
File
- tests/
src/ Kernel/ MailhandlerNodeTest.php, line 135
Class
- MailhandlerNodeTest
- Tests the Node handler plugin.
Namespace
Drupal\Tests\mailhandler\KernelCode
public function testSignedMails() {
$raw_signed_mail = $this
->getFileContent('eml/PGP_Signed_Inline.eml');
/** @var \Drupal\inmail\MIME\MimeMessageInterface $signed_mail */
$signed_mail = $this->parser
->parseMessage($raw_signed_mail);
// Add a public key to the user.
$this->user
->set('mailhandler_gpg_key', [
'public_key' => $this
->getFileContent('keys/public.key'),
]);
$this->user
->save();
// Update the handler configuration.
/** @var \Drupal\inmail\Entity\HandlerConfig $handler_config */
$handler_config = HandlerConfig::load('mailhandler_node');
$handler_config
->setConfiguration([
'content_type' => $this->contentType1
->id(),
])
->save();
// Process the mail.
$this->processor
->process('test_key', $raw_signed_mail, $this->deliverer);
// Assert there is a new node created.
$nodes = \Drupal::entityTypeManager()
->getStorage('node')
->loadMultiple();
/** @var \Drupal\node\NodeInterface $node */
$node = reset($nodes);
// @todo: Remove if condition after enabling GnuGP extension in tests.
// Assert the node field values.
if (extension_loaded('gnupg')) {
$this
->assertEquals($signed_mail
->getSubject(), $node
->getTitle());
$this
->assertEquals('Hello world!', $node
->get('body')->value);
$this
->assertEquals('full_html', $node
->get('body')->format);
$this
->assertEquals($this->user
->id(), $node
->getOwnerId());
$this
->assertEquals($this->contentType1
->id(), $node
->getType());
$this
->assertEquals(NODE_PUBLISHED, $node
->get('status')->value);
}
}