You are here

public function InstallTest::testInstallationAndUninstallation in User protect 8

Test installation and uninstallation.

File

tests/src/Functional/InstallTest.php, line 50

Class

InstallTest
Tests module installation and uninstallation.

Namespace

Drupal\Tests\userprotect\Functional

Code

public function testInstallationAndUninstallation() {

  // Install userprotect.
  $this
    ->assertFalse($this->moduleHandler
    ->moduleExists('userprotect'));
  $this
    ->assertTrue($this->moduleInstaller
    ->install([
    'userprotect',
  ]));
  $this
    ->assertTrue($this->moduleHandler
    ->moduleExists('userprotect'));

  // Test default configuration.
  $account = $this
    ->drupalCreateUser();
  $this
    ->assertTrue($account
    ->hasPermission('userprotect.mail.edit'), 'Authenticated user can edit own mail address.');
  $this
    ->assertTrue($account
    ->hasPermission('userprotect.pass.edit'), 'Authenticated user can edit own password.');
  $this
    ->assertTrue($account
    ->hasPermission('userprotect.account.edit'), 'Authenticated user can edit own account.');

  // Ensure an authenticated user can edit its own account.
  $this
    ->drupalLogin($account);
  $this
    ->drupalGet('user/' . $account
    ->id() . '/edit');
  $this
    ->assertResponse(200, 'Authenticated user has access to edit page of own account.');

  // Uninstall userprotect.
  $this->moduleInstaller
    ->uninstall([
    'userprotect',
  ]);

  // Workaround https://www.drupal.org/node/2021959
  // See \Drupal\Core\Test\FunctionalTestSetupTrait::rebuildContainer.
  unset($this->moduleHandler);
  $this
    ->rebuildContainer();
  $this->moduleHandler = $this->container
    ->get('module_handler');

  // Assert that userprotect is uninstalled.
  $this
    ->assertFalse($this->moduleHandler
    ->moduleExists('userprotect'));
}