SenderAnalyzerKernelTest.php in Mailhandler 8
File
tests/src/Kernel/SenderAnalyzerKernelTest.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\User;
class SenderAnalyzerKernelTest extends AnalyzerTestBase {
public function setUp() {
parent::setUp();
}
public function testSenderAnalyzer() {
$raw_message = $this
->getFileContent('eml/Plain.eml');
$message = $this->parser
->parseMessage($raw_message);
$result = new ProcessorResult();
$sender_analyzer = AnalyzerConfig::load('sender');
$analyzer = $this->analyzerManager
->createInstance($sender_analyzer
->getPluginId(), $sender_analyzer
->getConfiguration());
$analyzer
->analyze($message, $result);
$result = $result
->getAnalyzerResult();
$this
->assertEquals('milos@example.com', $result
->getSender());
$this
->assertFalse($result
->isUserAuthenticated());
$this
->assertNull($result
->getAccount());
$user = User::create([
'mail' => 'milos@example.com',
'name' => 'Milos',
]);
$user
->save();
$result = new ProcessorResult();
$analyzer
->analyze($message, $result);
$result = $result
->getAnalyzerResult();
$this
->assertEquals('milos@example.com', $result
->getSender());
$this
->assertTrue($result
->isUserAuthenticated());
$this
->assertEquals($user
->id(), $result
->getAccount()
->id());
}
}