You are here

function RegistrationStandardTestCase::testHostEntityBroadcastForm in Entity Registration 8.2

Same name in this branch
  1. 8.2 tests/registration.test \RegistrationStandardTestCase::testHostEntityBroadcastForm()
  2. 8.2 src/RegistrationStandardTestCase.php \Drupal\registration\RegistrationStandardTestCase::testHostEntityBroadcastForm()

Tests email broadcast functionality.

Generates registrations for a host entity, and confirms that emails were sent out to all registrants.

File

src/RegistrationStandardTestCase.php, line 133

Class

RegistrationStandardTestCase
Creates a registration type Create node entity type ensure registration type exists

Namespace

Drupal\registration

Code

function testHostEntityBroadcastForm() {
  $permissions = array(
    'administer ' . $this->registration_type_name . ' registration',
  );
  $this
    ->checkPermissions($permissions, TRUE);
  $user = $this
    ->drupalCreateUser($permissions);
  $this
    ->drupalLogin($user);

  // Create registration, Drupal user.
  $user_a = $this
    ->drupalCreateUser($permissions);
  $this
    ->createRegistration(array(
    'author_uid' => $user->uid,
    'registrant_id' => $user_a->uid,
  ));

  // Create registration, anonymous user.
  $anonymous_mail = $this
    ->randomName() . '@example.com';
  $this
    ->createRegistration(array(
    'author_uid' => $user->uid,
    'anon_mail' => $anonymous_mail,
  ));

  // Display form.
  $this
    ->drupalGet($this->host_entity_path . '/registrations/broadcast');
  $this
    ->assertResponse(200, t('User can access host entity broadcast settings page.'), 'Registration');
  $this
    ->assertFieldByName('subject');
  $this
    ->assertFieldByName('message');

  // Submit form.
  $edit = array(
    'subject' => $this
      ->randomName(16),
    'message' => $this
      ->randomString(),
  );
  $this
    ->drupalPost($this->host_entity_path . '/registrations/broadcast', $edit, t('Send'));
  $this
    ->assertText(t('Registration broadcast sent to @count registrants.', array(
    '@count' => 2,
  )), t('Host entity broadcast form submitted.'), 'Registration');

  // Verify emails were sent.
  $mails = $this
    ->drupalGetMails();
  $address_sent = array();
  foreach ($mails as $mail) {
    $address_sent[] = $mail['to'];
  }
  $this
    ->assertTrue(in_array($user_a->mail, $address_sent), t('Registration email broadcast to authenticated account.'), 'Registration');
  $this
    ->assertTrue(in_array($anonymous_mail, $address_sent), t('Registration email broadcast to anonymous person.'), 'Registration');
}