Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / config / tests / config_test / src / ConfigValidation.php
1 <?php
2
3 namespace Drupal\config_test;
4
5 use Symfony\Component\Validator\Context\ExecutionContextInterface;
6
7 /**
8  * Provides a collection of validation callbacks for testing purposes.
9  */
10 class ConfigValidation {
11
12   /**
13    * Validates a llama.
14    *
15    * @param string $string
16    *   The string to validate.
17    * @param \Symfony\Component\Validator\Context\ExecutionContextInterface $context
18    *   The validation execution context.
19    */
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');
23     }
24   }
25
26   /**
27    * Validates cats.
28    *
29    * @param string $string
30    *   The string to validate.
31    * @param \Symfony\Component\Validator\Context\ExecutionContextInterface $context
32    *   The validation execution context.
33    */
34   public static function validateCats($string, ExecutionContextInterface $context) {
35     if (!in_array($string, ['kitten', 'cats', 'nyans'])) {
36       $context->addViolation('no valid cat');
37     }
38   }
39
40   /**
41    * Validates a number.
42    *
43    * @param int $count
44    *   The integer to validate.
45    * @param \Symfony\Component\Validator\Context\ExecutionContextInterface $context
46    *   The validation execution context.
47    */
48   public static function validateCatCount($count, ExecutionContextInterface $context) {
49     if ($count <= 1) {
50       $context->addViolation('no enough cats');
51     }
52   }
53
54   /**
55    * Validates giraffes.
56    *
57    * @param string $string
58    *   The string to validate.
59    * @param \Symfony\Component\Validator\Context\ExecutionContextInterface $context
60    *   The validation execution context.
61    */
62   public static function validateGiraffes($string, ExecutionContextInterface $context) {
63     if (strpos($string, 'hum') !== 0) {
64       $context->addViolation('Giraffes just hum');
65     }
66   }
67
68   /**
69    * Validates a mapping.
70    *
71    * @param array $mapping
72    *   The data to validate.
73    * @param \Symfony\Component\Validator\Context\ExecutionContextInterface $context
74    *   The validation execution context.
75    */
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.');
79     }
80   }
81
82   /**
83    * Validates a sequence.
84    *
85    * @param array $sequence
86    *   The data to validate.
87    * @param \Symfony\Component\Validator\Context\ExecutionContextInterface $context
88    *   The validation execution context.
89    */
90   public static function validateSequence($sequence, ExecutionContextInterface $context) {
91     if (isset($sequence['invalid-key'])) {
92       $context->addViolation('Invalid giraffe key.');
93     }
94   }
95
96 }