function SimplenewsRolesResyncTestCase::testRegular in Simplenews Roles 7
File
- tests/
simplenews_roles.test, line 385 - SimplenewsRoles test functions.
Class
Code
function testRegular() {
// Find $tid based on the category name.
$tid = $this
->getRandomNewsletter();
// 1. Create an admin user,
$permissions = array(
'administer content types',
'administer nodes',
'access administration pages',
'administer newsletters',
'administer simplenews settings',
'administer simplenews subscriptions',
'create simplenews content',
'edit own simplenews content',
);
$admin_user = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($admin_user);
$this
->drupalLogout();
// 2. Create a test user and subscribe to default newsletter. Subscribe random mail.
$user_1 = $this
->drupalCreateUser(array(
'administer permissions',
'administer users',
));
$this
->drupalLogin($user_1);
$edit = array();
$this
->drupalPost('user/' . $user_1->uid . '/edit', $edit, t('Save'));
simplenews_subscribe_user($user_1->mail, $tid, FALSE, 'test');
$this
->drupalLogout();
$this
->drupalLogin($admin_user);
$mail_1 = $this
->randomEmail();
simplenews_subscribe_user($mail_1, $tid, FALSE, 'test');
// Check user is already subscribed.
drupal_static_reset('simplenews_user_is_subscribed');
drupal_static_reset('simplenews_categories_load_multiple');
$this
->assertTrue(simplenews_user_is_subscribed($user_1->mail, $tid), t('User (1) has subscribed.'));
$this
->assertTrue(simplenews_user_is_subscribed($mail_1, $tid), t('Mail (1) has subscribed.'));
// 3. Update newsletter settings. Run Cron.
$this
->drupalGet('admin/config/services/simplenews');
$this
->clickLink(t('edit newsletter category'));
// Trigger Save
$edit = array(
'from_address' => 'example@example.com',
);
$this
->drupalPost(NULL, $edit, t('Save'));
// Make sure to run cron to allow processing everything (accidentally).
simplenews_roles_cron();
// 4. Check user is still subscribed.
drupal_static_reset('simplenews_user_is_subscribed');
drupal_static_reset('simplenews_categories_load_multiple');
$this
->assertTrue(simplenews_user_is_subscribed($user_1->mail, $tid), t('User (1) has still subscribed.'));
$this
->assertTrue(simplenews_user_is_subscribed($mail_1, $tid), t('Mail (1) has still subscribed.'));
}