feaT: add SequentiallyConstraint and childs and test if we can have our...
6 unresolved threads
feaT: add SequentiallyConstraint and childs and test if we can have our RecursiveContextualValidator just convert values to TypedData if the data is the same.
Closes #3521131
Merge request reports
Activity
added 1 commit
- 5dcdf24e - feat: add SequentiallyConstraint and childs and test if we can have our...
added 1 commit
- 5c79ef77 - build: comment was too long in RecursiveContextualValidator
added 1 commit
- 9421a081 - build: comment was too long in RecursiveContextualValidator.
- Resolved by Björn Brala
- Resolved by Björn Brala
1 <?php 2 3 namespace Drupal\Core\Validation\Plugin\Validation\Constraint; 4 5 use Symfony\Component\Validator\Constraint; 6 use Symfony\Component\Validator\Constraints\SequentiallyValidator; 7 use Symfony\Component\Validator\Exception\UnexpectedTypeException; 8 9 /** 10 * Validates the Sequentially constraint. 11 */ 12 class SequentiallyConstraintValidator extends SequentiallyValidator { 1 <?php 2 3 namespace Drupal\Core\Validation\Plugin\Validation\Constraint; 4 5 use Drupal\Core\Plugin\ContainerFactoryPluginInterface; 6 use Drupal\Core\StringTranslation\TranslatableMarkup; 7 use Drupal\Core\Validation\Attribute\Constraint; 8 use Symfony\Component\DependencyInjection\ContainerInterface; 9 use Symfony\Component\Validator\Constraint as SymfonyConstraint; 10 use Symfony\Component\Validator\Constraints\Sequentially; 11 12 /** 13 * Checks constraints sequentially and shows the error from the first. 14 */ 15 #[Constraint( 16 id: 'Sequentially', 2 3 namespace Drupal\Core\Validation\Plugin\Validation\Constraint; 4 5 use Drupal\Core\Plugin\ContainerFactoryPluginInterface; 6 use Drupal\Core\StringTranslation\TranslatableMarkup; 7 use Drupal\Core\Validation\Attribute\Constraint; 8 use Symfony\Component\DependencyInjection\ContainerInterface; 9 use Symfony\Component\Validator\Constraint as SymfonyConstraint; 10 use Symfony\Component\Validator\Constraints\Sequentially; 11 12 /** 13 * Checks constraints sequentially and shows the error from the first. 14 */ 15 #[Constraint( 16 id: 'Sequentially', 17 label: new TranslatableMarkup('Sequentially validate', [], ['context' => 'Validation']) 55 $violations = $typed_data->validate(); 56 57 $violationMessages = []; 58 foreach ($violations as $violation) { 59 $violationMessages[] = (string) $violation->getMessage(); 60 } 61 62 $this->assertEquals($expectedViolations, $violationMessages, 'Validation passed for correct value.'); 63 } 64 65 /** 66 * Data provider for testValidation(). 67 */ 68 public static function dataProvider(): array { 69 return [ 70 'It should fail on a failing sibling validator' => [ 65 /** 66 * Data provider for testValidation(). 67 */ 68 public static function dataProvider(): array { 69 return [ 70 'It should fail on a failing sibling validator' => [ 71 'integer', 72 150, 73 [ 74 ['Range' => ['min' => 100]], 75 ['NotNull' => []], 76 ], 77 ['This value should be blank.'], 78 ['Blank' => []], 79 ], 80 'it should fail if second validator fails' => [ 76 ], 77 ['This value should be blank.'], 78 ['Blank' => []], 79 ], 80 'it should fail if second validator fails' => [ 81 'integer', 82 250, 83 [ 84 ['Range' => ['min' => 100]], 85 ['AllowedValues' => [500]], 86 ], 87 [ 88 'The value you selected is not a valid choice.', 89 ], 90 ], 91 'it should show first validation error only even when multiple would fail' => [
Please register or sign in to reply