You are here

public function MailchimpListsSubscriptionTest::testSubscribe in Mailchimp 8

Same name and namespace in other branches
  1. 2.x modules/mailchimp_lists/tests/src/Functional/MailchimpListsSubscriptionTest.php \Drupal\Tests\mailchimp_lists\Functional\MailchimpListsSubscriptionTest::testSubscribe()

Tests subscribing a member to a list.

File

modules/mailchimp_lists/src/Tests/MailchimpListsSubscriptionTest.php, line 47

Class

MailchimpListsSubscriptionTest
Tests list subscription functionality.

Namespace

Drupal\Tests\mailchimp_lists\Functional

Code

public function testSubscribe() {
  $list_id = '57afe96172';
  $email = 'test@example.org';
  $interest_category_id = 'a1e9f4b7f6';
  $interest_ids = [
    '9143cf3bd1',
    '3a2a927344',
  ];
  $merge_vars = [
    'EMAIL' => $email,
  ];
  $interests = [];
  $interests[$interest_category_id] = [
    $interest_ids[0] => 1,
    $interest_ids[1] => 0,
  ];
  $member_info = mailchimp_subscribe($list_id, $email, $merge_vars, $interests);
  $this
    ->assertEqual($member_info->id, md5($email), 'Tested new user subscription.');
  $this
    ->assertEqual($member_info->merge_fields->EMAIL, $email);
  $this
    ->assertEqual($member_info->interests->{$interest_ids[0]}, TRUE);
  $this
    ->assertEqual($member_info->interests->{$interest_ids[1]}, FALSE);
}