You are here

quail_api.module in Quail API 7

Same filename and directory in other branches
  1. 8 quail_api.module

Module file for the quail api.

File

quail_api.module
View source
<?php

/**
 * @file
 * Module file for the quail api.
 */

/**
 * Implements hook_permission().
 */
function quail_api_permission() {
  $permissions = array();
  drupal_alter('quail_api_permission', $permissions);
  return $permissions;
}

/**
 * Implements hook_views_api().
 */
function quail_api_views_api() {
  return array(
    'api' => 2.0,
    'path' => drupal_get_path('module', 'quail_api'),
  );
}

/**
 * Implements hook_theme().
 */
function quail_api_theme($existing, $type, $theme, $path) {
  $themes = array();
  $themes['quail_api_results'] = array(
    'template' => 'quail_api_results',
    'variables' => array(
      'severity_id' => NULL,
      'severity_array' => NULL,
      'severity_results' => array(),
      'markup_format' => NULL,
      'title_block' => 'h3',
      'display_title' => TRUE,
      'display_description' => TRUE,
    ),
    'path' => drupal_get_path('module', 'quail_api') . '/includes',
  );
  $themes['quail_api_test'] = array(
    'template' => 'quail_api_test',
    'variables' => array(
      'test_name' => '',
      'test_results' => array(),
      'markup_format' => NULL,
    ),
    'path' => drupal_get_path('module', 'quail_api') . '/includes',
  );
  $themes['quail_api_problem'] = array(
    'template' => 'quail_api_problem',
    'variables' => array(
      'problem_id' => '',
      'problem_data' => array(),
      'markup_format' => NULL,
    ),
    'path' => drupal_get_path('module', 'quail_api') . '/includes',
  );
  return $themes;
}

/**
 * Template preprocess function for quail_api_results.tpl.php.
 */
function template_preprocess_quail_api_results(&$variables) {
  drupal_add_css(drupal_get_path('module', 'quail_api') . '/includes/quail_api.css');
  $root_class_name = 'quail_api-results';
  $variables['severity_id'] = NULL;
  $variables['severity_machine_name'] = '';
  $variables['severity_human_name'] = '';
  $variables['severity_description'] = '';
  $variables['base_class'] = $root_class_name;
  $variables['specific_class'] = 'unknown';
  if (empty($variables['severity_results']) || !isset($variables['severity_results']['total'])) {
    $severity_results = array(
      'total' => 0,
    );
  }
  if (is_numeric($variables['id'])) {
    if (empty($variables['severity_array'])) {
      $severity_level = quail_api_get_display_levels($variables['id']);
    }
    else {
      $severity_level = $variables['severity_array'];
    }
    $variables['severity_id'] = $severity_level['id'];
    $variables['severity_machine_name'] = $severity_level['machine_name'];
    $variables['severity_human_name'] = $severity_level['human_name'];
    $variables['severity_description'] = $severity_level['description'];
    $variables['specific_class'] = $root_class_name . '-' . $severity_level['machine_name'];
  }
  unset($variables['severity_array']);

  // limit title_block to a specific list of html tags
  if (!in_array($variables['title_block'], array(
    'h2',
    'h3',
    'h4',
    'h5',
    'h6',
    'div',
    'span',
  ))) {
    $variables['title_block'] = 'h3';
  }
}

/**
 * Template preprocess function for quail_api_test.tpl.php.
 */
function template_preprocess_quail_api_test(&$variables) {
  drupal_add_css(drupal_get_path('module', 'quail_api') . '/includes/quail_api.css');
  $root_class_name = 'quail_api-test';
  $variables['base_class'] = $root_class_name;
  $variables['specific_class'] = '';
  $variables['test_title'] = '';
  $variables['test_description'] = '';
  $variables['test_problems'] = array();
  if (!empty($variables['test_name'])) {
    $variables['specific_class'] = $root_class_name . '-' . drupal_strtolower(check_plain($variables['test_name']));
  }
  if (!empty($variables['test_results']['body']['title'])) {
    $variables['test_title'] = check_plain($variables['test_results']['body']['title']);
    if (isset($variables['test_results']['body']['description'])) {
      $variables['test_description'] = check_markup($variables['test_results']['body']['description'], $variables['markup_format']);
    }
    if (!empty($variables['test_results']['problems'])) {
      $variables['test_problems'] = $variables['test_results']['problems'];
    }
  }
  unset($variables['test_name']);
  unset($variables['test_results']);
}

