You are here

public function ContextTest::testGetBasicContext in Message Subscribe 8

Test basic context method.

File

tests/src/Kernel/ContextTest.php, line 161

Class

ContextTest
Test getting context from entity.

Namespace

Drupal\Tests\message_subscribe\Kernel

Code

public function testGetBasicContext() {
  $node = $this->node;
  $group = $this->group;
  $comment = $this->comment;

  // Get context from comment.
  $context = $this->subscribers
    ->getBasicContext($comment);
  $expected_context = [];
  $expected_context['comment'] = array_combine([
    $comment
      ->id(),
  ], [
    $comment
      ->id(),
  ]);
  $expected_context['node'] = array_combine([
    $node
      ->id(),
    $group
      ->id(),
  ], [
    $node
      ->id(),
    $group
      ->id(),
  ]);
  $expected_context['user'] = array_combine([
    $comment
      ->getOwnerId(),
    $node
      ->getOwnerId(),
    $group
      ->getOwnerId(),
  ], [
    $comment
      ->getOwnerId(),
    $node
      ->getOwnerId(),
    $group
      ->getOwnerId(),
  ]);
  $expected_context['taxonomy_term'] = array_combine(array_keys($this->terms), array_keys($this->terms));
  $this
    ->assertEquals($expected_context['comment'], $context['comment'], 'Correct comment context from comment.');
  $this
    ->assertEquals($expected_context['node'], $context['node'], 'Correct node context from comment.');
  $this
    ->assertEquals($expected_context['taxonomy_term'], $context['taxonomy_term'], 'Correct taxonomy_term context from comment.');
  $this
    ->assertEquals($expected_context['user'], $context['user'], 'Correct user context from comment.');

  // Pass existing context.
  $subscribe_options = [
    'skip context' => TRUE,
  ];
  $original_context = [
    'node' => [
      1 => 1,
    ],
    'user' => [
      1 => 1,
    ],
  ];
  $context = $this->subscribers
    ->getBasicContext($comment, $subscribe_options, $original_context);
  $this
    ->assertEquals($original_context, $context, 'Correct context when skiping context.');
}