You are here

protected function SimplenewsTestBase::subscribe in Simplenews 8

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.

string $submit: (optional) The value of the form submit button. Defaults to t('Subscribe').

string $path: (optional) The path where to expect the form, defaults to 'newsletter/subscriptions'.

int $response: (optional) Expected response, defaults to 200.

6 calls to SimplenewsTestBase::subscribe()
SimplenewsPersonalizationFormsTest::testBlockedSubscribe in src/Tests/SimplenewsPersonalizationFormsTest.php
Blocked account subscribes, display message.
SimplenewsPersonalizationFormsTest::testDeleteAccount in src/Tests/SimplenewsPersonalizationFormsTest.php
Delete account, subscriptions deleted.
SimplenewsPersonalizationFormsTest::testDisableAccount in src/Tests/SimplenewsPersonalizationFormsTest.php
Disable account, subscriptions inactive.
SimplenewsPersonalizationFormsTest::testSubscribeRequestPassword in src/Tests/SimplenewsPersonalizationFormsTest.php
Subscribe, request password: "name is not recognized".
SimplenewsPersonalizationFormsTest::testSynchronizeRegisterSubscribe in src/Tests/SimplenewsPersonalizationFormsTest.php
Register then subscribe: require login, fields updated.

... See full list

File

src/Tests/SimplenewsTestBase.php, line 184
Simplenews test functions.

Class

SimplenewsTestBase
Base class for simplenews web tests.

Namespace

Drupal\simplenews\Tests

Code

protected function subscribe($newsletter_ids, $email = NULL, array $edit = array(), $submit = NULL, $path = 'newsletter/subscriptions', $response = 200) {
  if (isset($email)) {
    $edit += array(
      '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;
  }
  $this
    ->drupalPostForm($path, $edit, $submit ?: t('Subscribe'));
  $this
    ->assertResponse($response);
}