InstallTest.php in Drupal 10
File
core/modules/system/tests/src/Functional/Module/InstallTest.php
View source
<?php
namespace Drupal\Tests\system\Functional\Module;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Database\Database;
use Drupal\Core\Extension\ExtensionNameLengthException;
use Drupal\Tests\BrowserTestBase;
class InstallTest extends BrowserTestBase {
protected static $modules = [
'module_test',
];
protected $defaultTheme = 'stark';
public function testGetSchemaAtInstallTime() {
$value = Database::getConnection()
->select('module_test', 'mt')
->fields('mt', [
'data',
])
->execute()
->fetchField();
$this
->assertSame('varchar', $value);
}
public function testEnableUserTwice() {
\Drupal::service('module_installer')
->install([
'user',
], FALSE);
$this
->assertSame(0, $this
->config('core.extension')
->get('module.user'));
}
public function testRequiredModuleSchemaVersions() {
$update_registry = \Drupal::service('update.update_hook_registry');
$version = $update_registry
->getInstalledVersion('system');
$this
->assertGreaterThan(0, $version);
$version = $update_registry
->getInstalledVersion('user');
$this
->assertGreaterThan(0, $version);
$post_update_key_value = \Drupal::keyValue('post_update');
$existing_updates = $post_update_key_value
->get('existing_updates', []);
$this
->assertContains('module_test_post_update_test', $existing_updates);
}
public function testUninstallPostUpdateFunctions() {
\Drupal::service('module_installer')
->uninstall([
'module_test',
]);
$post_update_key_value = \Drupal::keyValue('post_update');
$existing_updates = $post_update_key_value
->get('existing_updates', []);
$this
->assertNotContains('module_test_post_update_test', $existing_updates);
}
public function testModuleNameLength() {
$module_name = 'invalid_module_name_over_the_maximum_allowed_character_length';
$message = new FormattableMarkup('Exception thrown when enabling module %name with a name length over the allowed maximum', [
'%name' => $module_name,
]);
try {
$this->container
->get('module_installer')
->install([
$module_name,
]);
$this
->fail($message);
} catch (\Exception $e) {
$this
->assertInstanceOf(ExtensionNameLengthException::class, $e);
}
$message = new FormattableMarkup('Exception thrown when enabling as if via the UI the module %name with a name length over the allowed maximum', [
'%name' => $module_name,
]);
try {
$this->container
->get('module_installer')
->install([
$module_name,
], FALSE);
$this
->fail($message);
} catch (\Exception $e) {
$this
->assertInstanceOf(ExtensionNameLengthException::class, $e);
}
}
}