EntityTypeAnalyzerKernelTest.php in Mailhandler 8
File
tests/src/Kernel/EntityTypeAnalyzerKernelTest.php
View source
<?php
namespace Drupal\Tests\mailhandler\Kernel;
use Drupal\inmail\DefaultAnalyzerResult;
use Drupal\inmail\Entity\AnalyzerConfig;
use Drupal\inmail\ProcessorResult;
use Drupal\node\Entity\NodeType;
class EntityTypeAnalyzerKernelTest extends AnalyzerTestBase {
public function setUp() {
parent::setUp();
}
public function testEntityTypeAnalyzer() {
$raw_message = $this
->getFileContent('eml/Plain.eml');
$message = $this->parser
->parseMessage($raw_message);
$result = new ProcessorResult();
$entity_type_analyzer = AnalyzerConfig::load('entity_type');
$analyzer = $this->analyzerManager
->createInstance($entity_type_analyzer
->getPluginId(), $entity_type_analyzer
->getConfiguration());
$analyzer
->analyze($message, $result);
$result = $result
->getAnalyzerResult();
$this
->assertEquals('Google Summer of Code 2016', $result
->getSubject());
$this
->assertEquals('node', $result
->getContext('entity_type')
->getContextValue()['entity_type']);
$this
->assertEquals(NULL, $result
->getContext('entity_type')
->getContextValue()['bundle']);
$page = NodeType::create([
'type' => 'page',
'name' => 'Page',
]);
$page
->save();
$result = new ProcessorResult();
$analyzer
->analyze($message, $result);
$result = $result
->getAnalyzerResult();
$this
->assertEquals('page', $result
->getContext('entity_type')
->getContextValue()['bundle']);
$raw_message = str_replace('[node][page]', '[user][#id]', $raw_message);
$message = $this->parser
->parseMessage($raw_message);
$result = new ProcessorResult();
$analyzer
->analyze($message, $result);
$result = $result
->getAnalyzerResult();
$this
->assertEquals('user', $result
->getContext('entity_type')
->getContextValue()['entity_type']);
$this
->assertEquals(NULL, $result
->getContext('entity_type')
->getContextValue()['bundle']);
$this
->assertEquals('[#id] Google Summer of Code 2016', $result
->getSubject());
}
}