/**
 * Template preprocess function for quail_api_problem.tpl.php.
 */
function template_preprocess_quail_api_problem(&$variables) {
  drupal_add_css(drupal_get_path('module', 'quail_api') . '/includes/quail_api.css');
  $root_class_name = 'quail_api-problem';
  $variables['base_class'] = $root_class_name;
  $variables['specific_class'] = '';
  $variables['problem_line'] = '';
  $variables['problem_description'] = '';
  if (isset($variables['problem_id'])) {
    $variables['specific_class'] = $root_class_name . '-' . drupal_strtolower(check_plain($variables['problem_id']));
  }
  if (isset($variables['problem_data']['line'])) {
    $variables['problem_line'] = check_plain($variables['problem_data']['line']);
  }
  if (isset($variables['problem_data']['element'])) {
    $variables['problem_description'] = check_markup($variables['problem_data']['element'], $variables['markup_format']);
  }
  unset($variables['problem_id']);
  unset($variables['problem_data']);
}

/**
 * Implements hook_libraries_info().
 */
function quail_api_libraries_info() {
  $libraries = array();
  $libraries['quail'] = array();
  $libraries['quail']['name'] = "Quail-Lib";
  $libraries['quail']['vendor url '] = 'http://code.google.com/p/quail-lib/';
  $libraries['quail']['download url'] = 'http://code.google.com/p/quail-lib/downloads/list';
  $libraries['quail']['path'] = 'quail';
  $libraries['quail']['version arguments'] = array(
    'file' => 'CHANGELOG.txt',
    'pattern' => '/^Version\\s+([0-9a-zA-Z\\.-]+)$/i',
    'lines' => 3,
    'cols' => 100,
  );
  $libraries['quail']['files'] = array();
  $libraries['quail']['files']['php'] = array(
    'quail.php',
    'includes/quail_api_guidelines.inc',
    'includes/quail_api_reporters.inc',
  );
  return $libraries;
}

/**
 * Returns an array of standards that are supported.
 *
 * @param string|null $standard
 *   (optional) Providing a valid standard name will cause the return value to
 *   only contain the standard that matches this string.
 * @param string $target
 *   (optional) Target allows for selecting standards based on some category or
 *   purpose.
 *   The target, in general, represents the scope in which the standards will
 *   be applied.
 *   The following targets are directly supported: 'snippet', 'page'.
 *
 * @return array
 *   An array of standards that are supported by this module or extending
 *   modules.
 *   The array keys are the machine names for each standard.
 */
