diff --git a/core/lib/Drupal/Core/Config/ConfigPrefixLengthException.php b/core/lib/Drupal/Core/Config/ConfigPrefixLengthException.php new file mode 100644 index 0000000..695a19b --- /dev/null +++ b/core/lib/Drupal/Core/Config/ConfigPrefixLengthException.php @@ -0,0 +1,13 @@ +config_prefix)) { - $config_prefix = $this->config_prefix; + $config_prefix = $this->provider . '.' . $this->config_prefix; } else { - $config_prefix = $this->id(); + $config_prefix = $this->provider . '.' . $this->id(); + } + + if (drupal_strlen($config_prefix) > 83) { + throw new ConfigPrefixLengthException(String::format('The @config_prefix config_prefix length is larger than the maximum limit of @char_count characters', array( + '@config_prefix' => $config_prefix, + '@char_count' => 83, + ))); } // Ensure that all configuration entities are prefixed by the module that // provides the configuration entity type. This ensures that default // configuration will be created as expected during module install and // dependencies can be calculated without the modules that provide the // entity types being installed. - return $this->provider . '.' . $config_prefix; + return $config_prefix; } /** diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php new file mode 100644 index 0000000..0a36508 --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php @@ -0,0 +1,70 @@ + '', + 'name' => '\Drupal\Core\Config\Entity\ConfigEntityType unit test', + 'group' => 'Entity', + ); + } + + /** + * Test that we get an exception if getConfigPrefix() returns a ConfigPrefixLengthException + * + * @expectedException \Drupal\Core\Config\ConfigPrefixLengthException + * @covers ::getConfigPrefix() + */ + public function testConfigPrefixLengthExceeds() { + $this->entity = new ConfigEntityType(array( + 'provider' => $this->randomName(20), + 'config_prefix' => $this->randomName(70), + )); + $this->assertEmpty($this->entity->getConfigPrefix()); + } + + /** + * Test that we do not get a ConfigPrefixLengthException and that we get the expected output + * + * @covers ::getConfigPrefix() + */ + public function testConfigPrefixLengthNormal() { + $entity_data = array( + 'provider' => $this->randomName(20), + 'config_prefix' => $this->randomName(40), + ); + $this->entity = new ConfigEntityType($entity_data); + $expected_prefix = $entity_data['provider'] . '.' . $entity_data['config_prefix']; + $this->assertEquals($expected_prefix, $this->entity->getConfigPrefix()); + } + + +}