It'd be nice if it was simpler to import accessibility tests on install, either via features integration or just cleaner API functions

What I ended up doing:


/**
 * Implements hook_install()
 */
function mymodule_install() {
  module_load_include('admin.inc', 'accessibility');
  $tests = module_invoke_all('accessibility_tests', TRUE);
  $enabled = _accessibility_admin_get_enabled_tests();
  $add_test = array_unique(array_merge(
    _mymodule_get_test_from_guildelines('508'),
    _mymodule_get_test_from_guildelines('wcag2aa')
  ));
  foreach ($add_test as $test) {
    if (!isset($enabled[$test]) && !empty($tests[$test])) {
      _mymodule_accessibility_create_test_from_quail($test, $tests[$test]);
    }
  }
}

/**
 * Creates a test entity from a quail test.
 */
function _mymodule_accessibility_create_test_from_quail($quail_name, $test) {
  $language = language_default();
  $new_test = new stdClass();
  $new_test->language = $language->language;
  $new_test->quail_name = $quail_name;
  $new_test->name = $test['title'];
  $new_test->severity = (isset($test['severity'])) ? $test['severity'] : 'suggestion';

  $wrapper = entity_metadata_wrapper('accessibility_test', $new_test);
  $wrapper->error_description->set(array('value'  => $test['description'],
                                         'format' => filter_default_format()
      ));
  $wrapper->save(TRUE);
  accessibility_test_save($new_test);
}

/**
 * Fetches what tests are associated with a guideline.
 */
function _mymodule_get_test_from_guildelines($guildeline) {
  $filename = libraries_get_path('quail') . '/src/resources/guidelines/' . $guildeline . '.json';
  $contents = file_get_contents($filename);
  return drupal_json_decode($contents);
}
CommentFileSizeAuthor
#5 accessibility_features_2058041_5.patch6.21 KBAnonymous (not verified)
#4 accessibility_features_2058041_4.patch6.16 KBAnonymous (not verified)
#3 accessibility_features_2058041_3.patch3.5 KBAnonymous (not verified)

Comments

Anonymous’s picture

Most of the entity stuff is based on the model project, so it does need cleaner APIs. Features integration would be great, I think that accessibility tests are in a definite grey area between configuration and content, and might be doable via UUID features.

Another use case for this would be to have "test packs" which had predefined tests with messages for different editing environments (i.e. the alt text test message talked about fixing it for a specific editor.)

Anonymous’s picture

Knee-jerk subject entry into tag field.

Anonymous’s picture

StatusFileSize
new3.5 KB

Here's the beginnings of a patch, it exports and imports tests so far but needs some more testing. The one issue is that it's leaving features as 'rebuilding' even tho the semaphore is removed.

Anonymous’s picture

StatusFileSize
new6.16 KB

Missed the new features file.

Anonymous’s picture

StatusFileSize
new6.21 KB

Fixed the problem where features would miss default states.

Anonymous’s picture

Status: Active » Needs review
btopro’s picture

Status: Needs review » Needs work

I tested this feature against the -console branch and noticed the following issues. Things export and appear to import correctly. The issue is that when you uninstall a feature it doesn't get rid of it and this causes PDO errors when you go to enable it again. It also seems to have this problem when trying to enable if there's a match in the database for the exact same record that was exported. On uninstall / install, field_revision_error_description and field_error_description need to be cleared or at least validated that they aren't going to overlap and cause a conflict.

Notice: Undefined variable: delete in accessibility_test_features_rebuild() (line 70 of /Applications/MAMP/htdocs/dev/maketest/sites/all/modules/contrib/accessibility/accessibility.features.inc).
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'accessibility_test-2-2-0-0-und' for key 'PRIMARY': INSERT INTO {field_revision_error_description} (entity_type, entity_id, revision_id, bundle, delta, language, error_description_value, error_description_summary, error_description_format) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8); Array ( [:db_insert_placeholder_0] => accessibility_test [:db_insert_placeholder_1] => 2 [:db_insert_placeholder_2] => 2 [:db_insert_placeholder_3] => accessibility_test [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => Links to a multimedia file should be followed by a link to a transcript of the file. [:db_insert_placeholder_7] => [:db_insert_placeholder_8] => textbook_editor ) in field_sql_storage_field_storage_write() (line 452 of /Applications/MAMP/htdocs/dev/maketest/modules/field/modules/field_sql_storage/field_sql_storage.module).
Notice: Undefined variable: delete in accessibility_test_features_rebuild() (line 70 of /Applications/MAMP/htdocs/dev/maketest/sites/all/modules/contrib/accessibility/accessibility.features.inc).
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'accessibility_test-1-0-0-und' for key 'PRIMARY': INSERT INTO {field_data_error_description} (entity_type, entity_id, revision_id, bundle, delta, language, error_description_value, error_description_summary, error_description_format) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8); Array ( [:db_insert_placeholder_0] => accessibility_test [:db_insert_placeholder_1] => 1 [:db_insert_placeholder_2] => 1 [:db_insert_placeholder_3] => accessibility_test [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => Links to a multimedia file should be followed by a link to a transcript of the file. [:db_insert_placeholder_7] => [:db_insert_placeholder_8] => textbook_editor ) in field_sql_storage_field_storage_write() (line 451 of /Applications/MAMP/htdocs/dev/maketest/modules/field/modules/field_sql_storage/field_sql_storage.module)

also unrelated but noticed during install/uninstall:
Notice: Use of undefined constant ACCESSIBILITY_QUAIL_VERSION - assumed 'ACCESSIBILITY_QUAIL_VERSION' in accessibility_requirements() (line 51 of /Applications/MAMP/htdocs/dev/maketest/sites/all/modules/contrib/accessibility/accessibility.install).

btopro’s picture

Feature revert was able to rebuild the records and import them again but generated the following --
Notice: Undefined variable: delete in accessibility_test_features_rebuild() (line 70 of /Applications/MAMP/htdocs/dev/maketest/sites/all/modules/contrib/accessibility/accessibility.features.inc).

I'm thinking if a delete function is added for these that it'll resolve this notice and the errors reported above.

Anonymous’s picture

Status: Needs work » Closed (fixed)

Fixed the delete issue, committed to 7.x.