3 namespace Drupal\config_test;
5 use Symfony\Component\Validator\Context\ExecutionContextInterface;
8 * Provides a collection of validation callbacks for testing purposes.
10 class ConfigValidation {
15 * @param string $string
16 * The string to validate.
17 * @param \Symfony\Component\Validator\Context\ExecutionContextInterface $context
18 * The validation execution context.
20 public static function validateLlama($string, ExecutionContextInterface $context) {
21 if (!in_array($string, ['llama', 'alpaca', 'guanaco', 'vicuña'], TRUE)) {
22 $context->addViolation('no valid llama');
29 * @param string $string
30 * The string to validate.
31 * @param \Symfony\Component\Validator\Context\ExecutionContextInterface $context
32 * The validation execution context.
34 public static function validateCats($string, ExecutionContextInterface $context) {
35 if (!in_array($string, ['kitten', 'cats', 'nyans'])) {
36 $context->addViolation('no valid cat');
44 * The integer to validate.
45 * @param \Symfony\Component\Validator\Context\ExecutionContextInterface $context
46 * The validation execution context.
48 public static function validateCatCount($count, ExecutionContextInterface $context) {
50 $context->addViolation('no enough cats');
57 * @param string $string
58 * The string to validate.
59 * @param \Symfony\Component\Validator\Context\ExecutionContextInterface $context
60 * The validation execution context.
62 public static function validateGiraffes($string, ExecutionContextInterface $context) {
63 if (strpos($string, 'hum') !== 0) {
64 $context->addViolation('Giraffes just hum');
69 * Validates a mapping.
71 * @param array $mapping
72 * The data to validate.
73 * @param \Symfony\Component\Validator\Context\ExecutionContextInterface $context
74 * The validation execution context.
76 public static function validateMapping($mapping, ExecutionContextInterface $context) {
77 if ($diff = array_diff(array_keys($mapping), ['llama', 'cat', 'giraffe', 'uuid', '_core'])) {
78 $context->addViolation('Missing giraffe.');
83 * Validates a sequence.
85 * @param array $sequence
86 * The data to validate.
87 * @param \Symfony\Component\Validator\Context\ExecutionContextInterface $context
88 * The validation execution context.
90 public static function validateSequence($sequence, ExecutionContextInterface $context) {
91 if (isset($sequence['invalid-key'])) {
92 $context->addViolation('Invalid giraffe key.');