class ExtensionNameConstraintTest

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Extension/ExtensionNameConstraintTest.php \Drupal\KernelTests\Core\Extension\ExtensionNameConstraintTest
  2. 10 core/tests/Drupal/KernelTests/Core/Extension/ExtensionNameConstraintTest.php \Drupal\KernelTests\Core\Extension\ExtensionNameConstraintTest

Tests the ExtensionName constraint.

Attributes

#[Group('Validation')] #[CoversClass(ExtensionNameConstraint::class)] #[RunTestsInSeparateProcesses]

Hierarchy

Expanded class hierarchy of ExtensionNameConstraintTest

File

core/tests/Drupal/KernelTests/Core/Extension/ExtensionNameConstraintTest.php, line 17

Namespace

Drupal\KernelTests\Core\Extension
View source
class ExtensionNameConstraintTest extends KernelTestBase {
  
  /**
   * Tests the ExtensionName constraint.
   */
  public function testValidation() : void {
    // Create a data definition that specifies the value must be a string with
    // the name of a valid extension.
    $definition = DataDefinition::create('string')->addConstraint('ExtensionName');
    /** @var \Drupal\Core\TypedData\TypedDataManagerInterface $typed_data */
    $typed_data = $this->container
      ->get('typed_data_manager');
    $data = $typed_data->create($definition, 'user');
    $this->assertCount(0, $data->validate());
    $data->setValue('invalid-name');
    $violations = $data->validate();
    $this->assertCount(1, $violations);
    $this->assertSame('This value is not a valid extension name.', (string) $violations->get(0)
      ->getMessage());
  }

}

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