You are here

public function SubscribersTest::testGetSubscribersExcludeSelf in Message Subscribe 8

Testing the exclusion of the entity author from the subscribers lists.

File

tests/src/Kernel/SubscribersTest.php, line 201

Class

SubscribersTest
Test getting subscribes from context.

Namespace

Drupal\Tests\message_subscribe\Kernel

Code

public function testGetSubscribersExcludeSelf() {

  // Test the affect of the variable when set to FALSE (do not notify self).
  \Drupal::configFactory()
    ->getEditable('message_subscribe.settings')
    ->set('notify_own_actions', FALSE)
    ->save();
  $message = Message::create([
    'template' => $this->template
      ->id(),
    'uid' => $this->users[1],
  ]);
  $node = $this->nodes[0];
  $user1 = $this->users[1];
  $user2 = $this->users[2];
  $uids = $this->messageSubscribers
    ->getSubscribers($node, $message);

  // Assert subscribers data.
  $expected_uids = [
    $this->users[2]
      ->id() => new DeliveryCandidate([
      'subscribe_node',
      'subscribe_user',
    ], [], $this->users[2]
      ->id()),
  ];
  $this
    ->assertEquals($uids, $expected_uids, 'All subscribers except for the triggering user were fetched.');

  // Test the affect of the variable when set to TRUE (Notify self).
  \Drupal::configFactory()
    ->getEditable('message_subscribe.settings')
    ->set('notify_own_actions', TRUE)
    ->save();
  $uids = $this->messageSubscribers
    ->getSubscribers($node, $message);

  // Assert subscribers data.
  $expected_uids = [
    $this->users[1]
      ->id() => new DeliveryCandidate([
      'subscribe_node',
    ], [], $this->users[1]
      ->id()),
    $this->users[2]
      ->id() => new DeliveryCandidate([
      'subscribe_node',
      'subscribe_user',
    ], [], $this->users[2]
      ->id()),
  ];
  $this
    ->assertEquals($uids, $expected_uids, 'All subscribers including the triggering user were fetched.');
}