You are here

public function InstallTest::testModuleNameLength in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Module/InstallTest.php \Drupal\system\Tests\Module\InstallTest::testModuleNameLength()

Tests that an exception is thrown when a module name is too long.

File

core/modules/system/src/Tests/Module/InstallTest.php, line 76
Contains \Drupal\system\Tests\Module\InstallTest.

Class

InstallTest
Tests the installation of modules.

Namespace

Drupal\system\Tests\Module

Code

public function testModuleNameLength() {
  $module_name = 'invalid_module_name_over_the_maximum_allowed_character_length';
  $message = format_string('Exception thrown when enabling module %name with a name length over the allowed maximum', array(
    '%name' => $module_name,
  ));
  try {
    $this->container
      ->get('module_installer')
      ->install(array(
      $module_name,
    ));
    $this
      ->fail($message);
  } catch (ExtensionNameLengthException $e) {
    $this
      ->pass($message);
  }

  // Since for the UI, the submit callback uses FALSE, test that too.
  $message = format_string('Exception thrown when enabling as if via the UI the module %name with a name length over the allowed maximum', array(
    '%name' => $module_name,
  ));
  try {
    $this->container
      ->get('module_installer')
      ->install(array(
      $module_name,
    ), FALSE);
    $this
      ->fail($message);
  } catch (ExtensionNameLengthException $e) {
    $this
      ->pass($message);
  }
}