PGPAnalyzerKernelTest.php in Mailhandler 8
File
tests/src/Kernel/PGPAnalyzerKernelTest.php
View source
<?php
namespace Drupal\Tests\mailhandler\Kernel;
use Drupal\inmail\DefaultAnalyzerResult;
use Drupal\inmail\Entity\AnalyzerConfig;
use Drupal\inmail\ProcessorResult;
use Drupal\user\Entity\Role;
use Drupal\user\Entity\User;
class PGPAnalyzerKernelTest extends AnalyzerTestBase {
public function setUp() {
parent::setUp();
}
public function testPGAnalyzer() {
$raw_signed_message = $this
->getFileContent('eml/PGP_Signed_Inline.eml');
$signed_mail = $this->parser
->parseMessage($raw_signed_message);
$role = Role::create([
'id' => 'mailhandler',
'label' => 'Mailhandler',
]);
$role
->grantPermission('create blog content');
$role
->grantPermission('create page content');
$role
->save();
$user = User::create([
'mail' => 'milos@example.com',
'name' => 'Milos',
]);
$user
->addRole($role
->id());
$user
->save();
$user
->set('mailhandler_gpg_key', [
'public_key' => $this
->getFileContent('keys/public.key'),
]);
$user
->save();
$result = new ProcessorResult();
$pgp_analyzer = AnalyzerConfig::load('pgp');
$analyzer = $this->analyzerManager
->createInstance($pgp_analyzer
->getPluginId(), $pgp_analyzer
->getConfiguration());
$analyzer
->analyze($signed_mail, $result);
$result = $result
->getAnalyzerResult();
if (extension_loaded('gnupg')) {
$this
->assertEquals($signed_mail
->getSubject(), $result
->getSubject());
$this
->assertEquals('Hello world!', $result
->getBody());
$this
->assertEquals($user, $result
->getAccount());
$this
->assertEquals('inline', $result
->getContext('pgp')
->getContextValue()['pgp_type']);
}
}
}