public function InstallTest::testModuleNameLength in Drupal 9
Same name and namespace in other branches
- 8 core/modules/system/tests/src/Functional/Module/InstallTest.php \Drupal\Tests\system\Functional\Module\InstallTest::testModuleNameLength()
Tests that an exception is thrown when a module name is too long.
File
- core/
modules/ system/ tests/ src/ Functional/ Module/ InstallTest.php, line 80
Class
- InstallTest
- Tests the installation of modules.
Namespace
Drupal\Tests\system\Functional\ModuleCode
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);
}
// Since for the UI, the submit callback uses FALSE, test that too.
$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);
}
}