You are here

function MultipleEmailLateInstallTestCase::testMultipleEmailsLateInstallModule in Multiple E-mail Addresses 7

Same name and namespace in other branches
  1. 6 multiple_email.test \MultipleEmailLateInstallTestCase::testMultipleEmailsLateInstallModule()

Test that the Multiple E-mails user can add a new e-mail address.

File

./multiple_email.test, line 308
Tests for the Multiple E-mail module

Class

MultipleEmailLateInstallTestCase

Code

function testMultipleEmailsLateInstallModule() {

  // Enable the Multiple E-mail module
  $this
    ->drupalGet('admin/modules');
  $this
    ->assertText('Multiple E-mail Addresses', t('Multiple E-mail Addresses module found'));
  $this
    ->drupalPost('admin/modules', array(
    'modules[Other][multiple_email][enable]' => 'TRUE',
  ), t('Save configuration'));
  $this
    ->assertRaw(t("Multiple E-mail settings are available under !link", array(
    '!link' => l(t('Administer') . ' > ' . t('Configuration') . ' > ' . t('People') . ' > ' . t('Multiple E-mail'), 'admin/config/people/multiple-email'),
  )));
  $this
    ->assertRaw('<input type="checkbox" id="edit-modules-other-multiple-email-enable" name="modules[Other][multiple_email][enable]" value="1" checked="checked" class="form-checkbox" />', t('Multiple E-mail Addresses module checkbox checked'));

  // Enable 'administer multiple emails' Permissions for adminuser.
  $this
    ->drupalGet('admin/people/permissions');
  $this
    ->assertRaw('4[administer multiple emails]');
  $this
    ->assertRaw(t('Save permissions'));
  $edit = array(
    '4[administer multiple emails]' => TRUE,
  );
  $this
    ->drupalPost('admin/people/permissions', $edit, t('Save permissions'));

  // Enable 'use multiple emails' Permissions for emailuser.
  $this
    ->drupalGet('admin/people/permissions');
  $this
    ->assertRaw('5[use multiple emails]');
  $this
    ->assertRaw(t('Save permissions'));
  $edit = array(
    '5[use multiple emails]' => TRUE,
  );
  $this
    ->drupalPost('admin/people/permissions', $edit, t('Save permissions'));

  // Verify that adminuser has access to settings page.
  $this
    ->drupalGet('admin/config/people/multiple-email');
  $this
    ->assertText(t('Multiple E-mails'));
  $this
    ->drupalPost('admin/config/people/multiple-email', array(), t('Save configuration'));
  $this
    ->assertText(t('The configuration options have been saved.'));

  // Log in as emailuser.
  $this
    ->drupalLogin($this->emailuser);

  // emailuser should not have access to settings page.
  $this
    ->drupalGet('admin/config/people/multiple-email');
  $this
    ->assertText(t('Access denied'));

  // Verify access to multiple e-mail addresses.
  $this
    ->drupalGet('user/' . $this->loggedInUser->uid . '/edit/email-addresses');
  $this
    ->assertText(t('Add new e-mail'));

  // Load freshly-enabled module code so API can be used.
  drupal_load('module', 'multiple_email');
  $address = multiple_email_find_address($this->loggedInUser->mail);
  $this
    ->assertText($this->loggedInUser->mail);

  // emailuser should not have access to edit addresses.
  $this
    ->assertNoRaw(l(t('Edit'), 'user/' . $this->loggedInUser->uid . '/edit/email-addresses/edit/' . $address->eid));

  // Log in as basicuser.
  $this
    ->drupalLogin($this->basicuser);

  // basicuser should not have access to settings page.
  $this
    ->drupalGet('admin/config/people/multiple-email');
  $this
    ->assertText(t('Access denied'));

  // basicuser should not have access to E-mail Addresses page.
  $this
    ->drupalGet('user/' . $this->loggedInUser->uid . '/edit/email-addresses');
  $this
    ->assertText(t('Access denied'));

  // basicuser should have normal e-mail address field on user edit page.
  $this
    ->drupalGet('user/' . $this->loggedInUser->uid . '/edit');
  $this
    ->assertRaw('<input type="text" id="edit-mail" name="mail" value="' . $this->loggedInUser->mail . '" size="60" maxlength="254" class="form-text required" />');
}