function NoFieldItemsExistWithHigherCardinalityTest::testMessageParameters

Tests the message template with different parameters.

Attributes

#[DataProvider('messageParametersProvider')]

File

core/modules/field/tests/src/Unit/Plugin/Validation/Constraint/NoFieldItemsExistWithHigherCardinalityTest.php, line 42

Class

NoFieldItemsExistWithHigherCardinalityTest
Tests the NoFieldItemsExistWithHigherCardinality constraint.

Namespace

Drupal\Tests\field\Unit\Plugin\Validation\Constraint

Code

public function testMessageParameters(string $entityType, string $fieldName, int $maxDelta, int $cardinality, string $expectedMessage) : void {
  $options = [
    'entityType' => $entityType,
    'fieldName' => $fieldName,
  ];
  $constraint = new NoFieldItemsExistWithHigherCardinality(entityType: $options['entityType'], fieldName: $options['fieldName']);
  // Simulate the violation building process.
  $parameters = [
    '@field_name' => $fieldName,
    '@entity_type' => $entityType,
    '@max_delta' => (string) $maxDelta,
    '@cardinality' => (string) $cardinality,
  ];
  $message = strtr($constraint->message, $parameters);
  $this->assertEquals($expectedMessage, $message);
}

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