function quail_api_get_standards($standard = NULL, $target = 'snippet') {
  $standards =& drupal_static(__FUNCTION__, NULL);
  if (!isset($standards)) {
    if ($cache = cache_get('quail_api_standards')) {
      $standards = $cache->data;
    }
  }
  if (isset($standards)) {
    if (!is_null($standard)) {
      if (isset($standards[$standard])) {
        return $standards[$standard];
      }
      return array();
    }
    return $standards;
  }
  $standards = array();
  if ($target == 'snippet' || $target == 'page') {
    $reporter = 'quail_api';
    $module = 'quail_api';
    $standards['all'] = array(
      'human_name' => t("All Tests"),
      'module' => $module,
      'description' => t("Validate using all known tests. This is more efficient than validating against each individual standard because identical tests are not run multiple times."),
      'guideline' => $target == 'snippet' ? 'quail_api_all' : 'all',
      'reporter' => $reporter,
      'target' => $target,
    );
    $standards['section_508'] = array(
      'human_name' => t("Section 508"),
      'module' => $module,
      'description' => t("Validate using the <a href='@section_508'>Section 508</a> standard.", array(
        '@section_508' => 'http://www.section508.gov/index.cfm?fuseAction=stdsdoc#Web',
      )),
      'guideline' => $target == 'snippet' ? 'quail_api_section508' : 'section508',
      'reporter' => $reporter,
      'target' => $target,
    );
    $standards['wcag_1_0_a'] = array(
      'human_name' => t("WCAG 1.0 a"),
      'module' => $module,
      'description' => t("Validate using the <a href='@wcag_1_0'>WCAG 1.0</a> (<a href='@wcag_1_0_a'>A</a>) standard.", array(
        '@wcag_1_0' => 'http://www.w3.org/TR/WCAG10/',
        '@wcag_1_0_a' => 'http://www.w3.org/WAI/WCAG1A-Conformance',
      )),
      'guideline' => $target == 'snippet' ? 'quail_api_wcag1a' : 'wcag1a',
      'reporter' => $reporter,
      'target' => $target,
    );
    $standards['wcag_1_0_aa'] = array(
      'human_name' => t("WCAG 1.0 aa"),
      'module' => $module,
      'description' => t("Validate using the <a href='@wcag_1_0'>WCAG 1.0</a> (<a href='@wcag_1_0_aa'>AA</a>) standard.", array(
        '@wcag_1_0' => 'http://www.w3.org/TR/WCAG10/',
        '@wcag_1_0_a' => 'http://www.w3.org/WAI/WCAG1AA-Conformance',
      )),
      'guideline' => $target == 'snippet' ? 'quail_api_wcag1aa' : 'wcag1aa',
      'reporter' => $reporter,
      'target' => $target,
    );
    $standards['wcag_1_0_aaa'] = array(
      'human_name' => t("WCAG 1.0 aaa"),
      'module' => $module,
      'description' => t("Validate using the <a href='@wcag_1_0'>WCAG 1.0</a> (<a href='@wcag_1_0_aaa'>AAA</a>) standard.", array(
        '@wcag_1_0' => 'http://www.w3.org/TR/WCAG10/',
        '@wcag_1_0_a' => 'http://www.w3.org/WAI/WCAG1AAA-Conformance',
      )),
      'guideline' => $target == 'snippet' ? 'quail_api_wcag1aaa' : 'wcag1aaa',
      'reporter' => $reporter,
      'target' => $target,
    );
    $standards['wcag_2_0_a'] = array(
      'human_name' => t("WCAG 2.0 a"),
      'module' => $module,
      'description' => t("Validate using the <a href='@wcag_2_0'>WCAG 2.0</a> (<a href='@wcag_2_0_a'>A</a>) standard.", array(
        '@wcag_2_0' => 'http://www.w3.org/TR/WCAG20/',
        '@wcag_1_0_a' => 'http://www.w3.org/WAI/WCAG2A-Conformance',
      )),
      'guideline' => $target == 'snippet' ? 'quail_api_wcag2a' : 'wcag2a',
      'reporter' => $reporter,
      'target' => $target,
    );
    $standards['wcag_2_0_aa'] = array(
      'human_name' => t("WCAG 2.0 aa"),
      'module' => $module,
      'description' => t("Validate using the <a href='@wcag_2_0'>WCAG 2.0</a> (<a href='@wcag_2_0_aa'>AA</a>) standard.", array(
        '@wcag_2_0' => 'http://www.w3.org/TR/WCAG20/',
        '@wcag_1_0_a' => 'http://www.w3.org/WAI/WCAG2AA-Conformance',
      )),
      'guideline' => $target == 'snippet' ? 'quail_api_wcag2aa' : 'wcag2aa',
      'reporter' => $reporter,
      'target' => $target,
    );
    $standards['wcag_2_0_aaa'] = array(
      'human_name' => t("WCAG 2.0 aaa"),
      'module' => $module,
      'description' => t("Validate using the <a href='@wcag_2_0'>WCAG 2.0</a> (<a href='@wcag_2_0_aaa'>AAA</a>) standard.", array(
        '@wcag_2_0' => 'http://www.w3.org/TR/WCAG20/',
        '@wcag_1_0_a' => 'http://www.w3.org/WAI/WCAG2AAA-Conformance',
      )),
      'guideline' => $target == 'snippet' ? 'quail_api_wcag2aaa' : 'wcag2aaa',
      'reporter' => $reporter,
      'target' => $target,
    );
  }
  $other_arguments = array();
  $other_arguments['target'] = $target;
  drupal_alter('quail_api_get_standards', $standards, $standard, $other_arguments);
  cache_set('quail_api_standards', $standards, 'cache');
  if (!is_null($standard)) {
    if (isset($standards[$standard])) {
      return $standards[$standard];
    }
    return array();
  }
  return $standards;
}

