You are here

class SimplenewsRolesUserRegisterTestCase in Simplenews Roles 7

Hierarchy

Expanded class hierarchy of SimplenewsRolesUserRegisterTestCase

File

tests/simplenews_roles.test, line 17
SimplenewsRoles test functions.

View source
class SimplenewsRolesUserRegisterTestCase extends SimplenewsRolesTestCase {
  public static function getInfo() {
    return array(
      'name' => t('User Register'),
      'description' => t('Check subscription after registration.'),
      'group' => t('Simplenews Roles'),
    );
  }

  /**
   * Check if the user subscribes to all newsletters from his role.
   *
   * Steps performed:
   *   1. Create an admin user,
   *   2. Create a newsletter category,
   *   3. Find $tid based on the category name,
   *   4. Create a newsletter,
   *   5. Add roles to the newsletter,
   *   6. Logout as admin user,
   *   7. Create a user,
   *   8. Check if the user has subscribed to the appropriate newsletters.
   */
  function testUserRegister() {

    // 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);

    // Create a newsletter category.
    $this
      ->drupalGet('admin/config/services/simplenews');
    $this
      ->clickLink(t('Add newsletter category'));
    $name = $this
      ->randomName();
    $edit = array(
      'name' => $name,
      'description' => $this
        ->randomString(20),
    );
    $this
      ->drupalPost(NULL, $edit, t('Save'));

    // Find $tid based on the category name.
    drupal_static_reset('simplenews_categories_load_multiple');
    $categories = simplenews_categories_load_multiple();
    $tid = NULL;
    foreach ($categories as $category) {
      if ($category->name == $name) {
        $tid = $category->tid;
      }
    }

    // Create a newsletter.
    $this
      ->drupalGet('node/add/simplenews');
    $this
      ->assertText(t('Newsletter category'));
    $edit = array(
      'title' => $this
        ->randomName(),
      'field_simplenews_term[und]' => $tid,
    );
    $this
      ->drupalPost(NULL, $edit, 'Save');

    // Add roles to the newsletter.
    $roles = array_keys(user_roles(TRUE));
    $edit = array();
    foreach ($roles as $role) {
      $edit['roles[' . $role . ']'] = $role;
    }
    $this
      ->drupalPost('admin/config/services/simplenews/categories/' . $tid . '/edit', $edit, t('Save'));

    // Logout as admin user.
    $this
      ->drupalLogout();

    // Create a user.
    $user = $this
      ->drupalCreateUser();

    // Check if the user has subscribed to the appropriate newsletters.
    $this
      ->assertTrue(simplenews_user_is_subscribed($user->mail, $tid), t('Subscription is successful.'));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SimplenewsRolesTestCase::setUp public function
SimplenewsRolesUserRegisterTestCase::getInfo public static function
SimplenewsRolesUserRegisterTestCase::testUserRegister function Check if the user subscribes to all newsletters from his role.