You are here

public function SubscribersTest::setUp in Message Subscribe 8

Same name in this branch
  1. 8 tests/src/Unit/SubscribersTest.php \Drupal\Tests\message_subscribe\Unit\SubscribersTest::setUp()
  2. 8 tests/src/Kernel/SubscribersTest.php \Drupal\Tests\message_subscribe\Kernel\SubscribersTest::setUp()

Overrides MessageSubscribeTestBase::setUp

File

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

Class

SubscribersTest
Test getting subscribes from context.

Namespace

Drupal\Tests\message_subscribe\Kernel

Code

public function setUp() {
  parent::setUp();
  $this
    ->installSchema('node', [
    'node_access',
  ]);
  $this->flagService = $this->container
    ->get('flag');
  $this->messageSubscribers = $this->container
    ->get('message_subscribe.subscribers');

  // Create node-type.
  $node_type = 'article';
  $flags = $this->flagService
    ->getAllFlags();
  $flag = $flags['subscribe_node'];
  $flag
    ->set('bundles', [
    $node_type,
  ]);
  $flag
    ->enable();
  $flag
    ->save();
  $flag = $flags['subscribe_user'];
  $flag
    ->enable();
  $flag
    ->save();
  $this->users[1] = $this
    ->createUser([
    'flag subscribe_node',
    'unflag subscribe_node',
    'flag subscribe_user',
    'unflag subscribe_user',
  ]);
  $this->users[2] = $this
    ->createUser([
    'flag subscribe_node',
    'unflag subscribe_node',
    'flag subscribe_user',
    'unflag subscribe_user',
  ]);

  // User 3 is blocked.
  $this->users[3] = $this
    ->createUser([
    'flag subscribe_node',
    'unflag subscribe_node',
    'flag subscribe_user',
    'unflag subscribe_user',
  ]);
  $this->users[3]
    ->block();
  $this->users[3]
    ->save();

  // Create node.
  $settings = [];
  $settings['type'] = $node_type;
  $settings['uid'] = $this->users[1];
  $this->nodes[0] = $this
    ->createNode($settings);
  $settings['uid'] = $this->users[2];
  $this->nodes[1] = $this
    ->createNode($settings);

  // User1, User2 and user_blocked flag node1.
  $this->flagService
    ->flag($flags['subscribe_node'], $this->nodes[0], $this->users[1]);
  $this->flagService
    ->flag($flags['subscribe_node'], $this->nodes[0], $this->users[2]);
  $this->flagService
    ->flag($flags['subscribe_node'], $this->nodes[0], $this->users[3]);
  $this->flagService
    ->flag($flags['subscribe_node'], $this->nodes[1], $this->users[3]);

  // User2 flags User1.
  $this->flagService
    ->flag($flags['subscribe_user'], $this->users[1], $this->users[2]);

  // Override default notifiers.
  \Drupal::configFactory()
    ->getEditable('message_subscribe.settings')
    ->set('default_notifiers', [])
    ->save();
}