InstallTest.php in User protect 8
File
tests/src/Functional/InstallTest.php
View source
<?php
namespace Drupal\Tests\userprotect\Functional;
use Drupal\Tests\BrowserTestBase;
class InstallTest extends BrowserTestBase {
public static $modules = [];
protected $moduleHandler;
protected $moduleInstaller;
protected $defaultTheme = 'stark';
public function setUp() {
parent::setUp();
$this->moduleHandler = $this->container
->get('module_handler');
$this->moduleInstaller = $this->container
->get('module_installer');
}
public function testInstallationAndUninstallation() {
$this
->assertFalse($this->moduleHandler
->moduleExists('userprotect'));
$this
->assertTrue($this->moduleInstaller
->install([
'userprotect',
]));
$this
->assertTrue($this->moduleHandler
->moduleExists('userprotect'));
$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.');
$this
->drupalLogin($account);
$this
->drupalGet('user/' . $account
->id() . '/edit');
$this
->assertResponse(200, 'Authenticated user has access to edit page of own account.');
$this->moduleInstaller
->uninstall([
'userprotect',
]);
unset($this->moduleHandler);
$this
->rebuildContainer();
$this->moduleHandler = $this->container
->get('module_handler');
$this
->assertFalse($this->moduleHandler
->moduleExists('userprotect'));
}
}