You are here

public function SimplenewsSubscribeTest::testHashAuth in Simplenews 3.x

Tests access for a registered user to manage subscriptions with a hash.

File

tests/src/Functional/SimplenewsSubscribeTest.php, line 687

Class

SimplenewsSubscribeTest
Un/subscription of anonymous and authenticated users.

Namespace

Drupal\Tests\simplenews\Functional

Code

public function testHashAuth() {
  $user = $this
    ->drupalCreateUser([
    'subscribe to newsletters',
  ]);
  $mail = $user
    ->getEmail();
  $subscriber = Subscriber::loadByMail($mail, 'create');
  $subscriber
    ->save();
  $this
    ->drupalGet('newsletter/subscriptions');
  $this
    ->assertSession()
    ->addressEquals('/newsletter/validate');
  $this
    ->submitForm([
    'mail' => $mail,
  ], 'Submit');
  $this
    ->assertSession()
    ->pageTextContains("If {$mail} is subscribed, an email will be sent with a link to manage your subscriptions.");
  $this
    ->assertSession()
    ->addressEquals('');
  $validate_url = $this
    ->extractValidationLink($this
    ->getMail(0));
  $this
    ->drupalGet($validate_url);
  $this
    ->assertSession()
    ->pageTextContains("Subscriptions for {$mail}");
  $this
    ->submitForm([], 'Update');
  $this
    ->assertText(t('Your newsletter subscriptions have been updated.'));
}