You are here

protected function SimplenewsTestBase::subscribe in Simplenews 3.x

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

Visits and submits a newsletter management form.

Parameters

string|string[] $newsletter_ids: An ID or an array of IDs of the newsletters to subscribe to.

string $email: The email to subscribe.

array $edit: (optional) Additional form field values, keyed by form field names.

int $uid: (optional) User ID to update via newsletter tab.

10 calls to SimplenewsTestBase::subscribe()
SimplenewsPersonalizationFormsTest::testBlockedSubscribe in tests/src/Functional/SimplenewsPersonalizationFormsTest.php
Blocked account subscribes, display message.
SimplenewsPersonalizationFormsTest::testDeleteAccount in tests/src/Functional/SimplenewsPersonalizationFormsTest.php
Delete account, subscriptions deleted.
SimplenewsPersonalizationFormsTest::testDisableAccount in tests/src/Functional/SimplenewsPersonalizationFormsTest.php
Disable account, subscriptions inactive.
SimplenewsPersonalizationFormsTest::testSubscribeRequestPassword in tests/src/Functional/SimplenewsPersonalizationFormsTest.php
Subscribe, check no user is created.
SimplenewsPersonalizationFormsTest::testSynchronizeRegisterSubscribe in tests/src/Functional/SimplenewsPersonalizationFormsTest.php
Register then subscribe: fields updated.

... See full list

File

tests/src/Functional/SimplenewsTestBase.php, line 189

Class

SimplenewsTestBase
Base class for simplenews web tests.

Namespace

Drupal\Tests\simplenews\Functional

Code

protected function subscribe($newsletter_ids, $email = NULL, array $edit = [], $uid = NULL) {
  if (!$uid) {

    // Setup subscription block with subscription form.
    $block_settings = [
      'newsletters' => array_keys(simplenews_newsletter_get_all()),
      'message' => $this
        ->randomMachineName(4),
    ];
    $block = $this
      ->setupSubscriptionBlock($block_settings);
  }
  if (isset($email)) {
    $edit += [
      'mail[0][value]' => $email,
    ];
  }
  if (!is_array($newsletter_ids)) {
    $newsletter_ids = [
      $newsletter_ids,
    ];
  }
  foreach ($newsletter_ids as $newsletter_id) {
    $edit["subscriptions[{$newsletter_id}]"] = $newsletter_id;
  }
  $path = $uid ? "/user/{$uid}/simplenews" : '';
  $this
    ->drupalGet($path);
  $this
    ->submitForm($edit, $uid ? t('Save') : t('Subscribe'));
  $this
    ->assertResponse(200);
  if (!$uid) {
    $block
      ->delete();
  }
}