/**
 * Returns a list of standards.
 *
 * This is only a list of the machine_name and human_name of the select lists.
 * Use this for populating select lists, radio buttons, and check boxes.
 *
 * @param array|null $standards
 *   Providing a valid array of standards as returned by
 *   quail_api_get_standards() and it will be properly converted into a
 *   standards list.
 * @param string $target
 *   (optional) Providing a target allows for limiting standards by some
 *   category.
 *   The target, in general, represents the scope in which the standards will
 *   be applied.
 *   The following targets are directly supported: 'snippet', 'page'.
 *
 * @return array
 *  An array of standards that are supported by this module or extending
 *  modules.
 *  The array keys are the standard machine name and the array value is the
 *  human name.
 *
 * @see quail_api_get_standards()
 */
function quail_api_get_standards_list($standards = NULL, $target = 'snippet') {
  if (is_null($standards)) {
    $standards = quail_api_get_standards(NULL, $target);
  }
  $standards_list = array();
  foreach ($standards as $machine_name => $value) {
    if (!isset($value['target']) || $value['target'] != $target) {
      continue;
    }
    if (isset($value['human_name'])) {
      $standards_list[$machine_name] = $value['human_name'];
    }
  }
  return $standards_list;
}

/**
 * Returns an array of display_levels that are supported.
 *
 * @param string|null $display_level
 *   (optional) A number representing the display level.
 *   When defined, the return value to only contain the display level that
 *   matches this string.
 *   When undefined, all display levels will be loaded into the display_levels
 *   array.
 *
 * @return array
 *   An array of display levels that are supported by this module or extending
 *   modules.
 *   The array keys are the machine names for each display level.
 */
function quail_api_get_display_levels($display_level = NULL) {
  $display_levels =& drupal_static(__FUNCTION__, NULL);
  if (!isset($display_levels)) {
    if ($cache = cache_get('quail_api_display_levels')) {
      $display_levels = $cache->data;
    }
  }
  if (isset($display_levels)) {
    if (!is_null($display_level)) {
      if (isset($display_levels[$display_level])) {
        return $display_levels[$display_level];
      }
      return array();
    }
    return $display_levels;
  }
  $display_levels = array();
  $display_levels[1] = array(
    'machine_name' => 'quail_test_major',
    'human_name' => t("Major Problems"),
    'module' => 'quail_api',
    'description' => t("Major problems represent critical failures in accessibility compliance."),
    'id' => 1,
    // QUAIL_TEST_SEVERE
    'default' => TRUE,
  );
  $display_levels[2] = array(
    'machine_name' => 'quail_test_minor',
    'human_name' => t("Minor Problems"),
    'module' => 'quail_api',
    'description' => t("Minor problems represent simple failures in accessibility compliance."),
    'id' => 2,
    // QUAIL_TEST_MODERATE
    'default' => TRUE,
  );
  $display_levels[3] = array(
    'machine_name' => 'quail_test_suggestion',
    'human_name' => t("Suggestions"),
    'module' => 'quail_api',
    'description' => t("Suggestions provide notes and tips on how to improve accessibility compliance."),
    'id' => 3,
    // QUAIL_TEST_SUGGESTION
    'default' => TRUE,
  );
  drupal_alter('quail_api_get_display_levels', $display_levels, $display_level);
  cache_set('quail_api_display_levels', $display_levels, 'cache');
  if (!is_null($display_level)) {
    if (isset($display_levels[$display_level])) {
      return $display_levels[$display_level];
    }
    return array();
  }
  return $display_levels;
}

