simplenews_roles.test in Simplenews Roles 6.2
File
tests/simplenews_roles.test
View source
<?php
class SimplenewsRolesTestCase extends DrupalWebTestCase {
protected $web_user;
public function setUp() {
parent::setUp('taxonomy', 'simplenews');
}
function getInfo() {
return array(
'name' => t('Simplenews Roles'),
'description' => t('Executes test suite for Simplenews Roles module.'),
'group' => t('Simplenews'),
);
}
function getRandomNewsletter() {
if ($taxonomies = taxonomy_get_tree(variable_get('simplenews_vid', ''))) {
$tids = array();
foreach ($taxonomies as $newsletter) {
$tids[] = $newsletter->tid;
}
$key = array_rand($tids);
return $tids[$key];
}
return 0;
}
function testRoleSync() {
$user = $this
->drupalCreateUser($permissions = NULL);
$rid = max(array_keys($user->roles));
$rids = array(
$rid,
);
$tid = $this
->getRandomNewsletter();
simplenews_roles_update_subscriptions($tid, $rids);
$this
->assertTrue(simplenews_user_is_subscribed($user->mail, $tid, TRUE), t('User with role was automatically subscribed.'));
simplenews_unsubscribe_user($user->mail, $tid, FALSE, 'website');
simplenews_roles_update_subscriptions($tid, $rids);
$this
->assertFalse(simplenews_user_is_subscribed($user->mail, $tid, TRUE), t('Manually unsubscribed user was not re-subscribed.'));
}
}