public function MailchimpListsTestCase::testAddSegmentSubscriber in Mailchimp 7.3
Same name and namespace in other branches
- 7.5 modules/mailchimp_lists/tests/mailchimp_lists.test \MailchimpListsTestCase::testAddSegmentSubscriber()
- 7.4 modules/mailchimp_lists/tests/mailchimp_lists.test \MailchimpListsTestCase::testAddSegmentSubscriber()
Tests adding a subscriber to a list segment.
File
- modules/
mailchimp_lists/ tests/ mailchimp_lists.test, line 240 - Test class and methods for the Mailchimp Lists module.
Class
- MailchimpListsTestCase
- @file Test class and methods for the Mailchimp Lists module.
Code
public function testAddSegmentSubscriber() {
$list_id = MAILCHIMP_LISTS_TEST_LIST_A;
$email = 'user@example.org';
$subscribed = mailchimp_subscribe($list_id, $email);
$this
->assertTrue($subscribed, 'Tested new user subscription.');
$segment_id = MAILCHIMP_LISTS_TEST_SEGMENT_A;
$batch = FALSE;
$subscriber_added = mailchimp_segment_add_subscriber($list_id, $segment_id, $email, $batch);
$this
->assertTrue($subscriber_added, 'Tested adding subscriber to list segment: ' . $segment_id . ' (NO BATCH)');
// Reset batch queue.
$queue = DrupalQueue::get(MAILCHIMP_LISTS_TEST_BATCH_QUEUE_CRON);
$queue
->deleteQueue();
$batch = TRUE;
$queue_id = MAILCHIMP_LISTS_TEST_BATCH_QUEUE_CRON;
$subscriber_added = mailchimp_segment_add_subscriber($list_id, $segment_id, $email, $batch, $queue_id);
$this
->assertTrue($subscriber_added, 'Tested adding subscriber to list segment: ' . $segment_id . ' (BATCH)');
$queue = DrupalQueue::get(MAILCHIMP_LISTS_TEST_BATCH_QUEUE_CRON);
$queue_item = $queue
->claimItem();
$this
->assertFalse(empty($queue_item), 'Tested list segment subscriber exists in batch queue.');
$this
->assertEqual($queue_item->data['list_id'], $list_id, 'Tested subscription to correct list.');
$this
->assertEqual($queue_item->data['item']['email'], $email, 'Tested correct email address.');
}