You are here

public function SimplenewsPersonalizationFormsTest::testSynchronizeRegisterSubscribe in Simplenews 3.x

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

Register then subscribe: 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);

  // Subscribe anonymous with verification disabled.
  $this
    ->config('simplenews.settings')
    ->set('subscription.skip_verification', TRUE)
    ->save();
  $new_value = $this
    ->randomString(20);
  $this
    ->subscribe([], $email, [
    'field_shared[0][value]' => $new_value,
  ]);

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