X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fconfig%2Ftests%2Fconfig_test%2Fsrc%2FConfigValidation.php;fp=web%2Fcore%2Fmodules%2Fconfig%2Ftests%2Fconfig_test%2Fsrc%2FConfigValidation.php;h=9c6939432ed5fe516ec41d8530950fb93bcca3be;hp=0000000000000000000000000000000000000000;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/web/core/modules/config/tests/config_test/src/ConfigValidation.php b/web/core/modules/config/tests/config_test/src/ConfigValidation.php new file mode 100644 index 000000000..9c6939432 --- /dev/null +++ b/web/core/modules/config/tests/config_test/src/ConfigValidation.php @@ -0,0 +1,96 @@ +addViolation('no valid llama'); + } + } + + /** + * Validates cats. + * + * @param string $string + * The string to validate. + * @param \Symfony\Component\Validator\Context\ExecutionContextInterface $context + * The validation execution context. + */ + public static function validateCats($string, ExecutionContextInterface $context) { + if (!in_array($string, ['kitten', 'cats', 'nyans'])) { + $context->addViolation('no valid cat'); + } + } + + /** + * Validates a number. + * + * @param int $count + * The integer to validate. + * @param \Symfony\Component\Validator\Context\ExecutionContextInterface $context + * The validation execution context. + */ + public static function validateCatCount($count, ExecutionContextInterface $context) { + if ($count <= 1) { + $context->addViolation('no enough cats'); + } + } + + /** + * Validates giraffes. + * + * @param string $string + * The string to validate. + * @param \Symfony\Component\Validator\Context\ExecutionContextInterface $context + * The validation execution context. + */ + public static function validateGiraffes($string, ExecutionContextInterface $context) { + if (strpos($string, 'hum') !== 0) { + $context->addViolation('Giraffes just hum'); + } + } + + /** + * Validates a mapping. + * + * @param array $mapping + * The data to validate. + * @param \Symfony\Component\Validator\Context\ExecutionContextInterface $context + * The validation execution context. + */ + public static function validateMapping($mapping, ExecutionContextInterface $context) { + if ($diff = array_diff(array_keys($mapping), ['llama', 'cat', 'giraffe', 'uuid', '_core'])) { + $context->addViolation('Missing giraffe.'); + } + } + + /** + * Validates a sequence. + * + * @param array $sequence + * The data to validate. + * @param \Symfony\Component\Validator\Context\ExecutionContextInterface $context + * The validation execution context. + */ + public static function validateSequence($sequence, ExecutionContextInterface $context) { + if (isset($sequence['invalid-key'])) { + $context->addViolation('Invalid giraffe key.'); + } + } + +}