function ConfigEntityValidationTestBase::testMachineNameLength
Same name in other branches
- 11.x core/tests/Drupal/KernelTests/Core/Config/ConfigEntityValidationTestBase.php \Drupal\KernelTests\Core\Config\ConfigEntityValidationTestBase::testMachineNameLength()
Tests that the entity ID's length is validated if it is a machine name.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Config/ ConfigEntityValidationTestBase.php, line 185
Class
- ConfigEntityValidationTestBase
- Base class for testing validation of config entities.
Namespace
Drupal\KernelTests\Core\ConfigCode
public function testMachineNameLength() : void {
$constraints = $this->getMachineNameConstraints();
$max_length = $constraints['Length']['max'];
$this->assertIsInt($max_length);
$this->assertGreaterThan(0, $max_length);
$id_key = $this->entity
->getEntityType()
->getKey('id');
$expected_errors = [
$id_key => 'This value is too long. It should have <em class="placeholder">' . $max_length . '</em> characters or less.',
// Config entity IDs are immutable by default.
'' => "The '{$id_key}' property cannot be changed.",
];
$this->entity
->set($id_key, $this->randomMachineName($max_length + 2));
$this->assertValidationErrors($expected_errors);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.