You are here

public function BodyAnalyzerKernelTest::testBodyAnalyzer in Mailhandler 8

Tests features of Body Analyzer plugin.

File

tests/src/Kernel/BodyAnalyzerKernelTest.php, line 26

Class

BodyAnalyzerKernelTest
Tests the Body Analyzer plugin.

Namespace

Drupal\Tests\mailhandler\Kernel

Code

public function testBodyAnalyzer() {
  $raw_message = $this
    ->getFileContent('eml/Plain.eml');

  /** @var \Drupal\inmail\MIME\MimeMessageInterface $message */
  $message = $this->parser
    ->parseMessage($raw_message);
  $result = new ProcessorResult();
  $body_analyzer = AnalyzerConfig::load('body');

  /** @var \Drupal\mailhandler\Plugin\inmail\Analyzer\BodyAnalyzer $analyzer */
  $analyzer = $this->analyzerManager
    ->createInstance($body_analyzer
    ->getPluginId(), $body_analyzer
    ->getConfiguration());
  $analyzer
    ->analyze($message, $result);
  $result = $result
    ->getAnalyzerResult();
  $expected_processed_body = <<<EOF
Hello, Drupal!<br />
<br />
--<br />
Milos Bovan<br />
milos@example.com
EOF;

  // New lines are replaced with <br /> HTML tag.
  $this
    ->assertEquals($expected_processed_body, $result
    ->getBody());
}