You are here

public function SubscribersTest::testEntityAccess in Message Subscribe 8

Assert subscribers list is entity-access aware.

File

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

Class

SubscribersTest
Test getting subscribes from context.

Namespace

Drupal\Tests\message_subscribe\Kernel

Code

public function testEntityAccess() {

  // Make sure we are notifying ourselves for this test.
  \Drupal::configFactory()
    ->getEditable('message_subscribe.settings')
    ->set('notify_own_actions', TRUE)
    ->save();
  $message = Message::create([
    'template' => $this->template
      ->id(),
  ]);
  $node = $this->nodes[0];
  $node
    ->setUnpublished();
  $node
    ->save();

  // Add permission to view own unpublished content.
  user_role_change_permissions(AccountInterface::AUTHENTICATED_ROLE, [
    'view own unpublished content' => TRUE,
  ]);

  // Set the node to be unpublished.
  $user1 = $this->users[1];
  $user2 = $this->users[2];
  $subscribe_options['entity access'] = TRUE;
  $uids = $this->messageSubscribers
    ->getSubscribers($node, $message, $subscribe_options);
  $this
    ->assertEquals(array_keys($uids), [
    $user1
      ->id(),
  ], 'Only user with access to node returned for subscribers list.');
  $subscribe_options['entity access'] = FALSE;
  $uids = $this->messageSubscribers
    ->getSubscribers($node, $message, $subscribe_options);
  $this
    ->assertEquals(array_keys($uids), [
    $user1
      ->id(),
    $user2
      ->id(),
  ], 'All users (even without access) returned for subscribers list.');
}