function ConstraintFactoryTest::testAddConstraintBackwardsCompatibility
Same name and namespace in other branches
- 11.x core/tests/Drupal/KernelTests/Core/Validation/ConstraintFactoryTest.php \Drupal\KernelTests\Core\Validation\ConstraintFactoryTest::testAddConstraintBackwardsCompatibility()
Tests creating constraint plugins without passing an associative array.
There are plugin classes that implement Constraint::getDefaultOption(), and when creating those constraints, it is possible to pass options that are not associative arrays. Doing so is deprecated, so this tests that plugin can still be instantiated this way, for backwards compatibility, while deprecation messages will be triggered.
Attributes
#[DataProvider('providerCreateInstanceBackwardsCompatibility')]
#[IgnoreDeprecations]
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Validation/ ConstraintFactoryTest.php, line 87
Class
Namespace
Drupal\KernelTests\Core\ValidationCode
public function testAddConstraintBackwardsCompatibility(string $plugin_id, string $plugin_class, mixed $options, string $expected_property, mixed $expected_value) : void {
$constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
$constraint = $constraint_manager->create($plugin_id, $options);
$this->assertInstanceOf($plugin_class, $constraint);
$this->assertSame($expected_value, $constraint->{$expected_property});
$this->expectDeprecation(sprintf('Passing any non-associative-array options to configure constraint plugin "%s" is deprecated in drupal:11.4.0 and will not be supported in drupal:12.0.0. See https://www.drupal.org/node/3554746', $plugin_id));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.