You are here

public function MailChimpTest::listUnsubscribe in Mailchimp 7.2

Unsubscribe a user from a list.

Return value

bool True if the user was removed, false if unnecessary or no such list.

Overrides MCAPI::listUnsubscribe

1 call to MailChimpTest::listUnsubscribe()
MailChimpTest::listBatchUnsubscribe in tests/mailchimp_tests.inc
Emulates batch unsubscribe.

File

tests/mailchimp_tests.inc, line 99
A virtual MailChimp API implementation for use in testing.

Class

MailChimpTest
@file A virtual MailChimp API implementation for use in testing.

Code

public function listUnsubscribe($id, $email_address, $delete_member = FALSE, $send_goodbye = TRUE, $send_notify = TRUE) {
  $lists = $this
    ->loadLists();
  if (isset($lists[$id])) {
    if (isset($lists[$id]['data'][$email_address])) {
      if ($lists[$id]['data'][$email_address]['subscribed']) {
        if ($delete_member) {
          unset($lists[$id]['data'][$email_address]);
        }
        else {
          $lists[$id]['data'][$email_address]['subscribed'] = FALSE;
        }
        $this
          ->writeLists($lists);
        return TRUE;
      }
      else {
        $this->errorMessage = "Could not unsubscribe " . $email_address . " from: " . $id . ": not currently subscribed.";
      }
    }
    else {
      $this->errorMessage = "Could not unsubscribe " . $email_address . " from: " . $id . ": address not on list";
    }
  }
  else {
    $this->errorMessage = "Could not unsubscribe " . $email_address . " from non-existant list: " . $id;
  }
  return FALSE;
}