/**
 * Returns a list of display levels that are supported.
 *
 * This is only a list of the machine_name and human_name of the select lists.
 * Use this for populating select lists, radio buttons, and check boxes.
 *
 * @param array|null $display_levels
 *   (optional) Providing a valid array of display lists as returned by
 *   quail_api_get_display_levels() and it will be properly converted into a
 *   display levels list.
 * @return array
 *   An array of display levels that are supported by this module or extending
 *   modules.
 *   The array keys are the display levels machine name and the array value is
 *   the human name.
 *
 * @see quail_api_get_display_levels()
 */
function quail_api_get_display_levels_list($display_levels = NULL) {
  if (is_null($display_levels)) {
    $display_levels = quail_api_get_display_levels(NULL);
  }
  $display_levels_list = array();
  foreach ($display_levels as $machine_name => $value) {
    if (isset($value['human_name'])) {
      $display_levels_list[$machine_name] = $value['human_name'];
    }
  }
  return $display_levels_list;
}

/**
 * Returns an array of quail test display levels, each initialized to TRUE.
 *
 * @param array|null $standards
 *   (optional) Providing a valid array of standards as returned by
 *   quail_api_get_display_levels() and it will be properly converted into a
 *   standards list.
 *
 * @return array
 *   An array of quail test display levels, each initialized to TRUE.
 */
function quail_api_get_default_display_level($display_levels = NULL) {
  if (is_null($display_levels)) {
    $display_levels = quail_api_get_display_levels(NULL);
  }
  $display_level = array();
  foreach ($display_levels as $id => $value) {
    if (isset($value['default'])) {
      $display_level[$value['id']] = $value['default'];
    }
  }
  return $display_level;
}

/**
 * Returns an array of validation methods that are supported.
 *
 * A validation method is how the validation process is to be performed.
 * Examples are:
 * - performing the validation everytime a page is viewed
 * - performing the validation only when a validate button is checked
 *
 * This is mostly information.
 * Extending modules are expected to provide the functionality that utilizes
 * this data.
 *
 * @todo function name, path, and arguments support should probably be added
 * here.
 *
 * @param string|null $validation_method
 *   (optional) A machine name representing of the validation method.
 *   When defined, the return value to only contain the validation method that
 *   matches the given id.
 *   When undefined, all validation methods will be loaded into the
 *   validation_method array.
 *
 * @return array
 *   An array of validation methods that are supported by this module or
 *   extending modules.
 *   The array keys are the machine names for each display level.
 */
function quail_api_get_validation_methods($validation_method = NULL) {
  $validation_methods =& drupal_static(__FUNCTION__, NULL);
  if (!isset($validation_methods)) {
    if ($cache = cache_get('quail_api_validation_methods')) {
      $validation_methods = $cache->data;
    }
  }
  if (isset($validation_methods)) {
    if (!is_null($validation_method)) {
      if (isset($validation_methods[$validation_method])) {
        return $validation_methods[$validation_method];
      }
      return array();
    }
    return $validation_methods;
  }
  $validation_methods = array();
  $validation_methods['quail_api_method_immediate'] = array(
    'human_name' => t("Immediately Validate"),
    'module' => 'quail_api',
    'description' => t("Always perform the validation. Validation results are never saved."),
    'database' => FALSE,
    'automatic' => TRUE,
  );
  $validation_methods['quail_api_method_manual'] = array(
    'human_name' => t("Manually Validate"),
    'module' => 'quail_api',
    'description' => t("Perform the validation only when requested. Validation results are never saved."),
    'database' => FALSE,
    'automatic' => FALSE,
  );
  $validation_methods['quail_api_method_immediate_database'] = array(
    'human_name' => t("Immediately Validate & Save"),
    'module' => 'quail_api',
    'description' => t("Always perform the validation. Validation results are stored in the database."),
    'database' => TRUE,
    'automatic' => TRUE,
  );
  $validation_methods['quail_api_method_manual_database'] = array(
    'human_name' => t("Manually Validate & Save"),
    'module' => 'quail_api',
    'description' => t("Perform the validation only when requested. Validation results are stored in the database."),
    'database' => TRUE,
    'automatic' => FALSE,
  );
  drupal_alter('quail_api_get_validation_methods', $validation_methods, $validation_method);
  cache_set('quail_api_validation_methods', $validation_methods, 'cache');
  if (!is_null($validation_method)) {
    if (isset($validation_methods[$validation_method])) {
      return $validation_methods[$validation_method];
    }
    return array();
  }
  return $validation_methods;
}

