protected function MailchimpListsBasicTestCase::subscribeUser in Mailchimp 7.2
Subscribes a given number of users to each test list.
@int $anon Number of anonymous email to add to Freeform list. @int $auth Number of authenticated users to create & add to optional list. (note that these users will also be added to the required lists in many cases) @int $req Number of authenticated users to create, triggering user hooks that should add them to required lists.
Return value
array An array of success & failure arrays for each type, containing email addresses for the 'anon' lists and UID's for the user lists.
1 call to MailchimpListsBasicTestCase::subscribeUser()
- MailchimpListsBasicTestCase::testMailchimpListSubscriptionWorkflow in modules/
mailchimp_lists/ tests/ mailchimp_lists.test - Tests subscription workflows.
File
- modules/
mailchimp_lists/ tests/ mailchimp_lists.test, line 312 - Test class and methods for the Mailchimp Lists module.
Class
- MailchimpListsBasicTestCase
- @file Test class and methods for the Mailchimp Lists module.
Code
protected function subscribeUser($type) {
$ret = array();
$offset = $this
->randomString(4);
switch ($type) {
case "anonymous":
// *********************************************************************
// Submit anonymous signup forms for the test Freeform list.
// *********************************************************************
$ret['anon'] = array(
'success' => array(),
'failure' => array(),
);
$form_edit = array();
$email = $this
->randomEmail();
$form_edit['mailchimp_lists[mailchimp_anonymous_test_list][mergevars][EMAIL]'] = $email;
$this
->drupalPost('mailchimp/subscribe', $form_edit, t('Subscribe'));
$this
->assertResponse(200, 'Anonymous subscription ') ? 'success' : 'failure';
return $email;
case "authenticated":
// *********************************************************************
// Submit mailchimp signup forms for the test "Optional" list.
// *********************************************************************
$form_edit = array(
'mailchimp_lists[mailchimp_optional_test_list][subscribe]' => TRUE,
);
$username = 'authuser_' . $offset;
$this->{$username} = $this
->drupalCreateUser();
$id = $this->{$username}->uid;
$this
->drupalLogin($this->{$username});
$this
->drupalPost('user/' . $id . "/mailchimp", $form_edit, t('Save'));
$this
->assertResponse(200, 'Authenticated subscription to optional list allowed.') ? 'success' : 'failure';
return $this->{$username}->uid;
case "required":
$edit = array(
'pass' => "test",
'status' => 1,
'roles' => array(
DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID,
),
);
$email = $this
->randomEmail();
$edit['name'] = "Test Authenticated User " . $offset;
$edit['mail'] = $email;
// Create a user with the authenticated role (req'd by required list).
// This should trigger the hook that subscribes this user:
$account = user_save(drupal_anonymous_user(), $edit);
return $account->uid;
}
}