You are here

class LateInstallTest in Multiple E-mail Addresses 2.x

Test module being installed after users are already created.

@group multiple_email

Hierarchy

  • class \Drupal\multiple_email\Tests\LateInstallTest extends \Drupal\simpletest\WebTestBase

Expanded class hierarchy of LateInstallTest

File

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

Namespace

Drupal\multiple_email\Tests
View source
class LateInstallTest extends WebTestBase {

  /**
   * Modules to enable.
   *
   * @var array
   */
  public static $modules = array(
    'node',
  );
  protected function setUp() {

    // Set up basic Drupal install.
    parent::setUp();

    // Create a user allowed to have multiple emails.
    $this->adminuser = $this
      ->drupalCreateUser(array(
      'administer users',
      'administer permissions',
      'administer modules',
      'administer site configuration',
    ));
    $this->emailuser = $this
      ->drupalCreateUser(array(
      'access content',
    ));
    $this->basicuser = $this
      ->drupalCreateUser();

    // Log in as adminuser
    $this
      ->drupalLogin($this->adminuser);
  }

  /**
   * Test that the Multiple E-mails user can add a new e-mail address.
   */
  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" />');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LateInstallTest::$modules public static property Modules to enable.
LateInstallTest::setUp protected function
LateInstallTest::testMultipleEmailsLateInstallModule public function Test that the Multiple E-mails user can add a new e-mail address.