function InstallTest::testModuleNameLength

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/Module/InstallTest.php \Drupal\Tests\system\Functional\Module\InstallTest::testModuleNameLength()
  2. 10 core/modules/system/tests/src/Kernel/Module/InstallTest.php \Drupal\Tests\system\Kernel\Module\InstallTest::testModuleNameLength()
  3. 11.x core/modules/system/tests/src/Kernel/Module/InstallTest.php \Drupal\Tests\system\Kernel\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 78

Class

InstallTest
Tests the installation of modules.

Namespace

Drupal\Tests\system\Functional\Module

Code

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);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.