/**
 * Returns a list of validation methods.
 *
 * This is only a list of the machine_name and human_name of the select lists.
 * Use this for populating select lists, radio buttons, and check boxes.
 *
 * @param array|null $validation_methods
 *   (optional) Providing a valid array of validation methods as returned by
 *   quail_api_get_validation_methods() and it will be properly converted into
 *   a validation methods list.
 *
 * @return array
 *   An array of validation methods that are supported by this module or
 *   extending modules.
 *   The array keys are the validation methods machine name and the array value
 *   is the human name.
 */
function quail_api_get_validation_methods_list($validation_methods = NULL) {
  if (is_null($validation_methods)) {
    $validation_methods = quail_api_get_validation_methods(NULL);
  }
  $validation_methods_list = array();
  foreach ($validation_methods as $machine_name => $value) {
    if (isset($value['human_name'])) {
      $validation_methods_list[$machine_name] = $value['human_name'];
    }
  }
  return $validation_methods_list;
}

/**
 * Perform accessibility validation of the given HTML snippet.
 *
 * @param string $html
 *   A string of HTML to validate.
 * @param array $standard
 *   An array containing a single standard to use as returned by:
 *   quail_api_get_standards().
 * @param 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 array
 *   An array of validation results with the following array keys.
 */
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;
}

/**
 * Loads the quail test data.
 *
 * @param array $conditions
 *   An array with the following possible keys:
 *   - id: The numeric id.
 *   - severity: A numeric value representing the severity (aka: display level)
 *     as defined by the quail library.
 *   - machine_name: The machine-friendly name for the test as defined by the
 *     quail library.
 * @param string|null $keyed
 *   (optional) A string matching one of the following: 'id', 'machine_name'.
 *   When this is NULL, the default behavior is to return the array exactly as
 *   it was returned by the database call.
 *   When this is a valid string, the key names of the returned array will use
 *   the specified key name.
 *
 * @return array
 *   An array of database results.
 */
function quail_api_load_tests($conditions = array(), $keyed = NULL) {
  if (!is_array($conditions)) {
    if (class_exists('cf_error')) {
      cf_error::invalid_array('conditions');
    }
    return array();
  }
  $query = db_select('quail_api_tests', 'qat');
  $query
    ->fields('qat');
  $query
    ->orderBy('qat.id', 'ASC');
  $and = NULL;
  if (isset($conditions['id']) && is_numeric($conditions['id'])) {
    $and = db_and();
    $and
      ->condition('id', $conditions['id'], '=');
  }
  if (isset($conditions['severity']) && is_numeric($conditions['severity'])) {
    if (is_null($and)) {
      $and = db_and();
    }
    $and
      ->condition('severity', $conditions['severity'], '=');
  }
  if (!empty($conditions['machine_name'])) {
    if (is_null($and)) {
      $and = db_and();
    }
    $and
      ->condition('machine_name', $conditions['machine_name'], '=');
  }
  if (is_object($and)) {
    $query
      ->condition($and);
  }
  if ($keyed === 'id' || $keyed === 'machine_name') {
    $results = array();
    try {
      $records = $query
        ->execute();
    } catch (Exception $e) {
      if (class_exists('cf_error')) {
        cf_error::on_query_execution($e);
      }
      return array();
    }
    foreach ($records as $record) {
      if (!is_object($record)) {
        continue;
      }
      $results[$record->{$keyed}] = $record;
    }
    return $results;
  }
  try {
    return $query
      ->execute()
      ->fetchAll();
  } catch (Exception $e) {
    if (class_exists('cf_error')) {
      cf_error::on_query_execution($e);
    }
  }
  return array();
}

