You are here

public function MailChimp_ListsTest::subscribe in Mailchimp 7.3

See also

Mailchimp_Lists::subscribe()

File

tests/mailchimp_lists_test.inc, line 147
A virtual MailChimp Lists API implementation for use in testing.

Class

MailChimp_ListsTest

Code

public function subscribe($id, $email, $merge_vars = null, $email_type = 'html', $double_optin = true, $update_existing = false, $replace_interests = true, $send_welcome = false) {
  $email_address = $email['email'];
  $lists = $this
    ->loadLists();
  if (isset($lists[$id])) {
    if (!isset($lists[$id]['data']['members'])) {
      $lists[$id]['data']['members'] = array();
    }
    $leid = NULL;
    $euid = NULL;
    if (isset($lists[$id]['data']['members'][$email_address])) {
      $lists[$id]['data']['members'][$email_address]['status'] = 'subscribed';
    }
    else {
      $leid = uniqid();
      $euid = uniqid();
      $lists[$id]['data']['members'][$email_address] = array(
        'id' => $euid,
        'leid' => $leid,
        'status' => 'subscribed',
        'email' => $email_address,
        'email_type' => $email_type,
        'merge_vars' => $merge_vars,
      );
    }
    $this
      ->writeLists($lists);
    $response = array(
      'email' => $email_address,
      'euid' => $euid,
      'leid' => $leid,
    );
    return $response;
  }
  else {
    $this->errorMessage = 'Could not add ' . $email_address . ' to non-existant list: ' . $id;
    return NULL;
  }
}