You are here

function quail_api_validate_markup in Quail API 7

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: quail_api_get_standards().

string|null $display_level: (optional) An array of booleans representing the quail test display levels (defaults to quail_api_create_quail_display_level_array()).

Return value

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

File

./quail_api.module, line 708
Module file for the quail api.

Code

function quail_api_validate_markup($html, $standard, $display_level = NULL) {
  $results = array(
    'report' => NULL,
    'total' => 0,
  );
  $library = libraries_load('quail');
  if (empty($library['loaded'])) {
    if (class_exists('cf_error')) {
      cf_error::failed_to_load('quail-lib');
    }
    $results['report'] = FALSE;
    return $results;
  }

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