You are here

public function SimplenewsPersonalizationFormsTest::testSynchronizeRegisterSubscribe in Simplenews 8

Register then subscribe: require login, fields updated.

File

src/Tests/SimplenewsPersonalizationFormsTest.php, line 67

Class

SimplenewsPersonalizationFormsTest
Tests crucial aspects of Subscriber fieldability and User field sync.

Namespace

Drupal\simplenews\Tests

Code

public function testSynchronizeRegisterSubscribe() {
  $email = $this
    ->randomEmail();

  // Register.
  $uid = $this
    ->registerUser($email, array(
    'field_shared[0][value]' => $this
      ->randomString(10),
  ));
  $user = User::load($uid);

  // Attempt subscribe and assert login message.
  $this
    ->subscribe('default', $email);
  $this
    ->assertRaw(t('There is an account registered for the e-mail address %mail. Please log in to manage your newsletter subscriptions', array(
    '%mail' => $email,
  )));

  // Login.
  $this
    ->resetPassLogin($user);

  // Subscribe.
  $new_value = $this
    ->randomString(20);
  $this
    ->subscribe('default', NULL, array(
    'field_shared[0][value]' => $new_value,
  ), t('Update'));

  // Assert fields are updated.
  $this
    ->drupalGet("user/{$uid}");
  $this
    ->assertText(Html::escape($new_value));
}