You are here

public static function QuailApiValidation::validate in Quail API 8

Perform accessibility validation of the given HTML snippet.

Parameters

string $html: A string of HTML to validate.

array $standard: An array containing a single standard to use as returned by: QuailApiSettings::get_standards().

string|null $severity: (optional) An array of booleans representing the quail test display levels

Return value

array An array of validation results with the following array keys.

File

src/QuailApiValidation.php, line 26

Class

QuailApiValidation
Class QuailApiValidation.

Namespace

Drupal\quail_api

Code

public static function validate($html, $standard, $severity = NULL) {
  $results = [
    'report' => NULL,
    'total' => 0,
  ];

  // the libraries module is currently incomplete and drupal core does not
  // provide remote PHP integration. Manually include the API.
  $include_path = drupal_get_path('module', 'quail_api');
  if (!file_exists($include_path . '/vendor/quail/quail.php')) {
    $results['report'] = FALSE;
    return $results;
  }
  include_once $include_path . '/vendor/quail/quail.php';
  include_once $include_path . "/includes/quail_api_guidelines.inc";
  include_once $include_path . "/includes/quail_api_reporters.inc";

  // quail-lib fails when the markup is empty.
  // empty markup is valid, so bypass the validator and return success.
  if (empty($html)) {
    $results['report'] = [];
    return $results;
  }
  if (!is_array($severity)) {
    $severity = QuailApiSettings::get_default_severity();
  }
  $quail = new \quail($html, $standard['guideline'], 'string', $standard['reporter']);
  $quail
    ->runCheck([
    'ac_module_guideline' => $standard['guideline'],
    'severity' => $severity,
  ]);
  $results = $quail
    ->getReport();
  $quail
    ->cleanup();
  if (!isset($results['report']) || !is_array($results['report'])) {
    $results['report'] = FALSE;
  }
  return $results;
}