You are here

protected function OptOutTest::setUp in Mass Contact 8

Overrides MassContactTestBase::setUp

File

tests/src/Kernel/OptOutTest.php, line 63

Class

OptOutTest
Kernel tests for the opt-out service.

Namespace

Drupal\Tests\mass_contact\Kernel

Code

protected function setUp() {
  parent::setUp();
  $this
    ->installSchema('system', [
    'sequences',
  ]);
  $this
    ->installEntitySchema('user');
  $this
    ->installConfig('mass_contact');

  // Add 3 categories.
  foreach (range(1, 3) as $i) {
    $this->categories[$i] = $this
      ->createCategory();
  }

  // Add 20 users.
  foreach (range(1, 20) as $i) {
    $account = $this
      ->createUser();

    // Users 2, 3, and 5 opt out globally.
    if (in_array($i, [
      2,
      3,
      5,
    ])) {
      $account->{MassContactInterface::OPT_OUT_FIELD_ID} = 1;
      $account
        ->save();
      $this->globalOptOut[$account
        ->id()] = $account;
    }
    elseif (in_array($i, [
      4,
      19,
    ])) {
      $account->{MassContactInterface::OPT_OUT_FIELD_ID} = $this->categories[1]
        ->id();
      $account
        ->save();
      $this->categoryOptOut1[$account
        ->id()] = $account;
    }
    elseif (in_array($i, [
      8,
      16,
    ])) {
      $account->{MassContactInterface::OPT_OUT_FIELD_ID} = $this->categories[2]
        ->id();
      $account
        ->save();
      $this->categoryOptOut2[$account
        ->id()] = $account;
    }
    else {
      $this->recipients[$account
        ->id()] = $account;
    }
  }
}