You are here

public function LateInstallTest::testMultipleEmailsLateInstallModule in Multiple E-mail Addresses 2.x

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

File

src/Tests/LateInstallTest.php, line 43
Definition of Drupal\multiple_email\Tests\LateInstallTest.

Class

LateInstallTest
Test module being installed after users are already created.

Namespace

Drupal\multiple_email\Tests

Code

public 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
    ->drupalPostForm('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' => \Drupal::l(t('Administer') . ' > ' . t('Configuration') . ' > ' . t('People') . ' > ' . t('Multiple E-mail'), Url::fromRoute('todo.change.this.route')),
  )));
  $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
    ->drupalPostForm('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
    ->drupalPostForm('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
    ->drupalPostForm('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
    ->id() . '/edit/email-addresses');
  $this
    ->assertText(t('Add new e-mail'));
  drupal_load('module', 'multiple_email');

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

  // emailuser should not have access to edit addresses.
  // @todo change route to match
  // 'user/' . $this->loggedInUser->id() . '/edit/email-addresses/edit/' . $address->eid
  $this
    ->assertNoRaw(\Drupal::l(t('Edit'), Url::fromRoute('todo.change.this.route')));

  // 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
    ->id() . '/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
    ->id() . '/edit');
  $this
    ->assertRaw('<input type="text" id="edit-mail" name="mail" value="' . $this->loggedInUser
    ->getEmail() . '" size="60" maxlength="254" class="form-text required" />');
}