You are here

public function SimplenewsPersonalizationFormsTest::testSynchronizeRegisterSubscribe in Simplenews 8.2

Same name and namespace in other branches
  1. 3.x tests/src/Functional/SimplenewsPersonalizationFormsTest.php \Drupal\Tests\simplenews\Functional\SimplenewsPersonalizationFormsTest::testSynchronizeRegisterSubscribe()

Register then subscribe: require login, fields updated.

File

tests/src/Functional/SimplenewsPersonalizationFormsTest.php, line 68

Class

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

Namespace

Drupal\Tests\simplenews\Functional

Code

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

  // Register.
  $uid = $this
    ->registerUser($email, [
    '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', [
    '%mail' => $email,
  ]));

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

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

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