You are here

public function MailhandlerNodeTest::setUp in Mailhandler 8

Overrides KernelTestBase::setUp

File

tests/src/Kernel/MailhandlerNodeTest.php, line 38

Class

MailhandlerNodeTest
Tests the Node handler plugin.

Namespace

Drupal\Tests\mailhandler\Kernel

Code

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

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

  // Create a new role.
  $role = Role::create([
    'id' => 'mailhandler',
    'label' => 'Mailhandler',
  ]);
  $role
    ->grantPermission('create blog content');
  $role
    ->grantPermission('create page content');
  $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;
  $this->processor = \Drupal::service('inmail.processor');
  $this->parser = \Drupal::service('inmail.mime_parser');
  $this->deliverer = DelivererConfig::create([
    'id' => 'test',
  ]);
}