function ConfigEntityValidationTestBase::getMachineNameConstraints

Same name and namespace in other branches
  1. 10 core/tests/Drupal/KernelTests/Core/Config/ConfigEntityValidationTestBase.php \Drupal\KernelTests\Core\Config\ConfigEntityValidationTestBase::getMachineNameConstraints()

Returns the validation constraints applied to the entity's ID.

If the entity type does not define an ID key, the test will fail. If an ID key is defined but is not using the `machine_name` data type, the test will be skipped.

Return value

array[] The validation constraint configuration applied to the entity's ID.

2 calls to ConfigEntityValidationTestBase::getMachineNameConstraints()
ConfigEntityValidationTestBase::testInvalidMachineNameCharacters in core/tests/Drupal/KernelTests/Core/Config/ConfigEntityValidationTestBase.php
Tests that the entity's ID is tested for invalid characters.
ConfigEntityValidationTestBase::testMachineNameLength in core/tests/Drupal/KernelTests/Core/Config/ConfigEntityValidationTestBase.php
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 116

Class

ConfigEntityValidationTestBase
Base class for testing validation of config entities.

Namespace

Drupal\KernelTests\Core\Config

Code

protected function getMachineNameConstraints() : array {
    $id_key = $this->entity
        ->getEntityType()
        ->getKey('id');
    $this->assertNotEmpty($id_key, "The entity under test does not define an ID key.");
    $data_definition = $this->entity
        ->getTypedData()
        ->get($id_key)
        ->getDataDefinition();
    if ($data_definition->getDataType() === 'machine_name') {
        return $data_definition->getConstraints();
    }
    else {
        $this->markTestSkipped("The entity's ID key does not use the machine_name data type.");
    }
}

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