You are here

protected function MassContactFormTest::setUp in Mass Contact 8

Overrides MassContactTestBase::setUp

File

tests/src/Functional/Form/MassContactFormTest.php, line 52

Class

MassContactFormTest
Tests for the Mass Contact form.

Namespace

Drupal\Tests\mass_contact\Functional\Form

Code

protected function setUp() {
  parent::setUp();
  $this->massContactUser = $this
    ->createUser([
    'mass contact send messages',
    'mass contact view archived messages',
  ]);
  $role_id = $this->massContactUser
    ->getRoles(TRUE);
  $this->massContactRole = Role::load(reset($role_id));
  foreach (range(1, 6) as $i) {
    $this->categories[$i] = $this
      ->createCategory();
  }

  // Add 410 users.
  $this->recipientRole = Role::load($this
    ->createRole([]));
  foreach (range(1, 410) as $i) {
    $account = $this
      ->createUser();
    if ($i == 5) {

      // Block the 5th one.
      $account
        ->block();
    }
    if ($i == 20 || $i == 50) {

      // Opt out of mass contacts for the 20th and 50th users.
      $account->mass_contact_opt_out->value = 1;
    }
    $account
      ->addRole($this->recipientRole
      ->id());
    $account
      ->save();
  }
}