You are here

public function MailhandlerCommentTest::setUp in Mailhandler 8

Overrides KernelTestBase::setUp

File

mailhandler_comment/tests/src/Kernel/MailhandlerCommentTest.php, line 47

Class

MailhandlerCommentTest
Tests the Comment handler plugin.

Namespace

Drupal\Tests\mailhandler_comment\Kernel

Code

public function setUp() {
  parent::setUp();
  $this
    ->installEntitySchema('user');
  $this
    ->installEntitySchema('node');
  $this
    ->installEntitySchema('comment');
  $this
    ->installEntitySchema('inmail_handler');
  $this
    ->installSchema('comment', [
    'comment_entity_statistics',
  ]);
  $this
    ->installSchema('system', [
    'sequences',
  ]);
  $this
    ->installConfig([
    'inmail',
    'mailhandler',
    'mailhandler_comment',
    'node',
    'user',
    'comment',
  ]);

  // Create a sample node type.
  $this->blog = NodeType::create([
    'type' => 'blog',
    'name' => 'Blog',
  ]);
  $this->blog
    ->save();

  // Create a new role.
  $role = Role::create([
    'id' => 'mailhandler',
    'label' => 'Mailhandler',
  ]);
  $role
    ->grantPermission('post comments');
  $role
    ->save();

  // Create a new user with "Mailhandler" role.

  /** @var \Drupal\user\Entity\User $user */
  $user = User::create([
    'mail' => 'milos@example.com',
    'name' => 'Milos',
  ]);
  $user
    ->addRole($role
    ->id());
  $user
    ->save();
  $this->user = $user;

  // Create a sample node.
  $this->node = Node::create([
    'type' => $this->blog
      ->id(),
    'title' => 'Sample blog post',
  ]);
  $this->node
    ->save();

  // Add a comment field to "blog".
  $this
    ->addDefaultCommentField('node', 'blog');
  $this->processor = \Drupal::service('inmail.processor');
  $this->parser = \Drupal::service('inmail.mime_parser');
  $this->deliverer = DelivererConfig::create([
    'id' => 'test',
  ]);
}