/**
 * This stores the quail test information in the drupal database.
 *
 * The quail test data does not have a unique id associated with is so the
 * machine name must be used.
 * When the machine name is used, a unique id is associated.
 * If the machine name already exists then no write is performed.
 * If an update of the data is required then pass either the 'do_update'
 * vairable.
 *
 * @param array $test_data
 *   An array of test data with the following keys:
 *   - machine_name: This is the name of the test as defined by the quail
 *     library.
 *   - severity: This is the display level of the test as defined by the quail
 *     library.
 *   - human_name: This is a more title of the test as defiend by the quail
 *     library.
 *   - description: The detailed description of the test, which is defined by
 *     the quail library in the 'body' item.
 *   - id: (optional) The numeric id for existing data.
 *   - do_update: (optional) A boolean. When specified this tells forces an
 *     update if the machine name already exists.
 *
 * @return int|false
 *   The return states of either FALSE, SAVED_NEW, or SAVED_UPDATED.
 */
function quail_api_save_test($test_data) {
  if (!is_array($test_data)) {
    if (class_exists('cf_error')) {
      cf_error::invalid_array('test_data');
    }
    return FALSE;
  }
  $result = FALSE;
  $columns = array(
    'machine_name',
    'severity',
    'human_name',
    'description',
  );
  foreach ($columns as $key) {
    if (empty($test_data[$key])) {
      if (class_exists('cf_error')) {
        cf_error::missing_array_key('problem_data', $key);
      }
      return FALSE;
    }
  }

  // @todo: implement 'id' and 'do_update'
  $results = quail_api_load_tests(array(
    'machine_name' => $test_data['machine_name'],
  ), NULL);
  if (empty($results)) {
    $data = array();
    $primary_key = array();
    $data['machine_name'] = $test_data['machine_name'];
    $data['severity'] = $test_data['severity'];
    $data['human_name'] = $test_data['human_name'];
    $data['description'] = $test_data['description'];
    $result = drupal_write_record('quail_api_tests', $data, $primary_key);
  }
  return $result;
}

/**
 * Resets all static caches provided by this module.
 */
function quail_api_reset_cache() {
  drupal_static_reset('quail_api_get_standards');
  drupal_static_reset('quail_api_get_display_levels');
  drupal_static_reset('quail_api_get_validation_methods');
  cache_clear_all('quail_api_standards', 'cache', TRUE);
  cache_clear_all('quail_api_display_levels', 'cache', TRUE);
  cache_clear_all('quail_api_validation_methods', 'cache', TRUE);
}

Functions

Namesort descending Description
quail_api_get_default_display_level Returns an array of quail test display levels, each initialized to TRUE.
quail_api_get_display_levels Returns an array of display_levels that are supported.
quail_api_get_display_levels_list Returns a list of display levels that are supported.
quail_api_get_standards Returns an array of standards that are supported.
quail_api_get_standards_list Returns a list of standards.
quail_api_get_validation_methods Returns an array of validation methods that are supported.
quail_api_get_validation_methods_list Returns a list of validation methods.
quail_api_libraries_info Implements hook_libraries_info().
quail_api_load_tests Loads the quail test data.
quail_api_permission Implements hook_permission().
quail_api_reset_cache Resets all static caches provided by this module.
quail_api_save_test This stores the quail test information in the drupal database.
quail_api_theme Implements hook_theme().
quail_api_validate_markup Perform accessibility validation of the given HTML snippet.
quail_api_views_api Implements hook_views_api().
template_preprocess_quail_api_problem Template preprocess function for quail_api_problem.tpl.php.
template_preprocess_quail_api_results Template preprocess function for quail_api_results.tpl.php.
template_preprocess_quail_api_test Template preprocess function for quail_api_test.tpl.php.