function acquia_spi_test_validate in Acquia Connector 7.3
Same name and namespace in other branches
- 6.2 acquia_spi/acquia_spi.module \acquia_spi_test_validate()
- 7.2 acquia_spi/acquia_spi.module \acquia_spi_test_validate()
Validates data from custom test callbacks.
Parameters
array $collection: An associative array containing a collection of user-contributed tests.
Return value
array An associative array containing the validation result of the given tests, along with any failed parameters.
3 calls to acquia_spi_test_validate()
- acquia_spi_test_collect in acquia_spi/
acquia_spi.module - Collects all user-contributed test results that pass validation.
- acquia_spi_test_status in acquia_spi/
acquia_spi.module - Determines the status of all user-contributed tests.
- drush_acquia_spi_custom_test_validate in acquia_spi/
acquia_spi.drush.inc - A command callback and drush wrapper for custom test validation.
File
- acquia_spi/
acquia_spi.module, line 952 - Send site profile information (NSPI) and system data to Acquia Insight.
Code
function acquia_spi_test_validate(array $collection) {
$result = TRUE;
$check_result_value = array();
// Load valid categories and severities.
$categories = array(
'performance',
'security',
'best_practices',
);
$severities = array(
0,
1,
2,
4,
8,
16,
32,
64,
128,
);
foreach ($collection as $machine_name => $tests) {
foreach ($tests as $check_name => $check_value) {
$fail_value = '';
$message = '';
$check_name = strtolower($check_name);
$check_value = is_string($check_value) ? strtolower($check_value) : $check_value;
// Validate the data inputs for each check.
switch ($check_name) {
case 'category':
if (!is_string($check_value) || !in_array($check_value, $categories)) {
$type = gettype($check_value);
$fail_value = "{$check_value} ({$type})";
$message = 'Value must be a string and one of ' . implode(', ', $categories);
}
break;
case 'solved':
if (!is_bool($check_value)) {
$type = gettype($check_value);
$fail_value = "{$check_value} ({$type})";
$message = 'Value must be a boolean';
}
break;
case 'severity':
if (!is_int($check_value) || !in_array($check_value, $severities)) {
$type = gettype($check_value);
$fail_value = "{$check_value} ({$type})";
$message = 'Value must be an integer and set to one of ' . implode(', ', $severities);
}
break;
default:
if (!is_string($check_value) || strlen($check_value) > 1024) {
$type = gettype($check_value);
$fail_value = "{$check_value} ({$type})";
$message = 'Value must be a string and no more than 1024 characters';
}
break;
}
if (!empty($fail_value) && !empty($message)) {
$check_result_value['failed'][$machine_name][$check_name]['value'] = $fail_value;
$check_result_value['failed'][$machine_name][$check_name]['message'] = $message;
}
}
}
// If there were any failures, the test has failed. Into exile it must go.
if (!empty($check_result_value)) {
$result = FALSE;
}
return array(
'result' => $result,
'failure' => isset($check_result_value['failed']) ? $check_result_value['failed'] : array(),
);
}